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:
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.