Reputation: 131
I am unable to write multiple where conditions using hibernate lucene search
Here iam able to search based on any of the following keyword
but i am having multiple keywords here so how can I apply restrictions by using this keywords please help me to apply multiple restrictions in hibernate lucene search
.Thanks in advance Here is my query.
@Override
public List getCompaniesBasedOnSearch(String keyword,String keyword2,String keyword3) throws InterruptedException {FullTextSession fullTextSession = Search.getFullTextSession(session);
fullTextSession.createIndexer(Company.class).startAndWait();
QueryBuilder qb = fullTextSession.getSearchFactory().buildQueryBuilder().forEntity(Company.class).get();
org.apache.lucene.search.Query query = qb.keyword().onFields("company_name","locations.city","locations.state").matching(keyword1).createQuery();
org.hibernate.Query hibQuery = fullTextSession.createFullTextQuery(query, Company_Info.class);
Upvotes: 1
Views: 429
Reputation: 131
Yup....! finally i got the solution we can add multiple restrictions in Hibernate Lucene Search by using combined queries.Kindly go through the following
QueryBuilder qb = fullTextSession.getSearchFactory().buildQueryBuilder().forEntity(Student.class).get();
org.apache.lucene.search.Query query = qb.bool().must( qb.keyword().onFields("name","country","skills.skill").matching(keyword).createQuery())
.must( qb.keyword().onField("skills.skill").matching(skill).createQuery())
.must( qb.keyword().onField("locations.city").matching(location).createQuery())
.must( qb.keyword().onField("jobStatus").matching("active").createQuery())
.must( qb.keyword().onField("postedOrSaved").matching("posted").createQuery())
.createQuery();
org.hibernate.Query hibQuery = fullTextSession.createFullTextQuery(query, Jobs.class);
List<Jobs> result = hibQuery.list();
here i am performing (("a" OR "b" OR "c") AND ("d") AND ("e") AND ("f")
operation among student
entity fields.
Upvotes: 1