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


Java SolrInputField类代码示例

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


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

示例1: solrInputField

import org.apache.solr.common.SolrInputField; //导入依赖的package包/类
public static <T> Matcher<SolrInputField> solrInputField(String fieldName, Matcher<T> valueMatcher) {
    return new TypeSafeMatcher<SolrInputField>() {
        @Override
        protected boolean matchesSafely(SolrInputField item) {
            return StringUtils.equals(fieldName, item.getName()) && valueMatcher.matches(item.getValue());
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("SolrInputField(")
                    .appendValue(fieldName)
                    .appendText(" value matching ")
                    .appendDescriptionOf(valueMatcher)
                    .appendText(")");
        }
    };
}
 
开发者ID:RBMHTechnology,项目名称:vind,代码行数:18,代码来源:SolrSearchServerTest.java

示例2: processElement

import org.apache.solr.common.SolrInputField; //导入依赖的package包/类
@ProcessElement
public void processElement(ProcessContext c) {
    TypedOccurrence inputRecord = c.element();
    SolrInputDocument outputRecord = new SolrInputDocument();
    if (inputRecord == null) {
        return;
    }
    Object occurrenceId = inputRecord.get("occurrenceId");
    if (occurrenceId == null || occurrenceId.toString().isEmpty()) {
        return;
    }

    // As a quick POC we just copy the fields in using the same name as the Avro schema (very naive)
    SCHEMA.getFields().stream()
            .filter(f -> f != null && f.name() != null)
            .filter(f -> inputRecord.getSchema().getField(f.name()) != null)
            .filter(f -> inputRecord.get(f.name()) != null)
            .forEach(f -> {
                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,代码行数:26,代码来源:SolrDocBuilder.java

示例3: 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

示例4: 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

示例5: 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

示例6: get

import org.apache.solr.common.SolrInputField; //导入依赖的package包/类
@Override
public String get() {
  StringBuilder builder = new StringBuilder();
  if (!difference.entriesDiffering().isEmpty()) {
    builder.append("Differing:\n");
    for (Map.Entry<String, MapDifference.ValueDifference<SolrInputField>> diff : difference.entriesDiffering().entrySet()) {
      builder.append("  ");
      builder.append(diff.getKey());
      builder.append('\n');
      builder.append("  left  : ");
      builder.append(diff.getValue().leftValue());
      builder.append('\n');
      builder.append("  right : ");
      builder.append(diff.getValue().rightValue());
      builder.append('\n');
    }
  }

  return builder.toString();
}
 
开发者ID:jcustenborder,项目名称:kafka-connect-solr,代码行数:21,代码来源:MapDifferenceSupplier.java

示例7: doEquivalent

import org.apache.solr.common.SolrInputField; //导入依赖的package包/类
@Override
protected boolean doEquivalent(SolrInputField o1, SolrInputField o2) {
  if (o1.getValue() instanceof SolrInputDocument) {
    if (!(o2.getValue() instanceof SolrInputDocument)) {
      return false;
    }
    final MapDifference<String, SolrInputField> difference = Maps.difference(
        (SolrInputDocument) o1.getValue(),
        (SolrInputDocument) o2.getValue(),
        this
    );
    if (!difference.areEqual()) {
      return false;
    }
  } else {
    if (o1.getValue() != o2.getValue()) {
      return false;
    }
  }
  return true;
}
 
开发者ID:jcustenborder,项目名称:kafka-connect-solr,代码行数:22,代码来源:SolrInputFieldEquivalence.java

示例8: writeDocFields

import org.apache.solr.common.SolrInputField; //导入依赖的package包/类
private void writeDocFields(SolrInputDocument doc, DataOutput dataOutput) throws IOException {
  if (doc != null && !doc.isEmpty()) {
    // doc - {id_field}
    dataOutput.writeInt(doc.size() - 1);
    for (Map.Entry<String, SolrInputField> entry : doc.entrySet()) {
      if (!ID.equals(entry.getKey())) {
        writeString(entry.getKey(), dataOutput);
        SolrInputField solrField = entry.getValue();
        writeString(solrField.getName(), dataOutput);
        dataOutput.writeInt(solrField.getValueCount());
        for (Iterator<Object> iterator = solrField.iterator(); iterator.hasNext(); ) {
          Object theVal = iterator.next();
          if (theVal != null) {
            String valAsString = objectMapper.writeValueAsString(theVal);
            writeString(valAsString, dataOutput);
          } else {
            // we have no object, is this an error?
            writeString(DUMMY_HOLDER, dataOutput);
          }
        }
      }
    }
  } else {
    dataOutput.writeInt(0);
  }
}
 
开发者ID:lucidworks,项目名称:solr-hadoop-common,代码行数:27,代码来源:LWSolrDocument.java

示例9: getInstance

import org.apache.solr.common.SolrInputField; //导入依赖的package包/类
@Override
public UpdateRequestProcessor getInstance(SolrQueryRequest req,
                                          SolrQueryResponse rsp,
                                          UpdateRequestProcessor next) {
  final IndexSchema schema = req.getSchema();
  return new FieldMutatingUpdateProcessor(getSelector(), next) {
    @Override
    protected SolrInputField mutate(SolrInputField src) {
      if (src.getValueCount() <= 1)
        return src;//short circuit single value
      SchemaField field = schema.getField(src.getName());
      FieldType ft = field.getType();
      IndexableField result = ft.createField(field, src, src.getBoost());
      if (result == null)
        return null;//remove
      src.setValue(result, src.getBoost());
      return src;
    }
  };
}
 
开发者ID:randomstatistic,项目名称:SOLR-5170,代码行数:21,代码来源:MultiValUpdateRequestProcessorFactory.java

示例10: createField

import org.apache.solr.common.SolrInputField; //导入依赖的package包/类
/**
 * Normally called by Solr's {@link org.apache.solr.update.DocumentBuilder}.
 * It will also be called by {@link org.apache.solr.update.processor.MultiValUpdateRequestProcessorFactory}
 * given a SolrInputField which has access to multiple values. This is
 * arranged to circumvent DocumentBuilder's limitation.
 */
@Override
public IndexableField createField(SchemaField field, Object value, float boost) {
  if (field.stored())
    throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "This field" +
        "cannot be configured as stored: " + field);
  List<Point> points;
  if (value instanceof SolrInputField) {
    SolrInputField inputField = ((SolrInputField) value);
    points = new ArrayList<Point>(inputField.getValueCount());
    for (Object iVal : inputField.getValues()) {
      points.add(pointFromValue(iVal));
    }
  } else if (value instanceof IndexableField) {//result of MultiValUpdateRequestProcessorFactory
    return (IndexableField) value;
  } else {
    points = Collections.singletonList(pointFromValue(value));
  }

  BytesRef bytes = MultiPointEncoding.pointsToBytes(points);
  return new BinaryDocValuesField(field.getName(), bytes);
}
 
开发者ID:randomstatistic,项目名称:SOLR-5170,代码行数:28,代码来源:MultiPointDocValuesField.java

示例11: writeSolrInputDocument

import org.apache.solr.common.SolrInputField; //导入依赖的package包/类
public void writeSolrInputDocument(SolrInputDocument sdoc) throws IOException {
  List<SolrInputDocument> children = sdoc.getChildDocuments();
  int sz = sdoc.size() + (children==null ? 0 : children.size());
  writeTag(SOLRINPUTDOC, sz);
  writeFloat(sdoc.getDocumentBoost());
  for (SolrInputField inputField : sdoc.values()) {
    if (inputField.getBoost() != 1.0f) {
      writeFloat(inputField.getBoost());
    }
    writeExternString(inputField.getName());
    writeVal(inputField.getValue());
  }
  if (children != null) {
    for (SolrInputDocument child : children) {
      writeSolrInputDocument(child);
    }
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:19,代码来源:JavaBinCodec.java

示例12: testSimple

import org.apache.solr.common.SolrInputField; //导入依赖的package包/类
public void testSimple() throws Exception {
  DocumentObjectBinder binder = new DocumentObjectBinder();
  XMLResponseParser parser = new XMLResponseParser();
  NamedList<Object> nl = parser.processResponse(new StringReader(xml));
  QueryResponse res = new QueryResponse(nl, null);

  SolrDocumentList solDocList = res.getResults();
  List<Item> l = binder.getBeans(Item.class,res.getResults());
  assertEquals(solDocList.size(), l.size());
  assertEquals(solDocList.get(0).getFieldValue("features"), l.get(0).features);

  Item item = new Item();
  item.id = "aaa";
  item.categories = new String[] {"aaa", "bbb", "ccc"};
  SolrInputDocument out = binder.toSolrInputDocument(item);

  assertEquals(item.id, out.getFieldValue("id"));
  SolrInputField catfield = out.getField("cat");
  assertEquals(3, catfield.getValueCount());

  List<String> catValues = (List<String>) catfield.getValue();
  assertEquals("aaa", catValues.get(0));
  assertEquals("bbb", catValues.get(1));
  assertEquals("ccc", catValues.get(2));
}
 
开发者ID:europeana,项目名称:search,代码行数:26,代码来源:TestDocumentObjectBinder.java

示例13: assertSolrInputFieldEquals

import org.apache.solr.common.SolrInputField; //导入依赖的package包/类
public boolean assertSolrInputFieldEquals(Object expected, Object actual) {
  if (!(expected instanceof SolrInputField) || !(actual instanceof  SolrInputField)) {
    return false;
  }

  if (expected == actual) {
    return true;
  }

  SolrInputField sif1 = (SolrInputField) expected;
  SolrInputField sif2 = (SolrInputField) actual;

  if (!sif1.getName().equals(sif2.getName())) {
    return false;
  }

  if (!sif1.getValue().equals(sif2.getValue())) {
    return false;
  }

  if (Float.compare(sif1.getBoost(), sif2.getBoost()) != 0) {
    return false;
  }

  return true;
}
 
开发者ID:europeana,项目名称:search,代码行数:27,代码来源:SolrTestCaseJ4.java

示例14: compare

import org.apache.solr.common.SolrInputField; //导入依赖的package包/类
@Override
public int compare(SolrInputDocument doc1, SolrInputDocument doc2) {
  SolrInputField f1 = doc1.getField(fieldName);
  SolrInputField f2 = doc2.getField(fieldName);
  if (f1 == f2) {
    return 0;
  } else if (f1 == null) {
    return -1;
  } else if (f2 == null) {
    return 1;
  }
  
  Object v1 = f1.getFirstValue();
  Object v2 = f2.getFirstValue();          
  return child.compare(v1, v2);
}
 
开发者ID:europeana,项目名称:search,代码行数:17,代码来源:SolrInputDocumentComparator.java

示例15: load

import org.apache.solr.common.SolrInputField; //导入依赖的package包/类
@Override
public void load(SolrInputDocument doc) throws IOException, SolrServerException {
  String uniqueKeyFieldName = getSchema().getUniqueKeyField().getName();
  Object id = doc.getFieldValue(uniqueKeyFieldName);
  if (id == null) {
    throw new IllegalArgumentException("Missing value for (required) unique document key: " + uniqueKeyFieldName
        + " (see Solr schema.xml)");
  }
  try {
    context.write(new Text(id.toString()), new SolrInputDocumentWritable(doc));
  } catch (InterruptedException e) {
    throw new IOException("Interrupted while writing " + doc, e);
  }

  if (LOG.isDebugEnabled()) {
    long numParserOutputBytes = 0;
    for (SolrInputField field : doc.values()) {
      numParserOutputBytes += sizeOf(field.getValue());
    }
    context.getCounter(MorphlineCounters.class.getName(), MorphlineCounters.PARSER_OUTPUT_BYTES.toString()).increment(numParserOutputBytes);
  }
  context.getCounter(MorphlineCounters.class.getName(), MorphlineCounters.DOCS_READ.toString()).increment(1);
}
 
开发者ID:europeana,项目名称:search,代码行数:24,代码来源:MorphlineMapper.java


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