有没有一种方法在hibernate-search中查找搜索词的字段? [英] Is there a way in hibernate-search to facet by fields where the search term was found?

查看:115
本文介绍了有没有一种方法在hibernate-search中查找搜索词的字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑以下索引实体:

  @Entity 
@Indexed
public class Document {

...

@Field
私有字符串标题;

@Field
private String text;


$ / code>

有没有办法向用户展示一个包含两个选项标题文本以及在标题中找到搜索词的文档计数文字分别?用户应该能够选择这些选项,以便只搜索有趣的字段。



例如,有三个文件:

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

而搜索查询是one:那么方面将是:

  {title: 2,text:1} 


解决方案

这种内置的功能在Hibernate Search中,但你可以自己做。而不是运行一个查询,运行三个:


  1. 一个带有标题或文本筛选器,不需要分面

  2. 其中一个仅在标题字段中显示过滤器,并且只在文本字段中显示title字段
  3. 然后从第一个查询中收集结果,第二个查询中的标题方面以及第二个查询中的标题方面第三个查询中的文本方面。



    更多关于Hibernate Search中的faceting的信息: https://docs.jboss.org/hibernate/stable/search/reference/zh-CN/html_single/#query面对


    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? 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. 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.

    More information about faceting in Hibernate Search: https://docs.jboss.org/hibernate/stable/search/reference/en-US/html_single/#query-faceting

    这篇关于有没有一种方法在hibernate-search中查找搜索词的字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆