Package org.apache.lucene.search

Examples of org.apache.lucene.search.IndexSearcher


    // open reader to test document count
    IndexReader reader = IndexReader.open(ramDir, true);
    assertEquals(docsToAdd, reader.numDocs());
   
    // open search zo check if all doc's are there
    IndexSearcher searcher = new IndexSearcher(reader);
   
    // search for all documents
    for (int i = 0; i < docsToAdd; i++) {
      Document doc = searcher.doc(i);
      assertTrue(doc.getField("content") != null);
    }

    // cleanup
    reader.close();
    searcher.close();
  }
View Full Code Here


    _TestUtil.checkIndex(dir1);

    // reader should remain usable even after IndexWriter is closed:
    assertEquals(100, r.numDocs());
    Query q = new TermQuery(new Term("indexname", "test"));
    assertEquals(100, new IndexSearcher(r).search(q, 10).totalHits);

    try {
      r.reopen();
      fail("failed to hit AlreadyClosedException");
    } catch (AlreadyClosedException ace) {
View Full Code Here

      if (r2 != r) {
        r.close();
        r = r2;
      }
      Query q = new TermQuery(new Term("indexname", "test"));
      final int count = new IndexSearcher(r).search(q, 10).totalHits;
      assertTrue(count >= lastCount);
      lastCount = count;
    }

    for(int i=0;i<NUM_THREAD;i++) {
View Full Code Here

      if (r2 != r) {
        r.close();
        r = r2;
      }
      Query q = new TermQuery(new Term("indexname", "test"));
      sum += new IndexSearcher(r).search(q, 10).totalHits;
    }

    for(int i=0;i<NUM_THREAD;i++) {
      threads[i].join();
    }
View Full Code Here

    w.setMaxBufferedDocs(2);
    w.getReader().close();

    w.setMergedSegmentWarmer(new IndexWriter.IndexReaderWarmer() {
        public void warm(IndexReader r) throws IOException {
          final IndexSearcher s = new IndexSearcher(r);
          final TopDocs hits = s.search(new TermQuery(new Term("foo", "bar")), 10);
          assertEquals(20, hits.totalHits);
        }
      });
   
    Document doc = new Document();
View Full Code Here

    // plan to add a set of useful stopwords, consider changing some of the
    // interior filters.
    StandardAnalyzer analyzer = new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT, Collections.emptySet());
    // TODO: something about lock timeouts and leftover locks.
    IndexWriter writer = new IndexWriter(storeDirectory, analyzer, true, IndexWriter.MaxFieldLength.LIMITED);
    IndexSearcher searcher = new IndexSearcher(storeDirectory, true);
   
    for(int dx = 0; dx < 1000; dx ++) {
      String f = randomField();
      Document doc = new Document();
      doc.add(new Field("data", f, Field.Store.YES, Field.Index.ANALYZED))
      writer.addDocument(doc);
    }
   
    searcher.close();
    writer.close();
                rmDir(new File(storePathname));
  }
View Full Code Here

    MultiFieldQueryParserWrapper mfqp = new MultiFieldQueryParserWrapper(
        new String[] { "body" }, analyzer);
    mfqp.setDefaultOperator(QueryParserWrapper.Operator.AND);
    Query q = mfqp.parse("the footest");
    IndexSearcher is = new IndexSearcher(ramDir, true);
    ScoreDoc[] hits = is.search(q, null, 1000).scoreDocs;
    assertEquals(1, hits.length);
    is.close();
  }
View Full Code Here

            this.numIteration = numIteration;
            this.dir = dir;
        }
        @Override
        public void run() {
            IndexSearcher searcher = null;
            Query query = new TermQuery(new Term("content", "aaa"));
            for(int i=0;i<this.numIteration;i++) {
                try{
                    searcher = new IndexSearcher(dir, false);
                } catch (Exception e) {
                    hitException = true;
                    System.out.println("Stress Test Index Searcher: create hit unexpected exception: " + e.toString());
                    e.printStackTrace(System.out);
                    break;
                }
                if (searcher != null) {
                    ScoreDoc[] hits = null;
                    try {
                        hits = searcher.search(query, null, 1000).scoreDocs;
                    } catch (IOException e) {
                        hitException = true;
                        System.out.println("Stress Test Index Searcher: search hit unexpected exception: " + e.toString());
                        e.printStackTrace(System.out);
                        break;
                    }
                    // System.out.println(hits.length() + " total results");
                    try {
                        searcher.close();
                    } catch (IOException e) {
                        hitException = true;
                        System.out.println("Stress Test Index Searcher: close hit unexpected exception: " + e.toString());
                        e.printStackTrace(System.out);
                        break;
View Full Code Here

  addDoc(writer, "lucene");
  addDoc(writer, "lucene release");

  writer.close();
  reader = IndexReader.open(directory, true);
  searcher = new IndexSearcher(reader);

    }
View Full Code Here

   
    Query query = lq.makeLuceneQueryField(fieldName, qf);
    /* if (verbose) System.out.println("Lucene: " + query.toString()); */

    TestCollector tc = new TestCollector();
    Searcher searcher = new IndexSearcher(dBase.getDb(), true);
    try {
      searcher.search(query, tc);
    } finally {
      searcher.close();
    }
    tc.checkNrHits();
  }
View Full Code Here

TOP

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

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.