关于lucene中多条件搜索文件的问题,各位帮忙啊

javalion 2003-08-23 05:30:35
现在有两个条件需要查询,是与的关系,一个是contents,另一个是path,一个一个查询都可以实现,但是如果我输入两个关键字,也就是keyContents和keyPath,而条件必须满足就是两者都存在的文件才能被检索出来。
如果是单个的,我用这个语句就可以了:
Query query = QueryParser.parse(line, "path", analyzer);
Hits hits = searcher.search(query);//得到结果
但是有两个条件,两个对应的字段,我该如何来解决这个问题,冥思苦想了很久了,望各位支持,给分啊!
...全文
93 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
javalion 2003-08-25
  • 打赏
  • 举报
回复
总算搞定了,原来想着自己rewrite query类的combine方法,可是比较恐怖啦,效率低下,总算发现原来lucene提供了这个接口,我找到了,真的找到了
用BooleanQuery对象的add方法,然后传几个参数就ok了
/** Adds a clause to a boolean query. Clauses may be:
<ul>
<li><code>required</code> which means that documents which <i>do not</i>
match this sub-query will <i>not</i> match the boolean query;
<li><code>prohibited</code> which means that documents which <i>do</i>
match this sub-query will <i>not</i> match the boolean query; or
<li>neither, in which case matched documents are neither prohibited from
nor required to match the sub-query.
</ul>
It is an error to specify a clause as both <code>required</code> and
<code>prohibited</code>.
*/
public final void add(Query query, boolean required, boolean prohibited) {
clauses.addElement(new BooleanClause(query, required, prohibited));
}
谢谢支持啊!
freedemon 2003-08-25
  • 打赏
  • 举报
回复
这个问题,问的很好。其实很好解决的。
freedemon 2003-08-25
  • 打赏
  • 举报
回复
zhe
stonewang 2003-08-24
  • 打赏
  • 举报
回复
有兴趣,顶
javalion 2003-08-24
  • 打赏
  • 举报
回复
怎么没有人用过lucene吗?自己up

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧