Reputation: 49107
I have just changed my search implementation to 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. http://www.elasticsearch.org/guide/en/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? I don't want to add a @Field(name="_all")
annotation in addition to the regular @Field
annotation. How do you do this?
Upvotes: 0
Views: 3018
Reputation: 19129
As suggested in https://stackoverflow.com/a/25324486/115835, one option is to make sure that property also gets indexed into a shared field.
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. I think I prefer this approach above the additional field.
Upvotes: 0
Reputation: 16384
It seems that Hibernate Search does not support this feature natively (as also the lucene guys do not suggest it).
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
Upvotes: 2