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


Java FieldDoc类代码示例

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


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

示例1: assertAvgScoreMode

import org.apache.lucene.search.FieldDoc; //导入依赖的package包/类
@Override
protected void assertAvgScoreMode(Query parentFilter, IndexSearcher searcher) throws IOException {
    MultiValueMode sortMode = MultiValueMode.AVG;
    Query childFilter = Queries.not(parentFilter);
    XFieldComparatorSource nestedComparatorSource = createFieldComparator("field2", sortMode, -127, createNested(searcher, parentFilter, childFilter));
    Query query = new ToParentBlockJoinQuery(new ConstantScoreQuery(childFilter), new QueryBitSetProducer(parentFilter), ScoreMode.None);
    Sort sort = new Sort(new SortField("field2", nestedComparatorSource));
    TopDocs topDocs = searcher.search(query, 5, sort);
    assertThat(topDocs.totalHits, equalTo(7));
    assertThat(topDocs.scoreDocs.length, equalTo(5));
    assertThat(topDocs.scoreDocs[0].doc, equalTo(11));
    assertThat(((Number) ((FieldDoc) topDocs.scoreDocs[0]).fields[0]).intValue(), equalTo(2));
    assertThat(topDocs.scoreDocs[1].doc, equalTo(7));
    assertThat(((Number) ((FieldDoc) topDocs.scoreDocs[1]).fields[0]).intValue(), equalTo(2));
    assertThat(topDocs.scoreDocs[2].doc, equalTo(3));
    assertThat(((Number) ((FieldDoc) topDocs.scoreDocs[2]).fields[0]).intValue(), equalTo(3));
    assertThat(topDocs.scoreDocs[3].doc, equalTo(15));
    assertThat(((Number) ((FieldDoc) topDocs.scoreDocs[3]).fields[0]).intValue(), equalTo(3));
    assertThat(topDocs.scoreDocs[4].doc, equalTo(19));
    assertThat(((Number) ((FieldDoc) topDocs.scoreDocs[4]).fields[0]).intValue(), equalTo(3));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:DoubleNestedSortingTests.java

示例2: assertAvgScoreMode

import org.apache.lucene.search.FieldDoc; //导入依赖的package包/类
protected void assertAvgScoreMode(Query parentFilter, IndexSearcher searcher, IndexFieldData.XFieldComparatorSource innerFieldComparator) throws IOException {
    MultiValueMode sortMode = MultiValueMode.AVG;
    Query childFilter = Queries.not(parentFilter);
    XFieldComparatorSource nestedComparatorSource = createFieldComparator("field2", sortMode, -127, createNested(searcher, parentFilter, childFilter));
    Query query = new ToParentBlockJoinQuery(new ConstantScoreQuery(childFilter), new QueryBitSetProducer(parentFilter), ScoreMode.None);
    Sort sort = new Sort(new SortField("field2", nestedComparatorSource));
    TopDocs topDocs = searcher.search(query, 5, sort);
    assertThat(topDocs.totalHits, equalTo(7));
    assertThat(topDocs.scoreDocs.length, equalTo(5));
    assertThat(topDocs.scoreDocs[0].doc, equalTo(11));
    assertThat(((Number) ((FieldDoc) topDocs.scoreDocs[0]).fields[0]).intValue(), equalTo(2));
    assertThat(topDocs.scoreDocs[1].doc, equalTo(7));
    assertThat(((Number) ((FieldDoc) topDocs.scoreDocs[1]).fields[0]).intValue(), equalTo(2));
    assertThat(topDocs.scoreDocs[2].doc, equalTo(3));
    assertThat(((Number) ((FieldDoc) topDocs.scoreDocs[2]).fields[0]).intValue(), equalTo(3));
    assertThat(topDocs.scoreDocs[3].doc, equalTo(15));
    assertThat(((Number) ((FieldDoc) topDocs.scoreDocs[3]).fields[0]).intValue(), equalTo(3));
    assertThat(topDocs.scoreDocs[4].doc, equalTo(19));
    assertThat(((Number) ((FieldDoc) topDocs.scoreDocs[4]).fields[0]).intValue(), equalTo(3));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:FloatNestedSortingTests.java

示例3: assertAvgScoreMode

import org.apache.lucene.search.FieldDoc; //导入依赖的package包/类
protected void assertAvgScoreMode(Query parentFilter, IndexSearcher searcher) throws IOException {
    MultiValueMode sortMode = MultiValueMode.AVG;
    Query childFilter = Queries.not(parentFilter);
    XFieldComparatorSource nestedComparatorSource = createFieldComparator("field2", sortMode, -127, createNested(searcher, parentFilter, childFilter));
    Query query = new ToParentBlockJoinQuery(new ConstantScoreQuery(childFilter), new QueryBitSetProducer(parentFilter), ScoreMode.None);
    Sort sort = new Sort(new SortField("field2", nestedComparatorSource));
    TopDocs topDocs = searcher.search(query, 5, sort);
    assertThat(topDocs.totalHits, equalTo(7));
    assertThat(topDocs.scoreDocs.length, equalTo(5));
    assertThat(topDocs.scoreDocs[0].doc, equalTo(11));
    assertThat(((Number) ((FieldDoc) topDocs.scoreDocs[0]).fields[0]).intValue(), equalTo(2));
    assertThat(topDocs.scoreDocs[1].doc, equalTo(3));
    assertThat(((Number) ((FieldDoc) topDocs.scoreDocs[1]).fields[0]).intValue(), equalTo(3));
    assertThat(topDocs.scoreDocs[2].doc, equalTo(7));
    assertThat(((Number) ((FieldDoc) topDocs.scoreDocs[2]).fields[0]).intValue(), equalTo(3));
    assertThat(topDocs.scoreDocs[3].doc, equalTo(15));
    assertThat(((Number) ((FieldDoc) topDocs.scoreDocs[3]).fields[0]).intValue(), equalTo(3));
    assertThat(topDocs.scoreDocs[4].doc, equalTo(19));
    assertThat(((Number) ((FieldDoc) topDocs.scoreDocs[4]).fields[0]).intValue(), equalTo(4));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:AbstractNumberNestedSortingTestCase.java

示例4: doEquals

import org.apache.lucene.search.FieldDoc; //导入依赖的package包/类
@Override
protected boolean doEquals(Object obj) {
    InternalTopHits other = (InternalTopHits) obj;
    if (from != other.from) return false;
    if (size != other.size) return false;
    if (topDocs.totalHits != other.topDocs.totalHits) return false;
    if (topDocs.scoreDocs.length != other.topDocs.scoreDocs.length) return false;
    for (int d = 0; d < topDocs.scoreDocs.length; d++) {
        ScoreDoc thisDoc = topDocs.scoreDocs[d];
        ScoreDoc otherDoc = other.topDocs.scoreDocs[d];
        if (thisDoc.doc != otherDoc.doc) return false;
        if (Double.compare(thisDoc.score, otherDoc.score) != 0) return false;
        if (thisDoc.shardIndex != otherDoc.shardIndex) return false;
        if (thisDoc instanceof FieldDoc) {
            if (false == (otherDoc instanceof FieldDoc)) return false;
            FieldDoc thisFieldDoc = (FieldDoc) thisDoc;
            FieldDoc otherFieldDoc = (FieldDoc) otherDoc;
            if (thisFieldDoc.fields.length != otherFieldDoc.fields.length) return false;
            for (int f = 0; f < thisFieldDoc.fields.length; f++) {
                if (false == thisFieldDoc.fields[f].equals(otherFieldDoc.fields[f])) return false;
            }
        }
    }
    return searchHits.equals(other.searchHits);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:26,代码来源:InternalTopHits.java

示例5: doHashCode

import org.apache.lucene.search.FieldDoc; //导入依赖的package包/类
@Override
protected int doHashCode() {
    int hashCode = from;
    hashCode = 31 * hashCode + size;
    hashCode = 31 * hashCode + topDocs.totalHits;
    for (int d = 0; d < topDocs.scoreDocs.length; d++) {
        ScoreDoc doc = topDocs.scoreDocs[d];
        hashCode = 31 * hashCode + doc.doc;
        hashCode = 31 * hashCode + Float.floatToIntBits(doc.score);
        hashCode = 31 * hashCode + doc.shardIndex;
        if (doc instanceof FieldDoc) {
            FieldDoc fieldDoc = (FieldDoc) doc;
            hashCode = 31 * hashCode + Arrays.hashCode(fieldDoc.fields);
        }
    }
    hashCode = 31 * hashCode + searchHits.hashCode();
    return hashCode;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:InternalTopHits.java

示例6: writeTo

import org.apache.lucene.search.FieldDoc; //导入依赖的package包/类
@Override
public void writeTo(StreamOutput out) throws IOException {
    super.writeTo(out);
    out.writeLong(id);
    out.writeVInt(size);
    for (int i = 0; i < size; i++) {
        out.writeVInt(docIds[i]);
    }
    if (lastEmittedDoc == null) {
        out.writeByte((byte) 0);
    } else if (lastEmittedDoc instanceof FieldDoc) {
        out.writeByte((byte) 1);
        Lucene.writeFieldDoc(out, (FieldDoc) lastEmittedDoc);
    } else {
        out.writeByte((byte) 2);
        Lucene.writeScoreDoc(out, lastEmittedDoc);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:ShardFetchRequest.java

示例7: testSortValues

import org.apache.lucene.search.FieldDoc; //导入依赖的package包/类
public void testSortValues() throws Exception {
    Directory dir = new RAMDirectory();
    IndexWriter indexWriter = new IndexWriter(dir, new IndexWriterConfig(Lucene.STANDARD_ANALYZER));
    for (int i = 0; i < 10; i++) {
        Document document = new Document();
        String text = new String(new char[]{(char) (97 + i), (char) (97 + i)});
        document.add(new TextField("str", text, Field.Store.YES));
        document.add(new SortedDocValuesField("str", new BytesRef(text)));
        indexWriter.addDocument(document);
    }
    IndexReader reader = SlowCompositeReaderWrapper.wrap(DirectoryReader.open(indexWriter));
    IndexSearcher searcher = new IndexSearcher(reader);
    TopFieldDocs docs = searcher.search(new MatchAllDocsQuery(), 10, new Sort(new SortField("str", SortField.Type.STRING)));
    for (int i = 0; i < 10; i++) {
        FieldDoc fieldDoc = (FieldDoc) docs.scoreDocs[i];
        assertThat((BytesRef) fieldDoc.fields[0], equalTo(new BytesRef(new String(new char[]{(char) (97 + i), (char) (97 + i)}))));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:SimpleLuceneTests.java

示例8: apply

import org.apache.lucene.search.FieldDoc; //导入依赖的package包/类
@Nullable
@Override
public Row apply(@Nullable ScoreDoc input) {
    if (input == null) {
        return null;
    }
    FieldDoc fieldDoc = (FieldDoc) input;
    scorer.score(fieldDoc.score);
    for (OrderByCollectorExpression orderByCollectorExpression : orderByCollectorExpressions) {
        orderByCollectorExpression.setNextFieldDoc(fieldDoc);
    }
    List<LeafReaderContext> leaves = indexReader.leaves();
    int readerIndex = ReaderUtil.subIndex(fieldDoc.doc, leaves);
    LeafReaderContext subReaderContext = leaves.get(readerIndex);
    int subDoc = fieldDoc.doc - subReaderContext.docBase;
    for (LuceneCollectorExpression<?> expression : expressions) {
        expression.setNextReader(subReaderContext);
        expression.setNextDocId(subDoc);
    }
    return inputRow;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:22,代码来源:ScoreDocRowFunction.java

示例9: parseLindenHits

import org.apache.lucene.search.FieldDoc; //导入依赖的package包/类
private List<LindenHit> parseLindenHits(ScoreDoc[] hits) throws IOException {
  List<LindenHit> lindenHits = new ArrayList<>();
  String idFieldName = config.getSchema().getId();
  for (ScoreDoc hit : hits) {
    LindenHit lindenHit = new LindenHit();
    if (Double.isNaN(hit.score)) {
      // get score for cluster result merge
      if (sortScoreFieldPos != -1) {
        lindenHit.setScore(Double.valueOf(((FieldDoc) hit).fields[sortScoreFieldPos].toString()));
      } else {
        lindenHit.setScore(1);
      }
    } else {
      lindenHit.setScore(hit.score);
    }
    String id = LindenUtil.getFieldStringValue(leaves, hit.doc, idFieldName);
    lindenHit.setId(id);
    lindenHit = this.parseSpatial(hit.doc, lindenHit);
    lindenHit = this.parseSort(hit, lindenHit);
    lindenHit = this.parseSource(hit.doc, lindenHit);
    lindenHit = this.parseExplain(hit.doc, lindenHit);
    lindenHits.add(lindenHit);
  }
  lindenHits = this.parseSnippets(lindenHits, hits);
  return lindenHits;
}
 
开发者ID:XiaoMi,项目名称:linden,代码行数:27,代码来源:LindenResultParser.java

示例10: parseSort

import org.apache.lucene.search.FieldDoc; //导入依赖的package包/类
private LindenHit parseSort(ScoreDoc hit, LindenHit lindenHit) {
  if (request.isSetSort()) {
    Map<String, String> fieldMap = new HashMap<>();
    for (int i = 0; i < request.getSort().getFields().size(); ++i) {
      LindenSortField field = request.getSort().getFields().get(i);
      if (field.type == LindenSortType.SCORE || field.type == LindenSortType.DISTANCE) {
        continue;
      }
      Object value = ((FieldDoc) hit).fields[i];
      if (value == null) {
        continue;
      }
      if (field.type == LindenSortType.STRING) {
        fieldMap.put(field.getName(), ((BytesRef) value).utf8ToString());
      } else {
        fieldMap.put(field.getName(), value.toString());
      }
    }
    lindenHit.setFields(fieldMap);
  }
  return lindenHit;
}
 
开发者ID:XiaoMi,项目名称:linden,代码行数:23,代码来源:LindenResultParser.java

示例11: serialize

import org.apache.lucene.search.FieldDoc; //导入依赖的package包/类
@Override
public byte[] serialize(final FieldDoc doc) {
    if (doc == null) {
        throw new IllegalArgumentException("FieldDoc cannot be null");
    }

    try {
        final SerializableFieldDoc sFieldDoc = new SerializableFieldDoc();
        sFieldDoc.setScore(doc.score);
        sFieldDoc.setDoc(doc.doc);
        sFieldDoc.setShardIndex(doc.shardIndex);
        sFieldDoc.setFields(doc.fields);

        return mapper.writeValueAsBytes(sFieldDoc);
    } catch (Exception e) {
        throw new SerializationException("Unable to serialize FieldDoc due to :" + e.getMessage(), e);
    }
}
 
开发者ID:bbende,项目名称:tripod,代码行数:19,代码来源:StandardFieldDocSerializer.java

示例12: deserialize

import org.apache.lucene.search.FieldDoc; //导入依赖的package包/类
@Override
public FieldDoc deserialize(byte[] bytes) {
    if (bytes == null) {
        throw new IllegalArgumentException("Bytes cannot be null");
    }

    try {
        final SerializableFieldDoc sFieldDoc = mapper.readValue(bytes, SerializableFieldDoc.class);

        final FieldDoc fieldDoc = new FieldDoc(
                sFieldDoc.getDoc(),
                sFieldDoc.getScore(),
                sFieldDoc.getFields(),
                sFieldDoc.getShardIndex()
        );

        return fieldDoc;
    } catch (Exception e) {
        throw new SerializationException("Unable to deserialize bytes due to :" + e.getMessage(), e);
    }
}
 
开发者ID:bbende,项目名称:tripod,代码行数:22,代码来源:StandardFieldDocSerializer.java

示例13: testSortValues

import org.apache.lucene.search.FieldDoc; //导入依赖的package包/类
/** tests the returned sort values are correct */
public void testSortValues() throws Exception {
  Expression expr = JavascriptCompiler.compile("sqrt(_score)");
  
  SimpleBindings bindings = new SimpleBindings();    
  bindings.add(new SortField("_score", SortField.Type.SCORE));
  
  Sort sort = new Sort(expr.getSortField(bindings, true));
  Query query = new TermQuery(new Term("body", "contents"));
  TopFieldDocs td = searcher.search(query, null, 3, sort, true, true);
  for (int i = 0; i < 3; i++) {
    FieldDoc d = (FieldDoc) td.scoreDocs[i];
    float expected = (float) Math.sqrt(d.score);
    float actual = ((Double)d.fields[0]).floatValue();
    assertEquals(expected, actual, CheckHits.explainToleranceDelta(expected, actual));
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:18,代码来源:TestDemoExpressions.java

示例14: testTwoOfSameBinding

import org.apache.lucene.search.FieldDoc; //导入依赖的package包/类
/** tests same binding used more than once in an expression */
public void testTwoOfSameBinding() throws Exception {
  Expression expr = JavascriptCompiler.compile("_score + _score");
  
  SimpleBindings bindings = new SimpleBindings();    
  bindings.add(new SortField("_score", SortField.Type.SCORE));
  
  Sort sort = new Sort(expr.getSortField(bindings, true));
  Query query = new TermQuery(new Term("body", "contents"));
  TopFieldDocs td = searcher.search(query, null, 3, sort, true, true);
  for (int i = 0; i < 3; i++) {
    FieldDoc d = (FieldDoc) td.scoreDocs[i];
    float expected = 2*d.score;
    float actual = ((Double)d.fields[0]).floatValue();
    assertEquals(expected, actual, CheckHits.explainToleranceDelta(expected, actual));
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:18,代码来源:TestDemoExpressions.java

示例15: testDollarVariable

import org.apache.lucene.search.FieldDoc; //导入依赖的package包/类
/** Uses variables with $ */
public void testDollarVariable() throws Exception {
  Expression expr = JavascriptCompiler.compile("$0+$score");
  
  SimpleBindings bindings = new SimpleBindings();    
  bindings.add(new SortField("$0", SortField.Type.SCORE));
  bindings.add(new SortField("$score", SortField.Type.SCORE));
  
  Sort sort = new Sort(expr.getSortField(bindings, true));
  Query query = new TermQuery(new Term("body", "contents"));
  TopFieldDocs td = searcher.search(query, null, 3, sort, true, true);
  for (int i = 0; i < 3; i++) {
    FieldDoc d = (FieldDoc) td.scoreDocs[i];
    float expected = 2*d.score;
    float actual = ((Double)d.fields[0]).floatValue();
    assertEquals(expected, actual, CheckHits.explainToleranceDelta(expected, actual));
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:19,代码来源:TestDemoExpressions.java


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