简体   繁体   English

在休眠搜索中,有没有一种方法可以按找到搜索词的字段进行构面?

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

Consider the following indexed entity: 考虑以下索引实体:

@Entity
@Indexed
public class Document {

    ...

    @Field
    private String title;

    @Field
    private String text;

}

Is there a way to present user a facet that will contain two options title and text with a count of documents where the search term was found in title and text respectively? 有没有一种方法可以向用户显示一个包含两个选项的titletext ,以及带有分别在titletext找到搜索词的文档数量的构面? And the user should be able to select these options to search only by interesting fields. 用户应该能够选择这些选项以仅按感兴趣的字段进行搜索。

For example, there are three documents: 例如,有三个文档:

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

And the search query is "one": then the facet will be: 搜索查询为“一个”:那么构面为:

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

There is no such built-in feature in Hibernate Search, but you can do it yourself. Hibernate Search中没有此类内置功能,但您可以自己完成。 Instead of running a single query, run three: 而不是运行单个查询,而是运行三个:

  1. one with a filter on "title OR text", without faceting 一个带有“标题或文本”过滤器的工具
  2. one with a filter only on the "title" field, with faceting on the "title" field 一个仅在“标题”字段上带有过滤器,在“标题”字段上带有切面的过滤器
  3. one with a filter only on the "text" field, with faceting on the "text" field 一个仅在“文本”字段上带有过滤器,在“文本”字段上带有刻面的过滤器

Then gather the results from the first query, the "title" facet from the second query, and the "text" facet from the third query. 然后从第一个查询收集结果,从第二个查询收集“ title”方面,从第三个查询收集“ text”方面。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM