hibernate-search 中是否有一种方法可以按找到搜索词的字段进行分面?

Is there a way in hibernate-search to facet by fields where the search term was found?

考虑以下索引实体:

@Entity
@Indexed
public class Document {

    ...

    @Field
    private String title;

    @Field
    private String text;

}

有没有办法向用户呈现一个包含两个选项 titletext 的方面,以及在 title 和 [=] 中找到搜索词的文档计数14=]分别是?并且用户应该能够 select 这些选项以仅按感兴趣的字段进行搜索。

比如有三个文件:

{ "title" : "One", "text" : "One" }
{ "title" : "One and Two", "text" : "Two" }
{ "title" : "Three", "text" : "Three and Two" }

并且搜索查询是 "one":那么构面将是:

{ "title" : 2, "text" : 1 }

Hibernate Search 中没有这样的内置功能,但您可以自己实现。不是 运行 单个查询,而是 运行 三个:

  1. 一个在 "title OR text" 上有过滤器,没有刻面
  2. 一个仅在 "title" 字段上有过滤器,在 "title" 字段上有分面
  3. 仅在 "text" 字段上有过滤器,在 "text" 字段上有分面

然后收集第一个查询的结果、第二个查询的 "title" 方面和第三个查询的 "text" 方面。

有关 Hibernate 搜索中分面的更多信息:https://docs.jboss.org/hibernate/stable/search/reference/en-US/html_single/#query-faceting