Java Code Examples for org.apache.solr.common.SolrInputField#setValue()

The following examples show how to use org.apache.solr.common.SolrInputField#setValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MappingSolrConverter.java    From dubbox with Apache License 2.0 6 votes vote down vote up
private Collection<SolrInputField> writeRegularPropertyToTarget(final Map<? super Object, ? super Object> target,
		SolrPersistentProperty persistentProperty, Object fieldValue) {

	SolrInputField field = new SolrInputField(persistentProperty.getFieldName());

	if (persistentProperty.isCollectionLike()) {
		Collection<?> collection = asCollection(fieldValue);
		for (Object o : collection) {
			if (o != null) {
				field.addValue(convertToSolrType(persistentProperty.getType(), o), 1f);
			}
		}
	} else {
		field.setValue(convertToSolrType(persistentProperty.getType(), fieldValue), 1f);
	}

	target.put(persistentProperty.getFieldName(), field);

	return Collections.singleton(field);

}
 
Example 2
Source File: AtomicUpdateDocumentMerger.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 *
 * @param updateSif the SolrInputField to update its values
 * @param cmdDocWChildren the doc to insert/set inside updateSif
 * @param updateDoc the document that was sent as part of the Add Update Command
 * @return updated SolrInputDocument
 */
@SuppressWarnings({"unchecked"})
public SolrInputDocument updateDocInSif(SolrInputField updateSif, SolrInputDocument cmdDocWChildren, SolrInputDocument updateDoc) {
  @SuppressWarnings({"rawtypes"})
  List sifToReplaceValues = (List) updateSif.getValues();
  final boolean wasList = updateSif.getValue() instanceof Collection;
  int index = getDocIndexFromCollection(cmdDocWChildren, sifToReplaceValues);
  SolrInputDocument updatedDoc = merge(updateDoc, cmdDocWChildren);
  if(index == -1) {
    sifToReplaceValues.add(updatedDoc);
  } else {
    sifToReplaceValues.set(index, updatedDoc);
  }
  // in the case where value was a List prior to the update and post update there is no more then one value
  // it should be kept as a List.
  final boolean singleVal = !wasList && sifToReplaceValues.size() <= 1;
  updateSif.setValue(singleVal? sifToReplaceValues.get(0): sifToReplaceValues);
  return cmdDocWChildren;
}
 
Example 3
Source File: DocumentBuilderTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public void testSolrInputFieldEquality() {
  String randomString = TestUtil.randomSimpleString(random(), 10, 20);

  int val = random().nextInt();
  SolrInputField sif1 = new SolrInputField(randomString);
  sif1.setValue(val);
  SolrInputField sif2 = new SolrInputField(randomString);
  sif2.setValue(val);

  assertTrue(assertSolrInputFieldEquals(sif1, sif2));

  sif2.setName("foo");
  assertFalse(assertSolrInputFieldEquals(sif1, sif2));

}
 
Example 4
Source File: IdAddingSolrUpdateWriterTest.java    From hbase-indexer with Apache License 2.0 5 votes vote down vote up
@Test
public void testAdd_MultipleDocumentsWithTheirOwnIds() {
    
    String idA = DOCUMENT_ID + "A";
    String idB = DOCUMENT_ID + "B";
    
    IdAddingSolrUpdateWriter updateWriter = new IdAddingSolrUpdateWriter(
            UNIQUE_KEY_FIELD, DOCUMENT_ID, null, TABLE_NAME, updateCollector);
    
    SolrInputDocument docA = mock(SolrInputDocument.class);
    SolrInputDocument docB = mock(SolrInputDocument.class);
    
    SolrInputField keyFieldA = new SolrInputField(UNIQUE_KEY_FIELD);
    keyFieldA.setValue(idA, 1.0f);
    SolrInputField keyFieldB = new SolrInputField(UNIQUE_KEY_FIELD);
    keyFieldB.setValue(idB, 1.0f);
    
    
    when(docA.getField(UNIQUE_KEY_FIELD)).thenReturn(keyFieldA);
    when(docB.getField(UNIQUE_KEY_FIELD)).thenReturn(keyFieldB);

    updateWriter.add(docA);
    updateWriter.add(docB);

    verify(updateCollector).add(idA, docA);
    verify(updateCollector).add(idB, docB);
}
 
Example 5
Source File: SolrQueryTest.java    From testcontainers-java with MIT License 4 votes vote down vote up
private static SolrInputField createInputField(String key, String value) {
    SolrInputField inputField = new SolrInputField(key);
    inputField.setValue(value);
    return inputField;
}
 
Example 6
Source File: IdAddingSolrUpdateWriterTest.java    From hbase-indexer with Apache License 2.0 3 votes vote down vote up
@Test
public void testAdd_IdAlreadyPresent() {
    IdAddingSolrUpdateWriter updateWriter = new IdAddingSolrUpdateWriter(
            UNIQUE_KEY_FIELD, DOCUMENT_ID, null, TABLE_NAME, updateCollector);
    
    
    SolrInputField solrIdField = new SolrInputField(DOCUMENT_ID);
    solrIdField.setValue(DOCUMENT_ID, 1.0f);
    
    when(solrDoc.getField(UNIQUE_KEY_FIELD)).thenReturn(solrIdField);

    updateWriter.add(solrDoc);

    verify(updateCollector).add(DOCUMENT_ID, solrDoc);
}