Package org.apache.lucene.search

Examples of org.apache.lucene.search.TopFieldCollector$OutOfOrderMultiComparatorNonScoringCollector


            // TODO: instead of always passing false we
            // should detect based on the query; if we make
            // the IndexSearcher search methods that take
            // Weight public again, we can go back to
            // pulling the Weight ourselves:
            TopFieldCollector collector = TopFieldCollector.create(sort, numHits,
                                                                   true, withScore(),
                                                                   withMaxScore(),
                                                                   false);
            searcher.search(q, null, collector);
            hits = collector.topDocs();
          } else {
            hits = searcher.search(q, numHits);
          }
        } else {
          Collector collector = createCollector();
View Full Code Here


    Query finalQuery = finishQuery(query, allTermsRequired);

    //System.out.println("finalQuery=" + query);

    // Sort by weight, descending:
    TopFieldCollector c = TopFieldCollector.create(SORT, num, true, false, false, false);

    // We sorted postings by weight during indexing, so we
    // only retrieve the first num hits now:
    Collector c2 = new EarlyTerminatingSortingCollector(c, SORT, num);
    IndexSearcher searcher = searcherMgr.acquire();
    List<LookupResult> results = null;
    try {
      //System.out.println("got searcher=" + searcher);
      searcher.search(finalQuery, c2);

      TopFieldDocs hits = (TopFieldDocs) c.topDocs();

      // Slower way if postings are not pre-sorted by weight:
      // hits = searcher.search(query, null, num, SORT);
      results = createResults(searcher, hits, num, key, doHighlight, matchedTokens, prefixToken);
    } finally {
View Full Code Here

      TopDocs hits;
      final int numHits = numHits();
      if (numHits > 0) {
        if (sort != null) {
          Weight w = q.weight(searcher);
          TopFieldCollector collector = TopFieldCollector.create(sort, numHits,
                                                                 true, withScore(),
                                                                 withMaxScore(),
                                                                 !w.scoresDocsOutOfOrder());
          searcher.search(w, null, collector);
          hits = collector.topDocs();
        } else {
          hits = searcher.search(q, numHits);
        }

        final String printHitsField = getRunData().getConfig().get("print.hits.field", null);
View Full Code Here

      close();
    }
  }

  private PossiblyLimitedTopDocs getTopDocs(Query query, Sort sort) throws IOException {
    final TopFieldCollector topCollector = TopFieldCollector.create(sort, maxHits, true, false, false, false);
    final Counter clock = Counter.newCounter(true);
    final int waitMillis = 1000;
    // TODO: if we interrupt the whole thread anyway, do we still need the TimeLimitingCollector?
    final TimeLimitingCollector collector = new TimeLimitingCollector(topCollector, clock, maxSearchTimeMillis / waitMillis);
    collector.setBaseline(0);
    final Thread counterThread = new Thread() {
      @Override
      public void run() {
        final long startTime = System.currentTimeMillis();
        while (true) {
          final long runTimeMillis = System.currentTimeMillis() - startTime;
          if (runTimeMillis > maxSearchTimeMillis) {
            // make sure there's no lingering thread for too long
            return;
          }
          clock.addAndGet(1);
          try {
            Thread.sleep(waitMillis);
          } catch (InterruptedException e) {
            throw new RuntimeException(e);
          }
        }
      }
    };
    counterThread.setName("LuceneSearchTimeoutThread");
    counterThread.start();

    boolean timeLimitActivated = false;
    try {
      indexSearcher.search(query, collector);
    } catch (TimeLimitingCollector.TimeExceededException e) {
      timeLimitActivated = true;
    }
    return new PossiblyLimitedTopDocs(topCollector.topDocs(), timeLimitActivated);
  }
View Full Code Here

    Query q = this.queryParser().parse(pageToken.getQueryString());
    TopDocs topDocs;

    Sort sort = new Sort(pageToken.getSortFields());
    TopFieldCollector collector = TopFieldCollector.create(sort,
        pageToken.getNextFirstHit() + pageSize - 1, true, true, true,
        true);

    long t1 = System.nanoTime();
    searcher.search(q, pageToken.getFilter(), collector);
    long t2 = System.nanoTime();

    topDocs = collector.topDocs(pageToken.getNextFirstHit() - 1);

    ScoreDoc[] hits = topDocs.scoreDocs;
    // jlog.info("Sort: " + sort + "; topDocs: " + topDocs + "; hits: + " +
    // hits);
    int firstHit = 0;
View Full Code Here

   //-------------------------------< internal >-------------------------------

   private void getHits() throws IOException
   {
      TopFieldCollector collector = TopFieldCollector.create(sort, numHits, false, true, false, false);
      searcher.search(query, collector);

      this.size = collector.getTotalHits();
      ScoreDoc[] docs = collector.topDocs().scoreDocs;
      for (int i = scoreNodes.size(); i < docs.length; i++)
      {
         String uuid = reader.document(docs[i].doc).get(FieldNames.UUID);
         //NodeId id = new NodeId(UUID.fromString(uuid));
         scoreNodes.add(new ScoreNode(uuid, docs[i].score, docs[i].doc));
View Full Code Here

   //-------------------------------< internal >-------------------------------

   private void getHits() throws IOException
   {
      TopFieldCollector collector = TopFieldCollector.create(sort, numHits, false, true, false, false);
      searcher.search(query, collector);

      this.size = collector.getTotalHits();
      ScoreDoc[] docs = collector.topDocs().scoreDocs;
      for (int i = scoreDocs.size(); i < docs.length; i++)
      {
         scoreDocs.add(docs[i]);
      }
      log.debug("getHits() {}/{}", scoreDocs.size(), numHits);
View Full Code Here

        else
        {
            boolean forceScore = context == null || !context.getTradeCorrectnessForSpeed();
            if ( forceScore )
            {
                TopFieldCollector collector = LuceneDataSource.scoringCollector( sorting, context.getTop() );
                searcher.search( query, collector );
                topDocs = collector.topDocs();
            }
            else
            {
                topDocs = searcher.search( query, null, context.getTop(), sorting );
            }
View Full Code Here

    }
    else
    {
        if ( this.score )
        {
            TopFieldCollector collector = LuceneDataSource.scoringCollector( sort, n );
            searcher.search( weight, null, collector );
            topDocs = collector.topDocs();
        }
        else
        {
            topDocs = searcher.search( weight, filter, n, sort );
        }
View Full Code Here

      final int numHits = numHits();
      if (numHits > 0) {
        if (withCollector() == false) {
          if (sort != null) {
            Weight w = searcher.createNormalizedWeight(q);
            TopFieldCollector collector = TopFieldCollector.create(sort, numHits,
                                                                   true, withScore(),
                                                                   withMaxScore(),
                                                                   !w.scoresDocsOutOfOrder());
            searcher.search(w, null, collector);
            hits = collector.topDocs();
          } else {
            hits = searcher.search(q, numHits);
          }
        } else {
          Collector collector = createCollector();
View Full Code Here

TOP

Related Classes of org.apache.lucene.search.TopFieldCollector$OutOfOrderMultiComparatorNonScoringCollector

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.