Reputation: 163
I'm trying to find a way to search items in my database using Hibernate search.
What I have is an entity with several fields, and the fields I want to search on are indexed.
I would like to be able to search items with fieldA==valueA && fieldB==valueB
(and maybe add more field to this search, if the user select more search criteria).
I am not even sure I should use Hibernate search for that or just construct a custom query.
Upvotes: 0
Views: 229
Reputation: 1014
Did you try a hql query?
Query q = s.createQuery("from foo Foo as foo where foo.name=:name and foo.size=:size");
q.setProperties(fooBean); // fooBean has getName() and getSize()
List foos = q.list();
Source: http://docs.jboss.org/hibernate/core/3.5/reference/en/html/queryhql.html
Edited:
Sees for a Lucene example to search on different fields https://stackoverflow.com/a/16009337/7141562
Anyway, i would stay with the JPA/Hibernate mode because it seems simpler and clearer solution.
Upvotes: 1