Lucene:facet范围取决于返回的结果

rqdpfwrv  于 2022-11-07  发布在  Lucene
关注(0)|答案(1)|浏览(256)

我有一个工作搜索设置,我给予方面的范围,并得到正确的结果回来。问题是,价格方面,我需要依赖于返回的结果,所以我不能事先知道范围。
示例1:搜索找到4个产品,价格如下:20、30、40、55。因此,我希望这些面是这样的:

0 - 20 (1)
21 - 40 (2)
41 - 60 (1)

示例2:搜索找到2个具有以下价格的产品:200,400,所以我希望面是这样的:

100 - 200 (1)
300 - 400 (1)

在Lucene中有没有什么地方我可以指定我希望范围基于搜索结果中的一个字段?
谢谢你

f4t66c6m

f4t66c6m1#

在多次搜索之后,我没有找到一种开箱即用的方法。实现方法是扩展DrillSideways,在BuildFacetsResult方法的开始,我们提取具有所需值的字段。如下所示:

public class DrillSidewaysHelper : DrillSideways
{
    private TopFieldCollector _localCollector;
    private List<decimal> _prices;
    protected override LuceneFacets BuildFacetsResult(FacetsCollector drillDownCollector, FacetsCollector[] drillSidewaysCollectors,
            string[] drillSidewaysFacets)
    {
       ExtractResults(); //here we extract the methods from the _localCollector and populate _prices
        ....here we can generate the facets range based on the _prices

    }

    public FacetResultSet<T> OurSearch(DrillDownQuery drillDownQuery, Sort sort)
    {
        int limit = m_searcher.IndexReader.MaxDoc;

        _localCollector = TopFieldCollector.Create(sort, limit, null, true, true, false, true);
        var drillSidewaysResult = Search(drillDownQuery, _localCollector);

        var facets = ExtractFacets(drillSidewaysResult.Facets);

        return new FacetResultSet<T>(_results, (uint) _localCollector.TotalHits, facets);
    }
}

和用法:

var drillSideways = new DrillSidewaysHelper(searcher, facetsConfig, taxonomyReader);

return drillSideways.OurSearch(drillDownQuery, sort);

相关问题