全文检索已经越来越像样了,不过还是发现很多问题,这玩意有些逻辑问题没想通。。
有三个字段参与检索:query1,query2,query3
这里设置它的逻辑关系如果只是单个的设置没啥问题,可是我想实现如:
SELECT * FROM TABLENAME WHERE (query1 like '%测试%' or query2 like '%测试%') and query3 like '%测试%'
IndexSearcher search = new IndexSearcher(indexpath);
QueryParser qp1 = new QueryParser("title", new StandardAnalyzer());
Query query1 = qp1.Parse(querystring);
QueryParser qp2 = new QueryParser("Content", new StandardAnalyzer()); Query query2 = qp2.Parse(querystring);
QueryParser qp3 = new QueryParser("tableName", new StandardAnalyzer()); Query query3 = qp3.Parse("异国文化");
BooleanQuery query = new BooleanQuery();
query.Add(query1, BooleanClause.Occur.SHOULD);
query.Add(query2, BooleanClause.Occur.SHOULD);
query.Add(query3, BooleanClause.Occur.MUST);
query.Add(query1, BooleanClause.Occur.SHOULD);
query.Add(query2, BooleanClause.Occur.SHOULD);
query.Add(query3, BooleanClause.Occur.MUST);
想实现先OR 再 AND查询 我这里的关键词应该怎么设置呢?
select * from TABLENAME where id in (SELECT id FROM TABLENAME WHERE query1 like '%测试%' or query2 like '%测试%' ) and query3 like '%测试%'
你可以把这个 query1 like '%测试%' or query2 like '%测试%' 构建一个 query1
query3 like '%测试%' 构建一个 query2
没用过,你自己看看吧,有个 MultiFieldQueryParser 这个玩意儿,好像.