Search in sources :

Example 1 with TimeLimitingCollector

use of org.apache.lucene.search.TimeLimitingCollector in project lucene-solr by apache.

the class Grouping method searchWithTimeLimiter.

/**
   * Invokes search with the specified filter and collector.  
   * If a time limit has been specified, wrap the collector in a TimeLimitingCollector
   */
private void searchWithTimeLimiter(final Filter luceneFilter, Collector collector) throws IOException {
    if (cmd.getTimeAllowed() > 0) {
        if (timeLimitingCollector == null) {
            timeLimitingCollector = new TimeLimitingCollector(collector, TimeLimitingCollector.getGlobalCounter(), cmd.getTimeAllowed());
        } else {
            /*
         * This is so the same timer can be used for grouping's multiple phases.   
         * We don't want to create a new TimeLimitingCollector for each phase because that would 
         * reset the timer for each phase.  If time runs out during the first phase, the 
         * second phase should timeout quickly.
         */
            timeLimitingCollector.setCollector(collector);
        }
        collector = timeLimitingCollector;
    }
    try {
        Query q = query;
        if (luceneFilter != null) {
            q = new BooleanQuery.Builder().add(q, Occur.MUST).add(luceneFilter, Occur.FILTER).build();
        }
        searcher.search(q, collector);
    } catch (TimeLimitingCollector.TimeExceededException | ExitableDirectoryReader.ExitingReaderException x) {
        logger.warn("Query: " + query + "; " + x.getMessage());
        qr.setPartialResults(true);
    }
}
Also used : Query(org.apache.lucene.search.Query) FunctionQuery(org.apache.lucene.queries.function.FunctionQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) TimeLimitingCollector(org.apache.lucene.search.TimeLimitingCollector)

Example 2 with TimeLimitingCollector

use of org.apache.lucene.search.TimeLimitingCollector in project elasticsearch-skywalker by jprante.

the class IntervalLimitedCollector method reset.

@Override
public void reset() {
    lastDoc = 0;
    tdc = TopScoreDocCollector.create(1000, outOfOrder);
    thc = new TimeLimitingCollector(tdc, TimeLimitingCollector.getGlobalCounter(), maxTime);
}
Also used : TimeLimitingCollector(org.apache.lucene.search.TimeLimitingCollector)

Example 3 with TimeLimitingCollector

use of org.apache.lucene.search.TimeLimitingCollector in project lucene-solr by apache.

the class CommandHandler method searchWithTimeLimiter.

/**
   * Invokes search with the specified filter and collector.  
   * If a time limit has been specified then wrap the collector in the TimeLimitingCollector
   */
private void searchWithTimeLimiter(Query query, ProcessedFilter filter, Collector collector) throws IOException {
    if (queryCommand.getTimeAllowed() > 0) {
        collector = new TimeLimitingCollector(collector, TimeLimitingCollector.getGlobalCounter(), queryCommand.getTimeAllowed());
    }
    TotalHitCountCollector hitCountCollector = new TotalHitCountCollector();
    if (includeHitCount) {
        collector = MultiCollector.wrap(collector, hitCountCollector);
    }
    if (filter.filter != null) {
        query = new BooleanQuery.Builder().add(query, Occur.MUST).add(filter.filter, Occur.FILTER).build();
    }
    if (filter.postFilter != null) {
        filter.postFilter.setLastDelegate(collector);
        collector = filter.postFilter;
    }
    try {
        searcher.search(query, collector);
    } catch (TimeLimitingCollector.TimeExceededException | ExitableDirectoryReader.ExitingReaderException x) {
        partialResults = true;
        logger.warn("Query: " + query + "; " + x.getMessage());
    }
    if (includeHitCount) {
        totalHitCount = hitCountCollector.getTotalHits();
    }
}
Also used : TotalHitCountCollector(org.apache.lucene.search.TotalHitCountCollector) TimeLimitingCollector(org.apache.lucene.search.TimeLimitingCollector)

Aggregations

TimeLimitingCollector (org.apache.lucene.search.TimeLimitingCollector)3 FunctionQuery (org.apache.lucene.queries.function.FunctionQuery)1 BooleanQuery (org.apache.lucene.search.BooleanQuery)1 Query (org.apache.lucene.search.Query)1 TotalHitCountCollector (org.apache.lucene.search.TotalHitCountCollector)1