一尘不染

Lucene同时使用分类法和DocValues方面

elasticsearch

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

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

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

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

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

还要列出 result.facet 包含null值,该值引用 DocValues facet。

也许您有一个 可行的* 示例,如何在 DrillSideways中 一起使用 分类法DocValues 方面。 *


阅读 238

收藏
2020-06-22

共1个答案

一尘不染

DrillSideways假定您仅使用TaxonomyFacets或SortedSetDocValuesFacets。如果不是这种情况,则可以根据需要将DrillSideways子类化并覆盖该buildFacetsResult方法以构建最终的Facet
。对于您添加到DrissSideways中的每个暗角,您将获得用于DrillDownQuery的FacetsCollector和两个带有侧面FacetCollectors和暗角的数组。

这是一个例子:

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);
  }
}
2020-06-22