Package org.apache.lucene.search

Examples of org.apache.lucene.search.Searcher.search()


       
    BooleanQuery bq = new BooleanQuery();
    bq.add(q1,Occur.MUST);
    bq.add(q4,Occur.MUST);
       
    searcher.search(bq,
                    new CountingHitCollector() {
                      @Override
                      public final void collect(int doc) throws IOException {
                        //System.out.println("BQ: Doc=" + doc + " score=" + score);
                        super.collect(doc);
View Full Code Here


      throw new IllegalArgumentException("query must not be null");
   
    Searcher searcher = createSearcher();
    try {
      final float[] scores = new float[1]; // inits to 0.0f (no match)
      searcher.search(query, new HitCollector() {
        public void collect(int doc, float score) {
          scores[0] = score;
        }
      });
      float score = scores[0];
View Full Code Here

      throw new IllegalArgumentException("query must not be null");
   
    Searcher searcher = createSearcher();
    try {
      final float[] scores = new float[1]; // inits to 0.0f (no match)
      searcher.search(query, new Collector() {
        private Scorer scorer;

        @Override
        public void collect(int doc) throws IOException {
          scores[0] = scorer.score();
View Full Code Here

        QueryParser parser = new QueryParser(Version.LUCENE_30, "content", analyzer);
        Query query = parser.parse(queryLine);
        combQuery.add(query, BooleanClause.Occur.MUST);

        TopScoreDocCollector collector = TopScoreDocCollector.create(10, false);
        searcher.search(combQuery, collector);

        assertEquals("Only 1 result expected from the testdata", 1, collector.getTotalHits());
    }
}
View Full Code Here

      int count = 0;
      for (RowResult r : scanner) {
        String value = Bytes.toString(r.getRow());
        Term term = new Term(rowkeyName, value);
        int hitCount = searcher.search(new TermQuery(term)).length();
        assertEquals("check row " + value, 1, hitCount);
        count++;
      }
      LOG.debug("Searcher.maxDoc: " + searcher.maxDoc());
      LOG.debug("IndexReader.numDocs: " + ((IndexSearcher)searcher).getIndexReader().numDocs());     
View Full Code Here

        Analyzer analyzer = new StandardAnalyzer();

        Query query = QueryParser.parse(line, "contents", analyzer);
        System.out.println("Searching for: " + query.toString("contents"));

                Hits hits = searcher.search(query);
                System.out.println("Total matching documents: " + hits.length());

                final int HITS_PER_PAGE = 10;

                for (int start = 0; start < hits.length(); start += HITS_PER_PAGE) {
View Full Code Here

        return query;
      }
     
      //get all Synonyms from SynonymIndex and add them to searchQuery
      log.debug("Synonym Query String: " + querySynonym.toString());
      TopDocs docs = synonymSearcher.search(querySynonym, MAX_SYNONYMS);
      log.debug("total found synonyms: " + docs.totalHits)
      for (ScoreDoc doc : docs.scoreDocs) {
        Document d = synonymReader.document(doc.doc);
        for (int i = 0; i < searchedAttributes.length; i++) {
          query = query + " OR " + searchedAttributes[i] + ":" + d.get("Synonym");
View Full Code Here

    Searcher autoCompleteSearcher = ia.getPrioritizedSearcher();
    IndexReader autoCompleteReader = ia.getReader(false);
    try {
      Query query = new TermQuery(new Term(GRAMMED_WORDS_FIELD, term));
      Sort sort = new Sort(new SortField(COUNT_FIELD, SortField.LONG, true));
      TopDocs docs = autoCompleteSearcher.search(query, null, 5, sort);
      int id = 1;
      for (ScoreDoc doc : docs.scoreDocs) {
        CRResolvableBean bean = new CRResolvableBean(id++);
        Document d = autoCompleteReader.document(doc.doc);
        bean.set(SOURCE_WORD_FIELD, d.get(SOURCE_WORD_FIELD));
View Full Code Here

      int count = 0;
      while (scanner.next(key, results)) {
        String value = key.getRow().toString();
        LOG.debug("Scanned over " + key.getRow());
        Term term = new Term(rowkeyName, value);
        int hitCount = searcher.search(new TermQuery(term)).length();
        assertEquals("check row " + value, 1, hitCount);
        count++;
      }
      LOG.debug("Searcher.maxDoc: " + searcher.maxDoc());
      LOG.debug("IndexReader.numDocs: " + ((IndexSearcher)searcher).getIndexReader().numDocs());     
View Full Code Here

      int count = 0;
      while (scanner.next(key, results)) {
        String value = key.getRow().toString();
        Term term = new Term(rowkeyName, value);
        int hitCount = searcher.search(new TermQuery(term)).length();
        assertEquals("check row " + value, 1, hitCount);
        count++;
      }
      int maxDoc = searcher.maxDoc();
      assertEquals("check number of rows", count, maxDoc);
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.