当前位置: 首页>>代码示例>>Java>>正文


Java SolrInputField.addValue方法代码示例

本文整理汇总了Java中org.apache.solr.common.SolrInputField.addValue方法的典型用法代码示例。如果您正苦于以下问题:Java SolrInputField.addValue方法的具体用法?Java SolrInputField.addValue怎么用?Java SolrInputField.addValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.solr.common.SolrInputField的用法示例。


在下文中一共展示了SolrInputField.addValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: processElement

import org.apache.solr.common.SolrInputField; //导入方法依赖的package包/类
@ProcessElement
public void processElement(ProcessContext c) {
  UntypedOccurrence inputRecord = c.element();
  SolrInputDocument outputRecord = new SolrInputDocument();

  // As a quick POC we just copy the fields in using the same name as the Avro schema (very naive)
  for (Schema.Field f : SCHEMA.getFields()) {
    if (inputRecord.get(f.name()) != null) {
      SolrInputField inputField = new SolrInputField(f.name());
      inputField.addValue(inputRecord.get(f.name()).toString(), DEFAULT_BOOST);
      outputRecord.put(f.name(), inputField);
    }
  }

  c.output(outputRecord);
}
 
开发者ID:gbif,项目名称:pipelines,代码行数:17,代码来源:SolrDocBuilder.java

示例2: addField

import org.apache.solr.common.SolrInputField; //导入方法依赖的package包/类
private void addField(SolrInputDocument doc, String name, String value) {
  // find if such field already exists
  if (doc.get(name) == null) {
    doc.addField(name, value);
  } else {
    // for some fields we can't allow multiple values, like ID field phrase, so we have to perform this check
    SolrInputField f = doc.get(name);
    
    boolean valueExists = false;
    
    for (Object existingValue : f.getValues()) {
      if (existingValue == null && value == null) {
        valueExists = true;
        break;
      }
      if (existingValue != null && value != null && existingValue.equals(value)) {
        valueExists = true;
        break;
      }
    }
      
    if (!valueExists) {
      f.addValue(value);
    }
  }
}
 
开发者ID:sematext,项目名称:solr-autocomplete,代码行数:27,代码来源:AutocompleteUpdateRequestProcessor.java

示例3: addField

import org.apache.solr.common.SolrInputField; //导入方法依赖的package包/类
private static void addField(SolrInputDocument doc, String name, String value) {
  // find if such field already exists
  if (doc.get(name) == null) {
    // System.out.println("Adding field " + name + " without previous values");
    doc.addField(name, value);
  } else {
    // for some fields we can't allow multiple values, like ID field phrase, so we have to perform this check
    SolrInputField f = doc.get(name);
    for (Object val : f.getValues()) {
      // fix for boolean values
      if ((value.equalsIgnoreCase("t") && val.toString().equalsIgnoreCase("true")) ||
          (value.equalsIgnoreCase("f") && val.toString().equalsIgnoreCase("false"))) {
            return;
      }
      if (value.equals(val.toString())) {
        // if we find such value in the doc, we will not add it again
        // System.out.println("Field " + name + " already contains value " + value);
        return;
      }
    }
    // System.out.println("Adding field " + name + " without new value " + value);
    f.addValue(value);
  }
}
 
开发者ID:sematext,项目名称:solr-autocomplete,代码行数:25,代码来源:CustomIndexLoader.java

示例4: mutate

import org.apache.solr.common.SolrInputField; //导入方法依赖的package包/类
@Override
protected final SolrInputField mutate(final SolrInputField src) {
  SolrInputField result = new SolrInputField(src.getName());
  for (final Object srcVal : src.getValues()) {
    final Object destVal = mutateValue(srcVal);
    if (DELETE_VALUE_SINGLETON == destVal) { 
      /* NOOP */
      log.debug("removing value from field '{}': {}", 
                src.getName(), srcVal);
    } else {
      if (destVal != srcVal) {
        log.debug("replace value from field '{}': {} with {}", 
                  new Object[] { src.getName(), srcVal, destVal });
      }
      result.addValue(destVal, 1.0F);
    }
  }
  result.setBoost(src.getBoost());
  return 0 == result.getValueCount() ? null : result;
}
 
开发者ID:europeana,项目名称:search,代码行数:21,代码来源:FieldValueMutatingUpdateProcessor.java

示例5: mutate

import org.apache.solr.common.SolrInputField; //导入方法依赖的package包/类
@Override
protected SolrInputField mutate(SolrInputField src) {
  SchemaField sf = schema.getFieldOrNull(src.getName());
  if (sf == null) { // remove this field
    return null;
  }
  FieldType type = PreAnalyzedField.createFieldType(sf);
  if (type == null) { // neither indexed nor stored - skip
    return null;
  }
  SolrInputField res = new SolrInputField(src.getName());
  res.setBoost(src.getBoost());
  for (Object o : src) {
    if (o == null) {
      continue;
    }
    Field pre = (Field)parser.createField(sf, o, 1.0f);
    if (pre != null) {
      res.addValue(pre, 1.0f);
    } else { // restore the original value
      log.warn("Could not parse field {} - using original value as is: {}", src.getName(), o);
      res.addValue(o, 1.0f);
    }
  }
  return res;
}
 
开发者ID:europeana,项目名称:search,代码行数:27,代码来源:PreAnalyzedUpdateProcessorFactory.java

示例6: testMultiValuedFieldAndDocBoosts

import org.apache.solr.common.SolrInputField; //导入方法依赖的package包/类
public void testMultiValuedFieldAndDocBoosts() throws Exception {
  SolrCore core = h.getCore();
  IndexSchema schema = core.getLatestSchema();
  SolrInputDocument doc = new SolrInputDocument();
  doc.setDocumentBoost(3.0f);
  SolrInputField field = new SolrInputField( "foo_t" );
  field.addValue( "summer time" , 1.0f );
  field.addValue( "in the city" , 5.0f ); // using boost
  field.addValue( "living is easy" , 1.0f );
  doc.put( field.getName(), field );

  Document out = DocumentBuilder.toDocument( doc, schema );
  IndexableField[] outF = out.getFields( field.getName() );
  assertEquals("wrong number of field values",
               3, outF.length);

  // since Lucene no longer has native documnt boosts, we should find
  // the doc boost multiplied into the boost o nthe first field value
  // all other field values should be 1.0f
  // (lucene will multiply all of the field boosts later)
  assertEquals(15.0f, outF[0].boost(), 0.0f);
  assertEquals(1.0f, outF[1].boost(), 0.0f);
  assertEquals(1.0f, outF[2].boost(), 0.0f);
  
}
 
开发者ID:europeana,项目名称:search,代码行数:26,代码来源:DocumentBuilderTest.java

示例7: writeRegularPropertyToTarget

import org.apache.solr.common.SolrInputField; //导入方法依赖的package包/类
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);

}
 
开发者ID:yiduwangkai,项目名称:dubbox-solr,代码行数:22,代码来源:MappingSolrConverter.java

示例8: testMultiValuedFieldAndDocBoosts

import org.apache.solr.common.SolrInputField; //导入方法依赖的package包/类
public void testMultiValuedFieldAndDocBoosts() throws Exception {
  SolrCore core = h.getCore();
  IndexSchema schema = core.getSchema();
  SolrInputDocument doc = new SolrInputDocument();
  doc.setDocumentBoost(3.0f);
  SolrInputField field = new SolrInputField( "foo_t" );
  field.addValue( "summer time" , 1.0f );
  field.addValue( "in the city" , 5.0f ); // using boost
  field.addValue( "living is easy" , 1.0f );
  doc.put( field.getName(), field );

  Document out = DocumentBuilder.toDocument( doc, core.getSchema() );
  IndexableField[] outF = out.getFields( field.getName() );
  assertEquals("wrong number of field values",
               3, outF.length);

  // since Lucene no longer has native documnt boosts, we should find
  // the doc boost multiplied into the boost o nthe first field value
  // all other field values should be 1.0f
  // (lucene will multiply all of the field boosts later)
  assertEquals(15.0f, outF[0].boost(), 0.0f);
  assertEquals(1.0f, outF[1].boost(), 0.0f);
  assertEquals(1.0f, outF[2].boost(), 0.0f);
  
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:26,代码来源:DocumentBuilderTest.java

示例9: readDocFields

import org.apache.solr.common.SolrInputField; //导入方法依赖的package包/类
private void readDocFields(DataInput in) throws IOException {
  int len = in.readInt();
  for (int i = 0; i < len; i++) {
    String key = readString(in);// issue if this is empty?
    if (key != null) {
      String solrFieldName = readString(in);
      if (solrFieldName == null) {
        solrFieldName = key;
      }
      SolrInputField solrField = new SolrInputField(solrFieldName);
      int solrFieldlen = in.readInt();
      for (int j = 0; j < solrFieldlen; j++) {
        String theValStr = readString(in);// stored as JSON
        if (theValStr != null && !theValStr.equals(DUMMY_HOLDER)) {
          Object theVal = objectMapper.readValue(theValStr, Object.class);
          if (theVal != null) {
            // default boost value
            solrField.addValue(theVal, 1.0F);
          } else {
            log.warn("Couldn't convert JSON string: {}", theValStr);
          }
        }
      }
      document.put(solrFieldName, solrField);
    }
  }
}
 
开发者ID:lucidworks,项目名称:solr-hadoop-common,代码行数:28,代码来源:LWSolrDocument.java

示例10: mutate

import org.apache.solr.common.SolrInputField; //导入方法依赖的package包/类
protected final SolrInputField mutate(final SolrInputField srcField) {
  List<String> messages = null;
  SolrInputField result = new SolrInputField(srcField.getName());
  for (final Object srcVal : srcField.getValues()) {
    final Object destVal = mutateValue(srcVal);
    if (SKIP_FIELD_VALUE_LIST_SINGLETON == destVal) {
      log.debug("field '{}' {} value '{}' is not mutatable, so no values will be mutated",
                new Object[] { srcField.getName(), srcVal.getClass().getSimpleName(), srcVal });
      return srcField;
    }
    if (DELETE_VALUE_SINGLETON == destVal) {
      if (log.isDebugEnabled()) {
        if (null == messages) {
          messages = new ArrayList<>();
        }
        messages.add(String.format(Locale.ROOT, "removing value from field '%s': %s '%s'", 
                                   srcField.getName(), srcVal.getClass().getSimpleName(), srcVal));
      }
    } else {
      if (log.isDebugEnabled()) {
        if (null == messages) {
          messages = new ArrayList<>();
        }
        messages.add(String.format(Locale.ROOT, "replace value from field '%s': %s '%s' with %s '%s'", 
                                   srcField.getName(), srcVal.getClass().getSimpleName(), srcVal, 
                                   destVal.getClass().getSimpleName(), destVal));
      }
      result.addValue(destVal, 1.0F);
    }
  }
  result.setBoost(srcField.getBoost());
  
  if (null != messages && log.isDebugEnabled()) {
    for (String message : messages) {
      log.debug(message);
    }
  }
  return 0 == result.getValueCount() ? null : result;
}
 
开发者ID:europeana,项目名称:search,代码行数:40,代码来源:AllValuesOrNoneFieldMutatingUpdateProcessor.java

示例11: getInstance

import org.apache.solr.common.SolrInputField; //导入方法依赖的package包/类
@Override
public final UpdateRequestProcessor getInstance(SolrQueryRequest req,
                                                SolrQueryResponse rsp,
                                                UpdateRequestProcessor next) {
  return new UpdateRequestProcessor(next) {
    @Override
    public void processAdd(AddUpdateCommand cmd) throws IOException {

      final SolrInputDocument doc = cmd.getSolrInputDocument();

      // preserve initial values and boost (if any)
      SolrInputField destField = doc.containsKey(dest) ? 
        doc.getField(dest) : new SolrInputField(dest); 
      
      boolean modified = false;
      for (final String fname : doc.getFieldNames()) {
        if (! srcSelector.shouldMutate(fname)) continue;

        for (Object val : doc.getFieldValues(fname)) {
          // preserve existing dest boost (multiplicitive), ignore src boost
          destField.addValue(val, 1.0f);
        }
        modified=true;
      }

      if (modified) doc.put(dest, destField);

      super.processAdd(cmd);
    }
  };
}
 
开发者ID:europeana,项目名称:search,代码行数:32,代码来源:CloneFieldUpdateProcessorFactory.java

示例12: field

import org.apache.solr.common.SolrInputField; //导入方法依赖的package包/类
/**
 * Convenience method for building up SolrInputFields
 */
final SolrInputField field(String name, float boost, Object... values) {
  SolrInputField f = new SolrInputField(name);
  for (Object v : values) {
    f.addValue(v, 1.0F);
  }
  f.setBoost(boost);
  return f;
}
 
开发者ID:europeana,项目名称:search,代码行数:12,代码来源:UpdateProcessorTestBase.java

示例13: field

import org.apache.solr.common.SolrInputField; //导入方法依赖的package包/类
/** 
 * Convenience method for building up SolrInputFields
 */
SolrInputField field(String name, float boost, Object... values) {
  SolrInputField f = new SolrInputField(name);
  for (Object v : values) {
    f.addValue(v, 1.0F);
  }
  f.setBoost(boost);
  return f;
}
 
开发者ID:europeana,项目名称:search,代码行数:12,代码来源:UUIDUpdateProcessorFallbackTest.java

示例14: create

import org.apache.solr.common.SolrInputField; //导入方法依赖的package包/类
public SolrInputField create(String fieldName, Object ... fieldValues) {
    SolrInputField inputField = new SolrInputField(fieldName);
    for (Object fieldValue : fieldValues) {
        inputField.addValue(fieldValue, 1);
    }
    return inputField;
}
 
开发者ID:CeON,项目名称:saos,代码行数:8,代码来源:SolrInputFieldFactory.java

示例15: mutate

import org.apache.solr.common.SolrInputField; //导入方法依赖的package包/类
protected final SolrInputField mutate(final SolrInputField srcField) {
  List<String> messages = null;
  SolrInputField result = new SolrInputField(srcField.getName());
  for (final Object srcVal : srcField.getValues()) {
    final Object destVal = mutateValue(srcVal);
    if (SKIP_FIELD_VALUE_LIST_SINGLETON == destVal) {
      log.debug("field '{}' {} value '{}' is not mutatable, so no values will be mutated",
                new Object[] { srcField.getName(), srcVal.getClass().getSimpleName(), srcVal });
      return srcField;
    }
    if (DELETE_VALUE_SINGLETON == destVal) {
      if (log.isDebugEnabled()) {
        if (null == messages) {
          messages = new ArrayList<String>();
        }
        messages.add(String.format(Locale.ROOT, "removing value from field '%s': %s '%s'", 
                                   srcField.getName(), srcVal.getClass().getSimpleName(), srcVal));
      }
    } else {
      if (log.isDebugEnabled()) {
        if (null == messages) {
          messages = new ArrayList<String>();
        }
        messages.add(String.format(Locale.ROOT, "replace value from field '%s': %s '%s' with %s '%s'", 
                                   srcField.getName(), srcVal.getClass().getSimpleName(), srcVal, 
                                   destVal.getClass().getSimpleName(), destVal));
      }
      result.addValue(destVal, 1.0F);
    }
  }
  result.setBoost(srcField.getBoost());
  
  if (null != messages && log.isDebugEnabled()) {
    for (String message : messages) {
      log.debug(message);
    }
  }
  return 0 == result.getValueCount() ? null : result;
}
 
开发者ID:yintaoxue,项目名称:read-open-source-code,代码行数:40,代码来源:AllValuesOrNoneFieldMutatingUpdateProcessor.java


注:本文中的org.apache.solr.common.SolrInputField.addValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。