Lucene的使用分类和DocValues一起刻面(Lucene use taxonomy and

2019-10-22 10:52发布

有使用基于该分类指数和DocValues方面的例子很多。 但我需要的类别(分类)和范围查询(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方面。

也许你有一个工作的例子,如何使用分类DocValues方面的DrillSideways在一起。

Answer 1:

DrillSideways假定您使用TaxonomyFacets或SortedSetDocValuesFacets独占。 如果不是这种情况,你也可以继承DrillSideways并重写buildFacetsResult方法来构建但是你喜欢最后的字母。 您将获得的DrillDownQuery和两个阵列与侧身FacetCollectors和变暗FacetsCollector,对于每一个暗淡您已经添加到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 use taxonomy and DocValues facets together