Package org.apache.lucene.search

Examples of org.apache.lucene.search.TopDocs


   
    //<start id="lucene.examples.mlt.query"/>
    Reader reader = new FileReader(inputPath); //<co id="mlt.query"/>
    Query query = moreLikeThis.like(reader);

    TopDocs results
      = indexSearcher.search(query, maxResults); //<co id="mlt.search"/>
   
    HashMap<String, CategoryHits> categoryHash
      = new HashMap<String, CategoryHits>();
   
View Full Code Here


  //just a simple test of the cosine overlap discussion in the Fuzzy chapter.
  @Test
  public void testCosine() throws Exception {
    OverlapMeasures om = new OverlapMeasures();
    TopDocs docs = om.cosine("chars:mob", 10, "bob", "fob", "job", "cob", "bobo");
    if (docs != null) {
      System.out.println("Total hits: " + docs.totalHits);
      for (int i = 0; i < docs.scoreDocs.length; i++){
        System.out.println("Id: " + docs.scoreDocs[i].doc + " score: " + docs.scoreDocs[i].score);
      }
View Full Code Here

      }

      // If numTerms==0, the call is just asking for a quick field list
      if( ttinfo != null && sfield != null && sfield.indexed() ) {
        Query q = new TermRangeQuery(fieldName,null,null,false,false);
        TopDocs top = searcher.search( q, 1 );
        if( top.totalHits > 0 ) {
          // Find a document with this field
          try {
            Document doc = searcher.doc( top.scoreDocs[0].doc );
            Fieldable fld = doc.getFieldable( fieldName );
View Full Code Here

            score = Float.NaN;
          }
          Object[] sortValues = ((List) document.get("sortValues")).toArray();
          scoreDocs[j++] = new ShardDoc(score, sortValues, uniqueId, shard);
        }
        result.put(key, new QueryCommandResult(new TopDocs(totalHits, scoreDocs, maxScore, sum, max, min), matches));
        continue;
      }

      Integer totalHitCount = (Integer) commandResult.get("totalHitCount");
      Integer totalGroupCount = (Integer) commandResult.get("totalGroupCount");
View Full Code Here

        for(ScoreDoc sd : shardGroupDocs.scoreDocs) {
          System.out.println("      doc=" + sd.doc);
        }
        */

        shardTopDocs[shardIDX] = new TopDocs(shardGroupDocs.totalHits,
                                             shardGroupDocs.scoreDocs,
                                             shardGroupDocs.maxScore,
                       shardGroupDocs.sum,
                       shardGroupDocs.max,
                       shardGroupDocs.min);
        maxScore = Math.max(maxScore, shardGroupDocs.maxScore);
    sum += shardGroupDocs.sum;
    max = Math.max(max, shardGroupDocs.max);
    min = Math.min(min, shardGroupDocs.min);
        totalHits += shardGroupDocs.totalHits;
      }

      final TopDocs mergedTopDocs = TopDocs.merge(docSort, docOffset + docTopN, shardTopDocs);

      // Slice;
      final ScoreDoc[] mergedScoreDocs;
      if (docOffset == 0) {
        mergedScoreDocs = mergedTopDocs.scoreDocs;
View Full Code Here

        }
      } else {
        groupSortValues = null;
      }

      final TopDocs topDocs = collector.topDocs(withinGroupOffset, maxDocsPerGroup);

      groups[downTo] = new GroupDocs<Object>(topDocs.getMaxScore(),
                                     og.count,
                                     topDocs.scoreDocs,
                                     null,
                                     groupSortValues,
                   topDocs.getSum(),
                   topDocs.getMax(),
                   topDocs.getMin());
    }

    /*
    while (groupQueue.size() != 0) {
      final OneGroup og = groupQueue.pop();
View Full Code Here

      writer.addDocument(doc);
    }
    writer.close();
    IndexReader reader = IndexReader.open(directory);
    IndexSearcher searcher = new IndexSearcher(reader);
    TopDocs topDocs = searcher.search(new MatchAllDocsQuery(), terms.length);
    for (int i = 0; i < topDocs.scoreDocs.length; i++){
        System.out.println("Id: " + topDocs.scoreDocs[i].doc + " Val: " + searcher.doc(topDocs.scoreDocs[i].doc).get("chars"));
    }
    QueryParser qp = new QueryParser(Version.LUCENE_36, "chars", analyzer);
    Query query = qp.parse(queryTerm);
View Full Code Here

  public void testUnaryClause() throws IOException {
    this.addDocument("\"aaa ccc\" \"bbb ccc\" . \"aaa bbb\" \"ccc eee\" . ");

    // {[aaa]}
    Query query = tuple().optional(nbq(should("aaa"))).getLuceneProxyQuery();
    TopDocs hits = searcher.search(query, 100);
    assertEquals(1, hits.totalHits);

    // {[ccc]}
    query = tuple().optional(nbq(should("ccc"))).getLuceneProxyQuery();
    hits = searcher.search(query, 100);
View Full Code Here

    final Query q = nbq(
      must(nbq(should("aaa"), should("bbb"))),
      should(nbq(should("ccc"), should("ddd")))
    ).getLuceneProxyQuery();

    final TopDocs docs = searcher.search(q, 10);
    assertEquals(2, docs.totalHits);
    assertEquals(0, docs.scoreDocs[0].doc); // first doc should be ranked higher

  }
View Full Code Here

    .setRewriteMethod(MultiNodeTermQuery.CONSTANT_SCORE_BOOLEAN_QUERY_REWRITE)
    .bound(2, 2)))).getLuceneProxyQuery();

    final String type = " (constant score boolean rewrite)";

    final TopDocs topDocs = index.searcher.search(dq, null, noDocs, Sort.INDEXORDER);

    final ScoreDoc[] sd = topDocs.scoreDocs;
    assertNotNull(sd);
    assertEquals("Score doc count"+type, count, sd.length );
    Document doc=index.searcher.doc(sd[0].doc);
View Full Code Here

TOP

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

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.