当前位置: 首页>>代码示例>>Java>>正文


Java TermGroupFacetCollector类代码示例

本文整理汇总了Java中org.apache.lucene.search.grouping.term.TermGroupFacetCollector的典型用法代码示例。如果您正苦于以下问题:Java TermGroupFacetCollector类的具体用法?Java TermGroupFacetCollector怎么用?Java TermGroupFacetCollector使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


TermGroupFacetCollector类属于org.apache.lucene.search.grouping.term包,在下文中一共展示了TermGroupFacetCollector类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: groupVariations

import org.apache.lucene.search.grouping.term.TermGroupFacetCollector; //导入依赖的package包/类
/**
 * Groups variations from specified {@link List} of {@link VcfFile}s by specified field
 * @param files a {@link List} of {@link FeatureFile}, which indexes to search
 * @param query a query to search in index
 * @param groupBy a field to perform grouping
 * @return a {@link List} of {@link Group}s, mapping field value to number of variations, having this value
 * @throws IOException if something goes wrong with the file system
 */
public List<Group> groupVariations(List<VcfFile> files, Query query, String groupBy) throws IOException {
    List<Group> res = new ArrayList<>();

    if (CollectionUtils.isEmpty(files)) {
        return Collections.emptyList();
    }

    SimpleFSDirectory[] indexes = fileManager.getIndexesForFiles(files);

    try (MultiReader reader = openMultiReader(indexes)) {
        if (reader.numDocs() == 0) {
            return Collections.emptyList();
        }

        IndexSearcher searcher = new IndexSearcher(reader);
        AbstractGroupFacetCollector groupedFacetCollector =
            TermGroupFacetCollector.createTermGroupFacetCollector(FeatureIndexFields.UID.fieldName,
                                                  getGroupByField(files, groupBy), false, null, GROUP_INITIAL_SIZE);
        searcher.search(query, groupedFacetCollector); // Computing the grouped facet counts
        TermGroupFacetCollector.GroupedFacetResult groupedResult = groupedFacetCollector.mergeSegmentResults(
            reader.numDocs(), 1, false);
        List<AbstractGroupFacetCollector.FacetEntry> facetEntries = groupedResult.getFacetEntries(0,
                                                                                                  reader.numDocs());
        for (AbstractGroupFacetCollector.FacetEntry facetEntry : facetEntries) {
            res.add(new Group(facetEntry.getValue().utf8ToString(), facetEntry.getCount()));
        }
    } finally {
        for (SimpleFSDirectory index : indexes) {
            IOUtils.closeQuietly(index);
        }
    }

    return res;
}
 
开发者ID:react-dev26,项目名称:NGB-master,代码行数:43,代码来源:FeatureIndexDao.java

示例2: groupVariations

import org.apache.lucene.search.grouping.term.TermGroupFacetCollector; //导入依赖的package包/类
/**
 * Groups variations from specified {@link List} of {@link VcfFile}s by specified field
 * @param files a {@link List} of {@link FeatureFile}, which indexes to search
 * @param query a query to search in index
 * @param groupBy a field to perform grouping
 * @return a {@link List} of {@link Group}s, mapping field value to number of variations, having this value
 * @throws IOException if something goes wrong with the file system
 */
public List<Group> groupVariations(List<VcfFile> files, Query query, String groupBy) throws IOException {
    List<Group> res = new ArrayList<>();

    if (CollectionUtils.isEmpty(files)) {
        return Collections.emptyList();
    }

    SimpleFSDirectory[] indexes = fileManager.getIndexesForFiles(files);
    long totalIndexSize = getTotalIndexSize(indexes);
    if (totalIndexSize > luceneIndexMaxSizeForGrouping) {
        throw new IllegalArgumentException(getMessage(MessagesConstants.ERROR_FEATURE_INEDX_TOO_LARGE));
    }

    try (MultiReader reader = openMultiReader(indexes)) {
        if (reader.numDocs() == 0) {
            return Collections.emptyList();
        }

        IndexSearcher searcher = new IndexSearcher(reader);
        AbstractGroupFacetCollector groupedFacetCollector =
                TermGroupFacetCollector.createTermGroupFacetCollector(FeatureIndexFields.UID.fieldName,
                        getGroupByField(files, groupBy), false, null, GROUP_INITIAL_SIZE);
        searcher.search(query, groupedFacetCollector); // Computing the grouped facet counts
        TermGroupFacetCollector.GroupedFacetResult groupedResult = groupedFacetCollector.mergeSegmentResults(
                reader.numDocs(), 1, false);
        List<AbstractGroupFacetCollector.FacetEntry> facetEntries = groupedResult.getFacetEntries(0,
                reader.numDocs());
        for (AbstractGroupFacetCollector.FacetEntry facetEntry : facetEntries) {
            res.add(new Group(facetEntry.getValue().utf8ToString(), facetEntry.getCount()));
        }
    } finally {
        for (SimpleFSDirectory index : indexes) {
            IOUtils.closeQuietly(index);
        }
    }

    return res;
}
 
开发者ID:epam,项目名称:NGB,代码行数:47,代码来源:FeatureIndexDao.java

示例3: getGroupedCounts

import org.apache.lucene.search.grouping.term.TermGroupFacetCollector; //导入依赖的package包/类
public NamedList<Integer> getGroupedCounts(SolrIndexSearcher searcher,
                                           DocSet base,
                                           String field,
                                           boolean multiToken,
                                           int offset,
                                           int limit,
                                           int mincount,
                                           boolean missing,
                                           String sort,
                                           String prefix) throws IOException {
  GroupingSpecification groupingSpecification = rb.getGroupingSpec();
  String groupField  = groupingSpecification != null ? groupingSpecification.getFields()[0] : null;
  if (groupField == null) {
    throw new SolrException (
        SolrException.ErrorCode.BAD_REQUEST,
        "Specify the group.field as parameter or local parameter"
    );
  }

  BytesRef prefixBR = prefix != null ? new BytesRef(prefix) : null;
  TermGroupFacetCollector collector = TermGroupFacetCollector.createTermGroupFacetCollector(groupField, field, multiToken, prefixBR, 128);
  searcher.search(new MatchAllDocsQuery(), base.getTopFilter(), collector);
  boolean orderByCount = sort.equals(FacetParams.FACET_SORT_COUNT) || sort.equals(FacetParams.FACET_SORT_COUNT_LEGACY);
  TermGroupFacetCollector.GroupedFacetResult result = collector.mergeSegmentResults(offset + limit, mincount, orderByCount);

  CharsRef charsRef = new CharsRef();
  FieldType facetFieldType = searcher.getSchema().getFieldType(field);
  NamedList<Integer> facetCounts = new NamedList<Integer>();
  List<TermGroupFacetCollector.FacetEntry> scopedEntries = result.getFacetEntries(offset, limit);
  for (TermGroupFacetCollector.FacetEntry facetEntry : scopedEntries) {
    facetFieldType.indexedToReadable(facetEntry.getValue(), charsRef);
    facetCounts.add(charsRef.toString(), facetEntry.getCount());
  }

  if (missing) {
    facetCounts.add(null, result.getTotalMissingCount());
  }

  return facetCounts;
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:41,代码来源:SimpleFacets.java

示例4: getGroupedCounts

import org.apache.lucene.search.grouping.term.TermGroupFacetCollector; //导入依赖的package包/类
public NamedList<Integer> getGroupedCounts(SolrIndexSearcher searcher,
                                           DocSet base,
                                           String field,
                                           boolean multiToken,
                                           int offset,
                                           int limit,
                                           int mincount,
                                           boolean missing,
                                           String sort,
                                           String prefix,
                                           Predicate<BytesRef> termFilter) throws IOException {
  GroupingSpecification groupingSpecification = rb.getGroupingSpec();
  final String groupField  = groupingSpecification != null ? groupingSpecification.getFields()[0] : null;
  if (groupField == null) {
    throw new SolrException (
        SolrException.ErrorCode.BAD_REQUEST,
        "Specify the group.field as parameter or local parameter"
    );
  }

  BytesRef prefixBytesRef = prefix != null ? new BytesRef(prefix) : null;
  final TermGroupFacetCollector collector = TermGroupFacetCollector.createTermGroupFacetCollector(groupField, field, multiToken, prefixBytesRef, 128);
  
  Collector groupWrapper = getInsanityWrapper(groupField, collector);
  Collector fieldWrapper = getInsanityWrapper(field, groupWrapper);
  // When GroupedFacetCollector can handle numerics we can remove the wrapped collectors
  searcher.search(base.getTopFilter(), fieldWrapper);
  
  boolean orderByCount = sort.equals(FacetParams.FACET_SORT_COUNT) || sort.equals(FacetParams.FACET_SORT_COUNT_LEGACY);
  TermGroupFacetCollector.GroupedFacetResult result 
    = collector.mergeSegmentResults(limit < 0 ? Integer.MAX_VALUE : 
                                    (offset + limit), 
                                    mincount, orderByCount);

  CharsRefBuilder charsRef = new CharsRefBuilder();
  FieldType facetFieldType = searcher.getSchema().getFieldType(field);
  NamedList<Integer> facetCounts = new NamedList<>();
  List<TermGroupFacetCollector.FacetEntry> scopedEntries 
    = result.getFacetEntries(offset, limit < 0 ? Integer.MAX_VALUE : limit);
  for (TermGroupFacetCollector.FacetEntry facetEntry : scopedEntries) {
    //:TODO:can we filter earlier than this to make it more efficient?
    if (termFilter != null && !termFilter.test(facetEntry.getValue())) {
      continue;
    }
    facetFieldType.indexedToReadable(facetEntry.getValue(), charsRef);
    facetCounts.add(charsRef.toString(), facetEntry.getCount());
  }

  if (missing) {
    facetCounts.add(null, result.getTotalMissingCount());
  }

  return facetCounts;
}
 
开发者ID:upenn-libraries,项目名称:solrplugins,代码行数:55,代码来源:SimpleFacets.java

示例5: GroupedFacetResult

import org.apache.lucene.search.grouping.term.TermGroupFacetCollector; //导入依赖的package包/类
private GroupedFacetResult(int totalCount, int totalMissingCount, List<TermGroupFacetCollector.FacetEntry> facetEntries) {
  this.totalCount = totalCount;
  this.totalMissingCount = totalMissingCount;
  this.facetEntries = facetEntries;
}
 
开发者ID:europeana,项目名称:search,代码行数:6,代码来源:GroupFacetCollectorTest.java

示例6: getFacetEntries

import org.apache.lucene.search.grouping.term.TermGroupFacetCollector; //导入依赖的package包/类
public List<TermGroupFacetCollector.FacetEntry> getFacetEntries() {
  return facetEntries;
}
 
开发者ID:europeana,项目名称:search,代码行数:4,代码来源:GroupFacetCollectorTest.java

示例7: getGroupedCounts

import org.apache.lucene.search.grouping.term.TermGroupFacetCollector; //导入依赖的package包/类
public NamedList<Integer> getGroupedCounts(SolrIndexSearcher searcher,
                                           DocSet base,
                                           String field,
                                           boolean multiToken,
                                           int offset,
                                           int limit,
                                           int mincount,
                                           boolean missing,
                                           String sort,
                                           String prefix) throws IOException {
  GroupingSpecification groupingSpecification = rb.getGroupingSpec();
  String groupField  = groupingSpecification != null ? groupingSpecification.getFields()[0] : null;
  if (groupField == null) {
    throw new SolrException (
        SolrException.ErrorCode.BAD_REQUEST,
        "Specify the group.field as parameter or local parameter"
    );
  }

  BytesRef prefixBR = prefix != null ? new BytesRef(prefix) : null;
  TermGroupFacetCollector collector = TermGroupFacetCollector.createTermGroupFacetCollector(groupField, field, multiToken, prefixBR, 128);
  searcher.search(new MatchAllDocsQuery(), base.getTopFilter(), collector);
  boolean orderByCount = sort.equals(FacetParams.FACET_SORT_COUNT) || sort.equals(FacetParams.FACET_SORT_COUNT_LEGACY);
  TermGroupFacetCollector.GroupedFacetResult result 
    = collector.mergeSegmentResults(limit < 0 ? Integer.MAX_VALUE : 
                                    (offset + limit), 
                                    mincount, orderByCount);

  CharsRef charsRef = new CharsRef();
  FieldType facetFieldType = searcher.getSchema().getFieldType(field);
  NamedList<Integer> facetCounts = new NamedList<>();
  List<TermGroupFacetCollector.FacetEntry> scopedEntries 
    = result.getFacetEntries(offset, limit < 0 ? Integer.MAX_VALUE : limit);
  for (TermGroupFacetCollector.FacetEntry facetEntry : scopedEntries) {
    facetFieldType.indexedToReadable(facetEntry.getValue(), charsRef);
    facetCounts.add(charsRef.toString(), facetEntry.getCount());
  }

  if (missing) {
    facetCounts.add(null, result.getTotalMissingCount());
  }

  return facetCounts;
}
 
开发者ID:europeana,项目名称:search,代码行数:45,代码来源:SimpleFacets.java

示例8: getGroupedCounts

import org.apache.lucene.search.grouping.term.TermGroupFacetCollector; //导入依赖的package包/类
public NamedList<Integer> getGroupedCounts(SolrIndexSearcher searcher,
                                           DocSet base,
                                           String field,
                                           boolean multiToken,
                                           int offset,
                                           int limit,
                                           int mincount,
                                           boolean missing,
                                           String sort,
                                           String prefix) throws IOException {
  GroupingSpecification groupingSpecification = rb.getGroupingSpec();
  String groupField  = groupingSpecification != null ? groupingSpecification.getFields()[0] : null;
  if (groupField == null) {
    throw new SolrException (
        SolrException.ErrorCode.BAD_REQUEST,
        "Specify the group.field as parameter or local parameter"
    );
  }

  BytesRef prefixBR = prefix != null ? new BytesRef(prefix) : null;
  TermGroupFacetCollector collector = TermGroupFacetCollector.createTermGroupFacetCollector(groupField, field, multiToken, prefixBR, 128);
  searcher.search(new MatchAllDocsQuery(), base.getTopFilter(), collector);
  boolean orderByCount = sort.equals(FacetParams.FACET_SORT_COUNT) || sort.equals(FacetParams.FACET_SORT_COUNT_LEGACY);
  TermGroupFacetCollector.GroupedFacetResult result 
    = collector.mergeSegmentResults(limit < 0 ? Integer.MAX_VALUE : 
                                    (offset + limit), 
                                    mincount, orderByCount);

  CharsRef charsRef = new CharsRef();
  FieldType facetFieldType = searcher.getSchema().getFieldType(field);
  NamedList<Integer> facetCounts = new NamedList<Integer>();
  List<TermGroupFacetCollector.FacetEntry> scopedEntries 
    = result.getFacetEntries(offset, limit < 0 ? Integer.MAX_VALUE : limit);
  for (TermGroupFacetCollector.FacetEntry facetEntry : scopedEntries) {
    facetFieldType.indexedToReadable(facetEntry.getValue(), charsRef);
    facetCounts.add(charsRef.toString(), facetEntry.getCount());
  }

  if (missing) {
    facetCounts.add(null, result.getTotalMissingCount());
  }

  return facetCounts;
}
 
开发者ID:yintaoxue,项目名称:read-open-source-code,代码行数:45,代码来源:SimpleFacets.java


注:本文中的org.apache.lucene.search.grouping.term.TermGroupFacetCollector类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。