Package org.apache.lucene.search

Examples of org.apache.lucene.search.ScoreDoc


//    }
//    CheckHits.checkHits(random(), q, "", indexSearcher, expectedDocs);

    TopDocs docs = indexSearcher.search(q, 1000);//calculates the score
    for (int i = 0; i < docs.scoreDocs.length; i++) {
      ScoreDoc gotSD = docs.scoreDocs[i];
      float expectedScore = scores[gotSD.doc];
      assertEquals("Not equal for doc "+gotSD.doc, expectedScore, gotSD.score, delta);
    }

    CheckHits.checkExplanations(q, "", indexSearcher);
View Full Code Here


    });
    ScoreDoc[] scoreDocs = new ScoreDoc[Math.min(10, hits.size())];
    for (int i = 0; i < scoreDocs.length; i++) {
      Map.Entry<Integer,JoinScore> hit = hits.get(i);
      scoreDocs[i] = new ScoreDoc(hit.getKey(), hit.getValue().score(scoreMode));
    }
    return new TopDocs(hits.size(), scoreDocs, hits.isEmpty() ? Float.NaN : hits.get(0).getValue().score(scoreMode));
  }
View Full Code Here

      throws IOException {

    List<LookupResult> results = new ArrayList<LookupResult>();
    BytesRef scratch = new BytesRef();
    for (int i=0;i<hits.scoreDocs.length;i++) {
      ScoreDoc sd = hits.scoreDocs[i];
      textDV.get(sd.doc, scratch);
      String text = scratch.utf8ToString();
      long score = weightsDV.get(sd.doc);

      BytesRef payload;
View Full Code Here

   * @throws IOException if an I/O error occurred during processing
   * @throws IllegalArgumentException if <code>field</code> was indexed without
   *         {@link IndexOptions#DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS}
   */
  public Map<String,String[]> highlightFields(String fields[], Query query, IndexSearcher searcher, TopDocs topDocs, int maxPassages[]) throws IOException {
    final ScoreDoc scoreDocs[] = topDocs.scoreDocs;
    int docids[] = new int[scoreDocs.length];
    for (int i = 0; i < docids.length; i++) {
      docids[i] = scoreDocs[i].doc;
    }

View Full Code Here

  public static void assertEquals(TopDocs expected, TopDocs actual) {
    Assert.assertEquals("wrong total hits", expected.totalHits, actual.totalHits);
    Assert.assertEquals("wrong maxScore", expected.getMaxScore(), actual.getMaxScore(), 0.0);
    Assert.assertEquals("wrong hit count", expected.scoreDocs.length, actual.scoreDocs.length);
    for(int hitIDX=0;hitIDX<expected.scoreDocs.length;hitIDX++) {
      final ScoreDoc expectedSD = expected.scoreDocs[hitIDX];
      final ScoreDoc actualSD = actual.scoreDocs[hitIDX];
      Assert.assertEquals("wrong hit docID", expectedSD.doc, actualSD.doc);
      Assert.assertEquals("wrong hit score", expectedSD.score, actualSD.score, 0.0);
      if (expectedSD instanceof FieldDoc) {
        Assert.assertTrue(actualSD instanceof FieldDoc);
        Assert.assertArrayEquals("wrong sort field values",
View Full Code Here

    TermQuery query = new TermQuery(new Term("f1", "value"));
    IterablePaging paging = new IterablePaging(new AtomicBoolean(true), searcher, query, 100, null, null, false);
    IterablePaging itPaging = paging.skipTo(90).gather(20).totalHits(totalHitsRef).progress(progressRef);
    BlurIterator<ScoreDoc, BlurException> iterator = itPaging.iterator();
    while (iterator.hasNext()) {
      ScoreDoc sd = iterator.next();
      System.out.println("time [" + progressRef.queryTime() + "] " + "total hits [" + totalHitsRef.totalHits() + "] "
          + "searches [" + progressRef.searchesPerformed() + "] " + "position [" + progressRef.currentHitPosition()
          + "] " + "doc id [" + sd.doc + "] " + "score [" + sd.score + "]");
    }
  }
View Full Code Here

  private void doTestExactScore (String field, FieldScoreQuery.Type tp) throws CorruptIndexException, Exception {
    IndexSearcher s = new IndexSearcher(dir, true);
    Query q = new FieldScoreQuery(field,tp);
    TopDocs td = s.search(q,null,1000);
    assertEquals("All docs should be matched!",N_DOCS,td.totalHits);
    ScoreDoc sd[] = td.scoreDocs;
    for (int i=0; i<sd.length; i++) {
      float score = sd[i].score;
      log(s.explain(q,sd[i].doc));
      String id = s.getIndexReader().document(sd[i].doc).get(ID_FIELD);
      float expectedScore = expectedFieldScore(id); // "ID7" --> 7.0
View Full Code Here

      vs = new ReverseOrdFieldSource(field);
    }
    Query q = new ValueSourceQuery(vs);
    TopDocs td = s.search(q,null,1000);
    assertEquals("All docs should be matched!",N_DOCS,td.totalHits);
    ScoreDoc sd[] = td.scoreDocs;
    for (int i=0; i<sd.length; i++) {
      float score = sd[i].score;
      String id = s.getIndexReader().document(sd[i].doc).get(ID_FIELD);
      log("-------- "+i+". Explain doc "+id);
      log(s.explain(q,sd[i].doc));
View Full Code Here

             * @return true if any document is loaded
             */
            private boolean loadDocs() {
                IndexNode indexNode = null;
                IndexSearcher searcher = null;
                ScoreDoc lastDocToRecord = null;
                try {
                    indexNode = acquire();
                    searcher = indexNode.acquireSearcher();
                    Query query = getQuery(filter, searcher.getIndexReader(),
                            nonFullTextConstraints, analyzer, index.getDefinition());
View Full Code Here

                    resultDocsSize = scoreDocs.length - result.from();
                }
                if (result.topDocs() instanceof TopFieldDocs) {
                    ShardDoc[] docs = new ShardDoc[resultDocsSize];
                    for (int i = 0; i < resultDocsSize; i++) {
                        ScoreDoc scoreDoc = scoreDocs[result.from() + i];
                        docs[i] = new ShardFieldDoc(result.shardTarget(), scoreDoc.doc, scoreDoc.score, ((FieldDoc) scoreDoc).fields);
                    }
                    return docs;
                } else {
                    ShardDoc[] docs = new ShardDoc[resultDocsSize];
                    for (int i = 0; i < resultDocsSize; i++) {
                        ScoreDoc scoreDoc = scoreDocs[result.from() + i];
                        docs[i] = new ShardScoreDoc(result.shardTarget(), scoreDoc.doc, scoreDoc.score);
                    }
                    return docs;
                }
            }
View Full Code Here

TOP

Related Classes of org.apache.lucene.search.ScoreDoc

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.