Package org.apache.lucene.search

Examples of org.apache.lucene.search.IndexSearcher.doc()


    // make sure they "took":
    searcher = new IndexSearcher(dir);
    hits = searcher.search(new TermQuery(new Term("content", "aaa")), null, 1000).scoreDocs;
    assertEquals("wrong number of hits", 33, hits.length);
    d = searcher.doc(hits[0].doc);
    assertEquals("wrong first document", "22", d.get("id"));
    testHits(hits, 33, searcher.getIndexReader());
    searcher.close();

    // optimize
View Full Code Here


    writer.close();

    searcher = new IndexSearcher(dir);
    hits = searcher.search(new TermQuery(new Term("content", "aaa")), null, 1000).scoreDocs;
    assertEquals("wrong number of hits", 33, hits.length);
    d = searcher.doc(hits[0].doc);
    assertEquals("wrong first document", "22", d.get("id"));
    testHits(hits, 33, searcher.getIndexReader());
    searcher.close();

    dir.close();
View Full Code Here

        ScoreDoc[] hits = results.scoreDocs;
        float total_score = 0;
        //add up the scores
        for (ScoreDoc hit : hits) {
            Document doc = searcher.doc(hit.doc);
            //System.err.printf("%5.3f %sn\n",
             //   hit.score, doc.get("contents"));
            total_score += hit.score;
        }
View Full Code Here

      // try the search over the first doc
      IndexSearcher indexSearcher = new IndexSearcher(writer.getReader());
      TopDocs result = indexSearcher.search(
              new MatchAllDocsQuery("contents"), 10);
      assertTrue(result.totalHits > 0);
      Document d = indexSearcher.doc(result.scoreDocs[0].doc);
      assertNotNull(d);
      assertNotNull(d.getFieldable("title"));
      assertNotNull(d.getFieldable("contents"));

      // add a second doc
View Full Code Here

      indexSearcher = new IndexSearcher(writer.getReader());
      result = indexSearcher.search(
              new MatchAllDocsQuery("contents"), 10);
      assertTrue(result.totalHits > 0);
      for (ScoreDoc di : result.scoreDocs) {
        d = indexSearcher.doc(di.doc);
        assertNotNull(d);
        assertNotNull(d.getFieldable("title"));
        assertNotNull(d.getFieldable("contents"));
      }
    } catch (Exception e) {
View Full Code Here

    searcher.setSimilarityProvider(this.similarityProvider);
   
    ScoreDoc[] hits = searcher.search(bq, limit).scoreDocs;

    for (ScoreDoc hit : hits) {
      Document doc = searcher.doc(hit.doc);
      results.list.add(doc.get("title"));

      // if not empty => relevant
      if (!doc.get("relevance").isEmpty()) {
        results.relevantResults++;
View Full Code Here

    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);
    return searcher.search(query, n);
  }
View Full Code Here

  public Document retrieve(final int docID) throws IOException {
    IndexSearcher searcher = mgr.acquire();

    try {
      return searcher.doc(docID);
    }
    finally {
      mgr.release(searcher);
      searcher = null;
    }
View Full Code Here

     
      List<T> tList = new ArrayList<T>();
      Document document;
      T tObject;
      for(int i=0;i<maxResults && i+fromIndex<resultSize;i++) {
        document = searcher.doc(scoreDocs[i+fromIndex].doc);
        try {
          tObject = (T) session.get(tClass, Long.parseLong(document.get("id")));
          if(tObject != null) {
            tList.add(tObject);
          } else {
View Full Code Here

    // make sure they "took":
    searcher = new IndexSearcher(dir, true);
    hits = searcher.search(new TermQuery(new Term("content", "aaa")), null, 1000).scoreDocs;
    assertEquals("wrong number of hits", 43, hits.length);
    d = searcher.doc(hits[0].doc);
    assertEquals("wrong first document", "22", d.get("id"));
    testHits(hits, 43, searcher.getIndexReader());
    searcher.close();

    // optimize
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.