Package org.apache.lucene.search

Examples of org.apache.lucene.search.TopDocCollector


            }

        }

        IndexSearcher searcher=new IndexSearcher(this.spellindex);
        TopDocCollector collector = new TopDocCollector(10 * num_sug); // go thru more than 'maxr' matches in case the distance filter triggers
        searcher.search(query, collector);
        ScoreDoc[] scoreDocs = collector.topDocs().scoreDocs;

        SuggestWordQueue sugqueue=new SuggestWordQueue(num_sug);
        SuggestWord sugword = new SuggestWord();
        for (int i = 0; i < scoreDocs.length; i++) {

View Full Code Here


      bq.add(new BooleanClause(q, BooleanClause.Occur.SHOULD));
    }*/ 
    SciXMLDocument resultsDoc;
    if(uq.rt == ResultsType.SNIPPETS) {
      int hitsNeeded = uq.size + uq.skip;
      TopDocCollector tdc = new TopDocCollector(hitsNeeded);
      searcher.search(bq, tdc);
      resultsDoc = getResultsDocument(tdc, inchis, words, ontIDs, nq, uq, searcher.getIndexReader());     
    } else {
      SimpleHitCollector shc = new SimpleHitCollector();
      searcher.search(bq, shc);
View Full Code Here

   */
  public static void doPagingSearch(BufferedReader in, Searcher searcher, Query query,
                                     int hitsPerPage, boolean raw, boolean interactive) throws IOException {
    // Collect enough docs to show 5 pages
    TopDocCollector collector = new TopDocCollector(5 * hitsPerPage);
    searcher.search(query, collector);
    ScoreDoc[] hits = collector.topDocs().scoreDocs;
   
    int numTotalHits = collector.getTotalHits();
    System.out.println(numTotalHits + " total matching documents");

    int start = 0;
    int end = Math.min(numTotalHits, hitsPerPage);
       
    while (true) {
      if (end > hits.length) {
        System.out.println("Only results 1 - " + hits.length +" of " + numTotalHits + " total matching documents collected.");
        System.out.println("Collect more (y/n) ?");
        String line = in.readLine();
        if (line.length() == 0 || line.charAt(0) == 'n') {
          break;
        }

        collector = new TopDocCollector(numTotalHits);
        searcher.search(query, collector);
        hits = collector.topDocs().scoreDocs;
      }
     
      end = Math.min(hits.length, start + hitsPerPage);
     
      for (int i = start; i < end; i++) {
View Full Code Here

    InstantiatedIndex ii = new InstantiatedIndex();

    IndexReader r = new InstantiatedIndexReader(ii);
    IndexSearcher s = new IndexSearcher(r);

    TopDocCollector c = new TopDocCollector(1);
    s.search(new TermQuery(new Term("foo", "bar")), c);

    assertEquals(0, c.getTotalHits());

    s.close();
    r.close();
    ii.close();
View Full Code Here

      ParseException {

    if (_searcher == null)
      return new SearchResult<AgencyAndId>();

    TopDocCollector collector = new TopDocCollector(maxResultCount);

    Query query = parser.parse(value);
    _searcher.search(query, collector);

    TopDocs top = collector.topDocs();

    Map<AgencyAndId, Float> topScores = new HashMap<AgencyAndId, Float>();

    for (ScoreDoc sd : top.scoreDocs) {
      Document document = _searcher.doc(sd.doc);
View Full Code Here

      ParseException {

    if (_searcher == null)
      return new SearchResult<AgencyAndId>();

    TopDocCollector collector = new TopDocCollector(maxResultCount);

    Query query = parser.parse(value);
    _searcher.search(query, collector);

    TopDocs top = collector.topDocs();

    Map<AgencyAndId, Float> topScores = new HashMap<AgencyAndId, Float>();

    String lowerCaseQueryValue = value.toLowerCase();
View Full Code Here

      TopDocs tps = null;
      Searcher searcher = null;
      ScoreDoc[] hits = null;
      if (bSortByScore){
        Search.TopDocCollectorSearchResult result = search.searchByScore(queryStr, startFrom, operator);
        TopDocCollector collector = result.getCollector();
        if (collector != null) {
          tps = collector.topDocs();
        }
        hits = tps.scoreDocs;
        searcher = result.getSearcher();
      } else {
        Search.TopFieldDocsSearchResult result = search.searchBySession(queryStr, startFrom, operator);
View Full Code Here

      } else {
        parser.setDefaultOperator(QueryParser.OR_OPERATOR);
      }
      Query query;
      query = parser.parse(queryStr);
      TopDocCollector collector = doPagingSearch(query, startFrom);
      TopDocCollectorSearchResult result = new TopDocCollectorSearchResult(
          collector, searcher);
      return result;
    } catch (ParseException e) {
      // TODO Auto-generated catch block
View Full Code Here

  }

  private TopDocCollector doPagingSearch(Query query, int startFrom)
      throws IOException {

    TopDocCollector collector = new TopDocCollector(startFrom + 10);
    searcher.search(query, collector);
    if (logger.isDebugEnabled()) {
      logger.debug(query.toString());
      logger.debug(collector.toString());
    }

    return collector;
  }
View Full Code Here

   
    if( searchQuery.isLimited() )
      maxResults = searchQuery.getMaxResults();
   
    Map<String, Float> searchTerms = extractTerms(query);
    TopDocCollector collector = new TopDocCollector( maxResults );
   
    if( searchQuery.isCanceled() )
      return null;
   
    indexSearcher.search(query, collector); // do the actual search
   
    if( collector.getTotalHits() == 0 )
      return null;
   
    ScoreDoc[] hits = collector.topDocs().scoreDocs;
    ArrayList<SearchResultDoc> resultDocs = new ArrayList<SearchResultDoc>(hits.length);
   
    for (int i = 0; i < hits.length && !searchQuery.isCanceled(); i++)
    {
      int docId = hits[i].doc;
View Full Code Here

TOP

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

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.