简体   繁体   English

使用Hibernate Search时如何在所有字段中进行搜索

[英]How to search across all fields when using Hibernate Search

I have just changed my search implementation to Hibernate Search 4.5.1.FINAL. 我刚刚将搜索实现更改为Hibernate Search 4.5.1.FINAL。 I am trying to create a query that search for a word in all the fields. 我正在尝试创建一个在所有字段中搜索单词的查询。 However, I am not able to find anything on how to achieve that. 但是,我无法找到有关如何实现这一目标的任何信息。 In ElasticSearch you have a _all field. 在ElasticSearch中,您有一个_all字段。 http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-all-field.html http://www.elasticsearch.org/guide/zh-CN/elasticsearch/reference/current/mapping-all-field.html

I am offering an text field that the user can write anything in and then get a result. 我提供了一个文本字段,用户可以在其中输入任何内容,然后得到结果。 But I don't know which fields he/she wants to search. 但是我不知道他/她想搜索哪些字段。

How can I do this in Hibernate Search? 如何在Hibernate Search中做到这一点? I don't want to add a @Field(name="_all") annotation in addition to the regular @Field annotation. 除了常规的@Field注释外,我不想添加@Field(name="_all")注释。 How do you do this? 你怎么做到这一点?

It seems that Hibernate Search does not support this feature natively (as also the lucene guys do not suggest it). 似乎Hibernate Search本身并不支持此功能(因为Lucene的人也不建议这样做)。

There seems that only one option exists which you already stated and you refuse using it; 似乎只有一种选择已经存在,而您拒绝使用; annotating all your fields for with a name: 用名称注释所有字段:

@Fields({
  @Field(index = Index.TOKENIZED),
  @Field(name = "ALL", index = Index.TOKENIZED)
})
//your variable declaration

As suggested in https://stackoverflow.com/a/25324486/115835 , one option is to make sure that property also gets indexed into a shared field. https://stackoverflow.com/a/25324486/115835中所建议,一种选择是确保属性也被索引到共享字段中。

The alternative is to build the query in a way that all fields are targeted. 替代方法是以所有字段为目标的方式来构建查询。 The user still can only see a single input field, but you under the hood build a boolean query targeting the fields you like (caution needs to be taken regarding analyzers and other search influencing field settings). 用户仍然只能看到一个输入字段,但是您可以在幕后针对您喜欢的字段构建布尔查询(需要注意分析器和其他影响搜索字段的设置)。 You can even make use of the meta data API, which allows you to programmatically get the list of configured fields. 您甚至可以使用元数据API,该API允许您以编程方式获取已配置字段的列表。 I think I prefer this approach above the additional field. 我认为我更喜欢这种方法而不是其他领域。

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

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