本文介绍了Lucene一起使用分类法和DocValues方面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

There are many examples of the use of facets based on the taxonomy index and on DocValues. But I need use as a hierarchy of categories (taxonomy) and Range queries (NumericDocValuesField) together.For example DrillSideways :

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

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

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

FacetsCollector created inside ds.search() and not possible to pass this collector to ds.search(). Pass MultiCollector.wrap (FacetsCollector, TopScoreDocCollector) as second parameter in ds.search() is not correct(?). However FacetsCollector need to build facets that are not available in the taxonomy index:

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

还列出 result.facets 包含空值,该空值引用 DocValues 方面.

Also list result.facets contain null value, which refers to DocValues ​​facet.

也许您有一个有效的示例,说明如何在 DrillSideways 中一起使用分类学 DocValues 方面.

Maybe you have a working example how use taxonomy and DocValues ​​facets in DrillSideways together.

推荐答案

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

DrillSideways assumes that you use either TaxonomyFacets or SortedSetDocValuesFacets exclusively. If this is not the case, you can subclass DrillSideways and override the buildFacetsResult method to build the final Facets however you like. You will get the FacetsCollector for the DrillDownQuery and two arrays with the sideways FacetCollectors and dims, for every dim you have added to the 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);
  }
}

这篇关于Lucene一起使用分类法和DocValues方面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 14:36