Package org.apache.lucene.search

Examples of org.apache.lucene.search.TotalHitCountCollector


  private int getWordFreqForClass(String word, BytesRef c) throws IOException {
    BooleanQuery booleanQuery = new BooleanQuery();
    booleanQuery.add(new BooleanClause(new TermQuery(new Term(textFieldName, word)), BooleanClause.Occur.MUST));
    booleanQuery.add(new BooleanClause(new TermQuery(new Term(classFieldName, c)), BooleanClause.Occur.MUST));
    TotalHitCountCollector totalHitCountCollector = new TotalHitCountCollector();
    indexSearcher.search(booleanQuery, totalHitCountCollector);
    return totalHitCountCollector.getTotalHits();
  }
View Full Code Here


  }

  private int countDocsWithClass() throws IOException {
    int docCount = MultiFields.getTerms(this.atomicReader, this.classFieldName).getDocCount();
    if (docCount == -1) { // in case codec doesn't support getDocCount
      TotalHitCountCollector totalHitCountCollector = new TotalHitCountCollector();
      BooleanQuery q = new BooleanQuery();
      q.add(new BooleanClause(new WildcardQuery(new Term(classFieldName, String.valueOf(WildcardQuery.WILDCARD_STRING))), BooleanClause.Occur.MUST));
      if (query != null) {
        q.add(query, BooleanClause.Occur.MUST);
      }
      indexSearcher.search(q,
          totalHitCountCollector);
      docCount = totalHitCountCollector.getTotalHits();
    }
    return docCount;
  }
View Full Code Here

    booleanQuery.add(new BooleanClause(subQuery, BooleanClause.Occur.MUST));
    booleanQuery.add(new BooleanClause(new TermQuery(new Term(classFieldName, c)), BooleanClause.Occur.MUST));
    if (query != null) {
      booleanQuery.add(query, BooleanClause.Occur.MUST);
    }
    TotalHitCountCollector totalHitCountCollector = new TotalHitCountCollector();
    indexSearcher.search(booleanQuery, totalHitCountCollector);
    return totalHitCountCollector.getTotalHits();
  }
View Full Code Here

    int totalMaxDocs = searcher.getSearcher().maxDoc();
    final int maxDocs = Math.min( n, totalMaxDocs );
    final Weight weight = preparedQuery.weight( searcher.getSearcher() );

    final TopDocsCollector<?> topDocCollector;
    final TotalHitCountCollector hitCountCollector;
    Collector collector = null;
    if ( maxDocs != 0 ) {
      topDocCollector = createTopDocCollector( maxDocs, weight );
      hitCountCollector = null;
      collector = topDocCollector;
      collector = optionallyEnableFieldCacheOnTypes( collector, totalMaxDocs, maxDocs );
      collector = optionallyEnableFieldCacheOnIds( collector, totalMaxDocs, maxDocs );
      collector = optionallyEnableFacetingCollectors( collector );
      collector = optionallyEnableDistanceCollector( collector, maxDocs );
    }
    else {
      topDocCollector = null;
      hitCountCollector = new TotalHitCountCollector();
      collector = hitCountCollector;
    }
    collector = decorateWithTimeOutCollector( collector );

    boolean timeoutNow = isImmediateTimeout();
    if ( !timeoutNow ) {
      try {
        searcher.getSearcher().search( weight, filter, collector );
      }
      catch ( TimeLimitingCollector.TimeExceededException e ) {
        //we have reached the time limit and stopped before the end
        //TimeoutManager.isTimedOut should be above that limit but set if for safety
        timeoutManager.forceTimedOut();
      }
    }

    // update top docs and totalHits
    if ( maxDocs != 0 ) {
      this.topDocs = topDocCollector.topDocs();
      this.totalHits = topDocs.totalHits;
      // if we were collecting facet data we have to update our instance state
      if ( facetCollectors != null && !facetCollectors.isEmpty() ) {
        facetMap = new HashMap<String, List<Facet>>();
        for ( FacetCollector facetCollector : facetCollectors ) {
          facetMap.put( facetCollector.getFacetName(), facetCollector.getFacetList() );
        }
      }
    }
    else {
      this.topDocs = null;
      this.totalHits = hitCountCollector.getTotalHits();
    }
    timeoutManager.isTimedOut();
  }
View Full Code Here

    int totalMaxDocs = searcher.getSearcher().maxDoc();
    final int maxDocs = Math.min( n, totalMaxDocs );
    final Weight weight = preparedQuery.weight( searcher.getSearcher() );

    final TopDocsCollector<?> topDocCollector;
    final TotalHitCountCollector hitCountCollector;
    Collector collector = null;
    if ( maxDocs != 0 ) {
      topDocCollector = createTopDocCollector( maxDocs, weight );
      hitCountCollector = null;
      collector = topDocCollector;
      collector = optionallyEnableFieldCacheOnTypes( collector, totalMaxDocs, maxDocs );
      collector = optionallyEnableFieldCacheOnIds( collector, totalMaxDocs, maxDocs );
      collector = optionallyEnableFacetingCollectors( collector );
    }
    else {
      topDocCollector = null;
      hitCountCollector = new TotalHitCountCollector();
      collector = hitCountCollector;
    }
    collector = decorateWithTimeOutCollector( collector );

    boolean timeoutNow = isImmediateTimeout();
    if ( !timeoutNow ) {
      try {
        searcher.getSearcher().search( weight, filter, collector );
      }
      catch ( TimeLimitingCollector.TimeExceededException e ) {
        //we have reached the time limit and stopped before the end
        //TimeoutManager.isTimedOut should be above that limit but set if for safety
        timeoutManager.forceTimedOut();
      }
    }

    // update top docs and totalHits
    if ( maxDocs != 0 ) {
      this.topDocs = topDocCollector.topDocs();
      this.totalHits = topDocs.totalHits;
      // if we were collecting facet data we have to update our instance state
      if ( facetCollectors != null && !facetCollectors.isEmpty() ) {
        facetMap = new HashMap<String, List<Facet>>();
        for ( FacetCollector facetCollector : facetCollectors ) {
          facetMap.put( facetCollector.getFacetName(), facetCollector.getFacetList() );
        }
      }
    }
    else {
      this.topDocs = null;
      this.totalHits = hitCountCollector.getTotalHits();
    }
    timeoutManager.isTimedOut();
  }
View Full Code Here

    int totalMaxDocs = searcher.getSearcher().maxDoc();
    final int maxDocs = Math.min( n, totalMaxDocs );
    final Weight weight = preparedQuery.weight( searcher.getSearcher() );

    final TopDocsCollector<?> topDocCollector;
    final TotalHitCountCollector hitCountCollector;
    Collector collector = null;
    if ( maxDocs != 0 ) {
      topDocCollector = createTopDocCollector( maxDocs, weight );
      hitCountCollector = null;
      collector = topDocCollector;
      collector = optionallyEnableFieldCacheOnTypes( collector, totalMaxDocs, maxDocs );
      collector = optionallyEnableFieldCacheOnIds( collector, totalMaxDocs, maxDocs );
      collector = optionallyEnableFacetingCollectors( collector );
    }
    else {
      topDocCollector = null;
      hitCountCollector = new TotalHitCountCollector();
      collector = hitCountCollector;
    }
    collector = decorateWithTimeOutCollector( collector );

    boolean timeoutNow = isImmediateTimeout();
    if ( !timeoutNow ) {
      try {
        searcher.getSearcher().search( weight, filter, collector );
      }
      catch ( TimeLimitingCollector.TimeExceededException e ) {
        //we have reached the time limit and stopped before the end
        //TimeoutManager.isTimedOut should be above that limit but set if for safety
        timeoutManager.forceTimedOut();
      }
    }

    // update top docs and totalHits
    if ( maxDocs != 0 ) {
      this.topDocs = topDocCollector.topDocs();
      this.totalHits = topDocs.totalHits;
      // if we were collecting facet data we have to update our instance state
      if ( facetCollectors != null && !facetCollectors.isEmpty() ) {
        facetMap = new HashMap<String, List<Facet>>();
        for ( FacetCollector facetCollector : facetCollectors ) {
          facetMap.put( facetCollector.getFacetName(), facetCollector.getFacetList() );
        }
      }
    }
    else {
      this.topDocs = null;
      this.totalHits = hitCountCollector.getTotalHits();
    }
    timeoutManager.isTimedOut();
  }
View Full Code Here

        return query(q, TopScoreDocCollector.create(maxResults,true), maxResults);
    }

    public long count(Query q) {
        TotalHitCountCollector collector = new TotalHitCountCollector();

        try {
            IndexSearcher s = getSearcher();
            s.search(q, collector);

            return collector.getTotalHits();
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
    }
View Full Code Here

  private void updateTopDocs(int n) throws IOException {
    final int totalMaxDocs = searcher.maxDoc();
    final int maxDocs = Math.min( n, totalMaxDocs );

    final TopDocsCollector<?> topDocCollector;
    final TotalHitCountCollector hitCountCollector;
    Collector collector = null;
    if ( maxDocs != 0 ) {
      topDocCollector = createTopDocCollector( maxDocs );
      hitCountCollector = null;
      collector = topDocCollector;
      collector = optionallyEnableFieldCacheOnTypes( collector, totalMaxDocs, maxDocs );
      collector = optionallyEnableFieldCacheOnIds( collector, totalMaxDocs, maxDocs );
      collector = optionallyEnableFacetingCollectors( collector );
      collector = optionallyEnableDistanceCollector( collector, maxDocs );
    }
    else {
      topDocCollector = null;
      hitCountCollector = new TotalHitCountCollector();
      collector = hitCountCollector;
    }
    collector = decorateWithTimeOutCollector( collector );

    boolean timeoutNow = isImmediateTimeout();
    if ( !timeoutNow ) {
      try {
        searcher.search( filter, collector );
      }
      catch (TimeLimitingCollector.TimeExceededException e) {
        //we have reached the time limit and stopped before the end
        //TimeoutManager.isTimedOut should be above that limit but set if for safety
        timeoutManager.forceTimedOut();
      }
    }

    // update top docs and totalHits
    if ( maxDocs != 0 ) {
      this.topDocs = topDocCollector.topDocs();
      this.totalHits = topDocs.totalHits;
      // if we were collecting facet data we have to update our instance state
      if ( facetCollectors != null && !facetCollectors.isEmpty() ) {
        facetMap = new HashMap<String, List<Facet>>();
        for ( FacetCollector facetCollector : facetCollectors ) {
          facetMap.put( facetCollector.getFacetName(), facetCollector.getFacetList() );
        }
      }
    }
    else {
      this.topDocs = null;
      this.totalHits = hitCountCollector.getTotalHits();
    }
    timeoutManager.isTimedOut();
  }
View Full Code Here

    int totalMaxDocs = searcher.getSearcher().maxDoc();
    final int maxDocs = Math.min( n, totalMaxDocs );
    final Weight weight = preparedQuery.weight( searcher.getSearcher() );

    final TopDocsCollector<?> topDocCollector;
    final TotalHitCountCollector hitCountCollector;
    Collector collector = null;
    if ( maxDocs != 0 ) {
      topDocCollector = createTopDocCollector( maxDocs, weight );
      hitCountCollector = null;
      collector = topDocCollector;
      collector = optionallyEnableFieldCacheOnTypes( collector, totalMaxDocs, maxDocs );
      collector = optionallyEnableFieldCacheOnIds( collector, totalMaxDocs, maxDocs );
      collector = optionallyEnableFacetingCollectors( collector );
      collector = optionallyEnableDistanceCollector( collector, maxDocs );
    }
    else {
      topDocCollector = null;
      hitCountCollector = new TotalHitCountCollector();
      collector = hitCountCollector;
    }
    collector = decorateWithTimeOutCollector( collector );

    boolean timeoutNow = isImmediateTimeout();
    if ( !timeoutNow ) {
      try {
        searcher.getSearcher().search( weight, filter, collector );
      }
      catch ( TimeLimitingCollector.TimeExceededException e ) {
        //we have reached the time limit and stopped before the end
        //TimeoutManager.isTimedOut should be above that limit but set if for safety
        timeoutManager.forceTimedOut();
      }
    }

    // update top docs and totalHits
    if ( maxDocs != 0 ) {
      this.topDocs = topDocCollector.topDocs();
      this.totalHits = topDocs.totalHits;
      // if we were collecting facet data we have to update our instance state
      if ( facetCollectors != null && !facetCollectors.isEmpty() ) {
        facetMap = new HashMap<String, List<Facet>>();
        for ( FacetCollector facetCollector : facetCollectors ) {
          facetMap.put( facetCollector.getFacetName(), facetCollector.getFacetList() );
        }
      }
    }
    else {
      this.topDocs = null;
      this.totalHits = hitCountCollector.getTotalHits();
    }
    timeoutManager.isTimedOut();
  }
View Full Code Here

            TopDocs topDocs;
            int numDocs = searchContext.from() + searchContext.size();

            if (searchContext.searchType() == SearchType.COUNT || numDocs == 0) {
                TotalHitCountCollector collector = new TotalHitCountCollector();
                searchContext.searcher().search(query, collector);
                topDocs = new TopDocs(collector.getTotalHits(), Lucene.EMPTY_SCORE_DOCS, 0);
            } else if (searchContext.searchType() == SearchType.SCAN) {
                topDocs = searchContext.scanContext().execute(searchContext);
            } else {
                // Perhaps have a dedicated scroll phase?
                if (!searchContext.useSlowScroll() && searchContext.request().scroll() != null) {
View Full Code Here

TOP

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

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.