Package org.apache.lucene.search

Examples of org.apache.lucene.search.TotalHitCountCollector


    IOUtils.close(indexReader, taxoReader);
  }
 
  private void verifyNotFacetsData(DirectoryReader indexReader, IndexSearcher searcher) throws IOException {
    // verify that non facets data was not damaged
    TotalHitCountCollector total = new TotalHitCountCollector();
    searcher.search(new PrefixQuery(new Term("foo", "content")), total);
    assertEquals("invalid number of results for content query", total.getTotalHits(), indexReader.maxDoc());
   
    int numDocIDs = 0;
    for (AtomicReaderContext context : indexReader.leaves()) {
      Terms docIDs = context.reader().terms("docid");
      assertNotNull(docIDs);
View Full Code Here


    for (String dim : expectedCounts.keySet()) {
      CategoryPath drillDownCP = new CategoryPath(dim);
      FacetSearchParams fsp = new FacetSearchParams(fip, new CountFacetRequest(drillDownCP, 10));
      DrillDownQuery drillDown = new DrillDownQuery(fip, new MatchAllDocsQuery());
      drillDown.add(drillDownCP);
      TotalHitCountCollector total = new TotalHitCountCollector();
      FacetsCollector fc = FacetsCollector.create(fsp, indexReader, taxoReader);
      searcher.search(drillDown, MultiCollector.wrap(fc, total));
      assertTrue("no results for drill-down query " + drillDown, total.getTotalHits() > 0);
      List<FacetResult> facetResults = fc.getFacetResults();
      assertEquals(1, facetResults.size());
      FacetResultNode rootNode = facetResults.get(0).getFacetResultNode();
      assertEquals("wrong count for " + dim, expectedCounts.get(dim).intValue(), (int) rootNode.value);
    }
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

  }

  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

  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

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.