Java 类org.apache.lucene.search.grouping.term.TermAllGroupHeadsCollector 实例源码

项目:thrift-transport    文件:LuceneTests.java   
@Test
public void testTermAllGroupHeadsCollector() throws Exception {
    String groupField = "title";
    Sort sortWithinGroup = new Sort();

    searcherManager.maybeRefresh();
    IndexSearcher searcher = searcherManager.acquire();

    // Render groupsResult... Note that the groupValue of each GroupDocs will be null, so if you need to present this value you'll have to separately retrieve it (for example using stored fields, FieldCache, etc.).
    //Another collector is the TermAllGroupHeadsCollector that can be used to retrieve all most relevant documents per group. Also known as group heads. This can be useful in situations when one wants to compute group based facets / statistics on the complete query result. The collector can be executed during the first or second phase. This collector can also be used with the GroupingSearch convenience utility, but when if one only wants to compute the most relevant documents per group it is better to just use the collector as done here below.
    AbstractAllGroupHeadsCollector collector = TermAllGroupHeadsCollector.create(groupField, sortWithinGroup);
    searcher.search(new TermQuery(new Term("title", "Lucene")), collector);

    // Return all group heads as int array
    int[] groupHeadsArray = collector.retrieveGroupHeads();
    // Return all group heads as FixedBitSet.
    int maxDoc = searcher.getIndexReader().maxDoc();
    FixedBitSet groupHeadsBitSet = collector.retrieveGroupHeads(maxDoc);

}
项目:search    文件:CommandHandler.java   
private DocSet computeGroupedDocSet(Query query, ProcessedFilter filter, List<Collector> collectors) throws IOException {
  Command firstCommand = commands.get(0);
  AbstractAllGroupHeadsCollector termAllGroupHeadsCollector =
      TermAllGroupHeadsCollector.create(firstCommand.getKey(), firstCommand.getSortWithinGroup());
  if (collectors.isEmpty()) {
    searchWithTimeLimiter(query, filter, termAllGroupHeadsCollector);
  } else {
    collectors.add(termAllGroupHeadsCollector);
    searchWithTimeLimiter(query, filter, MultiCollector.wrap(collectors.toArray(new Collector[collectors.size()])));
  }

  return new BitDocSet(termAllGroupHeadsCollector.retrieveGroupHeads(searcher.maxDoc()));
}
项目:NYBC    文件:CommandHandler.java   
private DocSet computeGroupedDocSet(Query query, ProcessedFilter filter, List<Collector> collectors) throws IOException {
  Command firstCommand = commands.get(0);
  AbstractAllGroupHeadsCollector termAllGroupHeadsCollector =
      TermAllGroupHeadsCollector.create(firstCommand.getKey(), firstCommand.getSortWithinGroup());
  if (collectors.isEmpty()) {
    searchWithTimeLimiter(query, filter, termAllGroupHeadsCollector);
  } else {
    collectors.add(termAllGroupHeadsCollector);
    searchWithTimeLimiter(query, filter, MultiCollector.wrap(collectors.toArray(new Collector[collectors.size()])));
  }

  int maxDoc = searcher.maxDoc();
  long[] bits = termAllGroupHeadsCollector.retrieveGroupHeads(maxDoc).getBits();
  return new BitDocSet(new OpenBitSet(bits, bits.length));
}
项目:search-core    文件:CommandHandler.java   
private DocSet computeGroupedDocSet(Query query, ProcessedFilter filter, List<Collector> collectors) throws IOException {
  Command firstCommand = commands.get(0);
  AbstractAllGroupHeadsCollector termAllGroupHeadsCollector =
      TermAllGroupHeadsCollector.create(firstCommand.getKey(), firstCommand.getSortWithinGroup());
  if (collectors.isEmpty()) {
    searchWithTimeLimiter(query, filter, termAllGroupHeadsCollector);
  } else {
    collectors.add(termAllGroupHeadsCollector);
    searchWithTimeLimiter(query, filter, MultiCollector.wrap(collectors.toArray(new Collector[collectors.size()])));
  }

  int maxDoc = searcher.maxDoc();
  long[] bits = termAllGroupHeadsCollector.retrieveGroupHeads(maxDoc).getBits();
  return new BitDocSet(new OpenBitSet(bits, bits.length));
}
项目:read-open-source-code    文件:CommandHandler.java   
private DocSet computeGroupedDocSet(Query query, ProcessedFilter filter, List<Collector> collectors) throws IOException {
  Command firstCommand = commands.get(0);
  AbstractAllGroupHeadsCollector termAllGroupHeadsCollector =
      TermAllGroupHeadsCollector.create(firstCommand.getKey(), firstCommand.getSortWithinGroup());
  if (collectors.isEmpty()) {
    searchWithTimeLimiter(query, filter, termAllGroupHeadsCollector);
  } else {
    collectors.add(termAllGroupHeadsCollector);
    searchWithTimeLimiter(query, filter, MultiCollector.wrap(collectors.toArray(new Collector[collectors.size()])));
  }

  return new BitDocSet(termAllGroupHeadsCollector.retrieveGroupHeads(searcher.maxDoc()));
}
项目:read-open-source-code    文件:CommandHandler.java   
private DocSet computeGroupedDocSet(Query query, ProcessedFilter filter, List<Collector> collectors) throws IOException {
  Command firstCommand = commands.get(0);
  AbstractAllGroupHeadsCollector termAllGroupHeadsCollector =
      TermAllGroupHeadsCollector.create(firstCommand.getKey(), firstCommand.getSortWithinGroup());
  if (collectors.isEmpty()) {
    searchWithTimeLimiter(query, filter, termAllGroupHeadsCollector);
  } else {
    collectors.add(termAllGroupHeadsCollector);
    searchWithTimeLimiter(query, filter, MultiCollector.wrap(collectors.toArray(new Collector[collectors.size()])));
  }

  return new BitDocSet(termAllGroupHeadsCollector.retrieveGroupHeads(searcher.maxDoc()));
}
项目:search    文件:Grouping.java   
/**
 * {@inheritDoc}
 */
@Override
public AbstractAllGroupHeadsCollector<?> createAllGroupCollector() throws IOException {
  Sort sortWithinGroup = groupSort != null ? groupSort : new Sort();
  return TermAllGroupHeadsCollector.create(groupBy, sortWithinGroup);
}
项目:NYBC    文件:Grouping.java   
/**
 * {@inheritDoc}
 */
@Override
public AbstractAllGroupHeadsCollector<?> createAllGroupCollector() throws IOException {
  Sort sortWithinGroup = groupSort != null ? groupSort : new Sort();
  return TermAllGroupHeadsCollector.create(groupBy, sortWithinGroup);
}
项目:search-core    文件:Grouping.java   
/**
 * {@inheritDoc}
 */
@Override
public AbstractAllGroupHeadsCollector<?> createAllGroupCollector() throws IOException {
  Sort sortWithinGroup = groupSort != null ? groupSort : new Sort();
  return TermAllGroupHeadsCollector.create(groupBy, sortWithinGroup);
}
项目:read-open-source-code    文件:Grouping.java   
/**
 * {@inheritDoc}
 */
@Override
public AbstractAllGroupHeadsCollector<?> createAllGroupCollector() throws IOException {
  Sort sortWithinGroup = groupSort != null ? groupSort : new Sort();
  return TermAllGroupHeadsCollector.create(groupBy, sortWithinGroup);
}
项目:read-open-source-code    文件:Grouping.java   
/**
 * {@inheritDoc}
 */
@Override
public AbstractAllGroupHeadsCollector<?> createAllGroupCollector() throws IOException {
  Sort sortWithinGroup = groupSort != null ? groupSort : new Sort();
  return TermAllGroupHeadsCollector.create(groupBy, sortWithinGroup);
}