Examples of ScoreDoc


Examples of org.apache.lucene.search.ScoreDoc

  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

Examples of org.apache.lucene.search.ScoreDoc

          _tmpScoreDoc.doc = doc;
          _tmpScoreDoc.score = score;
          if (!_queueFull || _currentComparator.compare(_bottom, _tmpScoreDoc) > 0) {
            final int order = ((FacetDataCache<?>) groupBy.getFacetData(_currentReader)).orderArray
                .get(doc);
            ScoreDoc pre = _currentValueDocMaps.get(order);
            if (pre != null) {
              if (_currentComparator.compare(pre, _tmpScoreDoc) > 0) {
                ScoreDoc tmp = pre;
                _bottom = _currentQueue.replace(_tmpScoreDoc, pre);
                _currentValueDocMaps.put(order, _tmpScoreDoc);
                _tmpScoreDoc = tmp;
              }
            } else {
              if (_queueFull) {
                MyScoreDoc tmp = (MyScoreDoc) _bottom;
                _currentValueDocMaps
                    .remove(((FacetDataCache<?>) groupBy.getFacetData(tmp.reader)).orderArray
                        .get(tmp.doc));
                _bottom = _currentQueue.replace(_tmpScoreDoc);
                _currentValueDocMaps.put(order, _tmpScoreDoc);
                _tmpScoreDoc = tmp;
              } else {
                ScoreDoc tmp = new MyScoreDoc(doc, score, _currentQueue, _currentReader);
                _bottom = _currentQueue.add(tmp);
                _currentValueDocMaps.put(order, tmp);
                _queueFull = (_currentQueue.size >= _numHits);
              }
            }
          }
        }
      }
    } else {
      if (_count > 0) {
        final float score = (_doScoring ? _scorer.score() : 0.0f);

        if (_queueFull) {
          _tmpScoreDoc.doc = doc;
          _tmpScoreDoc.score = score;

          if (_currentComparator.compare(_bottom, _tmpScoreDoc) > 0) {
            ScoreDoc tmp = _bottom;
            _bottom = _currentQueue.replace(_tmpScoreDoc);
            _tmpScoreDoc = tmp;
          }
        } else {
          _bottom = _currentQueue.add(new MyScoreDoc(doc, score, _currentQueue, _currentReader));
View Full Code Here

Examples of org.apache.lucene.search.ScoreDoc

            return matches;
        }

        // track the last discovered hit so we can re-execute the query if we are
        // deduping and need to fill results
        ScoreDoc lastDoc = null;
        do {
            // collect all the hits up to maxResults, and sort them based
            // on Lucene match score and population for the associated
            // GeoNames record
            TopDocs results = indexSearcher.searchAfter(lastDoc, query, filter, maxResults, POPULATION_SORT);
View Full Code Here

Examples of org.apache.lucene.search.ScoreDoc

    private List<String> convertToIds(TopDocs docs, int offset) throws EventSearchServiceException {
        List<String> eventIds = new ArrayList<String>();

        for (int i = offset; i < docs.scoreDocs.length; ++i) {
            ScoreDoc doc = docs.scoreDocs[i];
            Document document = LuceneService.get().getDocument(doc.doc);
            String id = document.get("ID");
            if (id == null)
                continue;
View Full Code Here

Examples of org.apache.lucene.search.ScoreDoc

  private int numHits;

  public PagingCollector(int numHits) {
    // creates an empty score doc so that i don't have to check for null
    // each time.
    this(numHits, new ScoreDoc(-1, Float.MAX_VALUE));
  }
View Full Code Here

Examples of org.apache.lucene.search.ScoreDoc

      super(size, prePopulate);
    }

    @Override
    protected ScoreDoc getSentinelObject() {
      return new ScoreDoc(Integer.MAX_VALUE, Float.NEGATIVE_INFINITY);
    }
View Full Code Here

Examples of org.apache.lucene.search.ScoreDoc

  private void doTestExactScore (String field, FieldScoreQuery.Type tp) throws CorruptIndexException, Exception {
    IndexSearcher s = new IndexSearcher(dir);
    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

Examples of org.apache.lucene.search.ScoreDoc

    // and all the similarity factors are set to 1
    hits = searcher.search(query, null, 100);
    assertTrue("hits is null and it shouldn't be", hits != null);
    assertTrue("should be 10 hits", hits.totalHits == 10);
    for (int j = 0; j < hits.scoreDocs.length; j++) {
      ScoreDoc doc = hits.scoreDocs[j];
      assertTrue(doc.score + " does not equal: " + 3, doc.score == 3);
    }
    for (int i=1;i<10;i++) {
      query = newPhraseQuery("field", English.intToEnglish(i)+" hundred", true);
      // all should have score = 3 because adjacent terms have payloads of 2,4
      // and all the similarity factors are set to 1
      hits = searcher.search(query, null, 100);
      assertTrue("hits is null and it shouldn't be", hits != null);
      assertTrue("should be 100 hits", hits.totalHits == 100);
      for (int j = 0; j < hits.scoreDocs.length; j++) {
        ScoreDoc doc = hits.scoreDocs[j];
//        System.out.println("Doc: " + doc.toString());
//        System.out.println("Explain: " + searcher.explain(query, doc.doc));
        assertTrue(doc.score + " does not equal: " + 3, doc.score == 3);
      }
    }
View Full Code Here

Examples of org.apache.lucene.search.ScoreDoc

  public void testLongerSpan() throws IOException {
    PayloadNearQuery query;
    TopDocs hits;
    query = newPhraseQuery("field", "nine hundred ninety nine", true);
    hits = searcher.search(query, null, 100);
    ScoreDoc doc = hits.scoreDocs[0];
//    System.out.println("Doc: " + doc.toString());
//    System.out.println("Explain: " + searcher.explain(query, doc.doc));
    assertTrue("hits is null and it shouldn't be", hits != null);
    assertTrue("there should only be one hit", hits.totalHits == 1);
    // should have score = 3 because adjacent terms have payloads of 2,4
View Full Code Here

Examples of org.apache.lucene.search.ScoreDoc

    hits = searcher.search(query, null, 100);
    assertTrue("hits is null and it shouldn't be", hits != null);
    // should be only 1 hit - doc 999
    assertTrue("should only be one hit", hits.scoreDocs.length == 1);
    // the score should be 3 - the average of all the underlying payloads
    ScoreDoc doc = hits.scoreDocs[0];
//    System.out.println("Doc: " + doc.toString());
//    System.out.println("Explain: " + searcher.explain(query, doc.doc));
    assertTrue(doc.score + " does not equal: " + 3, doc.score == 3)
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.