查看:1824|回复:0
实现SQL:(unitid like 'unitid%' and idml like 'id2%') or (tounitid like 'unitid%' a...发表时间:2013-01-10 16:02:30

我爱java

0分享0主题0帖子

学徒一级

(初出茅庐)

Lucene嵌套查询 实现SQL:(unitid like 'unitid%'  and idml like 'id2%') or (tounitid like 'unitid%' and tomlid like 'id2%' and tostate=1)


01    BooleanQuery bQuery = new BooleanQuery();
02    BooleanQuery b1 = new BooleanQuery();
03    WildcardQuery w1 = new WildcardQuery(new Term("unitid", unitid + "*"));
04    WildcardQuery w2 = new WildcardQuery(new Term("idml", id2 + "*"));
05    b1.add(w1, BooleanClause.Occur.MUST);//AND
06    b1.add(w2, BooleanClause.Occur.MUST);//AND
07    bQuery.add(b1, BooleanClause.Occur.SHOULD);//OR
08    BooleanQuery b2 = new BooleanQuery();
09    WildcardQuery w3 = new WildcardQuery(new Term("tounitid", unitid + "*"));
10    WildcardQuery w4 = new WildcardQuery(new Term("tomlid", id2 + "*"));
11    WildcardQuery w5 = new WildcardQuery(new Term("tostate", "1"));
12    b2.add(w3, BooleanClause.Occur.MUST);//AND
13    b2.add(w4, BooleanClause.Occur.MUST);//AND
14    b2.add(w5, BooleanClause.Occur.MUST);//AND
15    bQuery.add(b2, BooleanClause.Occur.SHOULD);//OR

相关帖子

您需要登录以后才可以回帖    登录|注册