Lucene一起使用分类法和DocValues方面

时间:2015-03-30 21:09:26

标签: solr elasticsearch lucene taxonomy facet

有很多基于分类索引和DocValues使用facet的例子。但我需要将类别(分类法)和范围查询(NumericDocValuesField)的层次结构一起使用。 例如DrillSideways:

  DrillSideways ds = new DrillSideways (searcher, config, taxoReader);
  DrillSideways.DrillSidewaysResult result = ds.search (q, topScoreDocCollector);

ds.search()的第二个参数是 TopScoreDocCollector

ds.search()中创建了

FacetsCollector ,并且无法将此收集器传递给 ds.search()。传递 MultiCollector.wrap(FacetsCollector,TopScoreDocCollector)作为 ds.search()中的第二个参数不正确(?)。但是 FacetsCollector 需要构建分类索引中不可用的构面:

 Facets facetsTime = new LongRangeFacetCounts (..., FacetsCollector, ...);
 facetsTime.getTopChildren (...);

同样列出 result.facets 包含空值,引用 DocValues 方面。

也许您有一个工作示例,如何在 DrillSideways 中一起使用分类 DocValues 方面。

1 个答案:

答案 0 :(得分:2)

DrillSideways假定您只使用TaxonomyFacets或SortedSetDocValuesFacets。如果不是这种情况,您可以继承DrillSideways并覆盖buildFacetsResult方法以构建最终的Facets,无论您喜欢什么。你将获得DrillDownQuery的FacetsCollector和两个带有侧面FacetCollectors和dims的数组,用于你添加到DrissSideways的每个暗淡。

以下是一个例子:

public class MyDrillSideways extends DrillSideways {

  public MyDrillSideways(IndexSearcher searcher, FacetsConfig config, TaxonomyReader taxoReader) {
    super(searcher, config, taxoReader);
  }

  @Override
  protected Facets buildFacetsResult(FacetsCollector drillDowns, FacetsCollector[] drillSideways, String[] drillSidewaysDims) throws IOException {

    String longRangeFacetDim = "mySpecialLongRangeDim";
    Facets drillDownFacets = new FastTaxonomyFacetCounts(taxoReader, config, drillDowns);

    boolean foundLongRangeInDrillSideways = false;
    Map<String, Facets> drillSidewaysFacets = new HashMap<>();
    if (drillSideways != null) {
      for (int i = 0; i < drillSideways.length; i++) {
        String sidewaysDim = drillSidewaysDims[i];
        FacetsCollector drillSideway = drillSideways[i];

        Facets sidewaysFacets;
        if (sidewaysDim.equals(longRangeFacetDim)) {
          foundLongRangeInDrillSideways = true;
          sidewaysFacets = new LongRangeFacetCounts(...,drillSideway,...);
        } else {
          sidewaysFacets = new FastTaxonomyFacetCounts(taxoReader, config, drillSideway);
        }
        drillSidewaysFacets.put(sidewaysDim, sidewaysFacets);
      }
    }

    if (!foundLongRangeInDrillSideways) {
      Facets facetsTime = new LongRangeFacetCounts(..., FacetsCollector, ...);
      drillSidewaysFacets.put(longRangeFacetDim, facetsTime);
    }

    return new MultiFacets(drillSidewaysFacets, drillDownFacets);
  }
}