3

我想计算构面查询 UI 的构面计数,但我认为我遗漏了一些东西,因为我无法使用构面过滤器获得所需的数字。

这是一个例子。给定两个方面,每个方面有三个可能的项:

Colors: {red, yellow, blue}
Notes: {do, re, mi}

当我进行搜索时,一个方面中每个术语的计数不考虑另一个方面中设置的过滤器。

为了显示:

[ ] All colors (18)
 [x] Red (10)
 [ ] Green (5)
 [ ] Blue (3)

[ ] All notes (18)
 [ ] Do (5)
 [x] Re (7)
 [ ] Mi (6)

请注意,每个构面内的总数与查询的命中总数相加,就好像没有设置过滤器一样。

我想要的行为是让 Notes facet 中的数字考虑 Colors facet 中的过滤器,反之亦然。也就是说,注释项的数字总和应为 10(以匹配红色过滤器),而不是 18。

有趣的是,文档中的示例屏幕截图使用了 Linked In 中的示例,该示例实际上演示了我想要的行为。

http://www.elasticsearch.org/guide/reference/api/search/facets/

我可以通过为每个方面的每个术语手动重新提交一次查询来获得我想要的结果(呃),但我想知道是否有办法通过更改我的查询来获得与 LinkedIn 相同的行为。

4

1 回答 1

8

The only way I've found this to work is via the following logic for any multi-select facet:

Whenever the user selects a value from a facet ("drills down") you add a corresponding filter to all facets (via facet_filter) except the facet that the selection was done in, as well as to the top-level filter to filter the query results.

In other words, given 3 multi-select facets, A, B & C:

  • Select value from A => Add filter to top-level filter as well as to the facet_filter of facet B and C.
  • Select value from B => Add filter to top-level filter as well as to the facet_filter of A & C.
  • ... and so on

The top-level filter always combines the filters for all selections, whereas each individual facet contains facet_filters according to the selection in the other facets.

于 2012-08-18T12:47:08.193 回答