我尝试使用hibernate搜索构建此查询,但我无法成功。
Select * from message where (sender.id = "1" AND message.status = "sent") OR (recipient.id = "1" AND message.status = "new") OR (recipient.id = "1" AND message.status = "seen")
我怎么能用lucene呢?
我卡在这里
FullTextSession fullTextSession = Search.getFullTextSession(getSessionFactory().getCurrentSession());
QueryBuilder qb = fullTextSession.getSearchFactory()
.buildQueryBuilder().forEntity(getPersistentClass()).get();
BooleanQuery bquery = new BooleanQuery();
Query q1 = qb.keyword().onField("sender.id").matching(user.getId()).createQuery();
Query q2 = qb.keyword().onField("status").matching(Message.Status.SENT).createQuery();
BooleanJunction must1 = qb.bool();
must1.must(q1);
must1.must(q2);
Query q3 = qb.keyword().onField("recipient.id").matching(user.getId()).createQuery();
Query q4 = qb.keyword().onField("status").matching(Message.Status.NEW).createQuery();
BooleanJunction must2 = qb.bool();
must2.must(q3);
must2.must(q4);
Query q5 = qb.keyword().onField("recipient.id").matching(user.getId()).createQuery();
Query q6 = qb.keyword().onField("status").matching(Message.Status.SEEN).createQuery();
BooleanJunction must3 = qb.bool();
must3.must(q5);
must3.must(q6);
任何帮助?
答案 0 :(得分:0)
Query query = qb.bool()
.should(must1.createQuery())
.should(must2.createQuery())
.should(must3.createQuery())
.createQuery();