lucene关于实现freetext的查询的问题。

gerbility 2008-05-11
我看了lucene in action,书上给的例子精确到天,而我的要求需要精确到分或者秒。可是用RangeQuery在同一天内得不到结果,上网搜索说是只能用filter实现。不知道各位有没有做过相关的查询?lucene版本是2.3.2,谢谢,已解决。

再问个问题:要怎么实现freetext的查询,就是用户输入类似(fieldName1 = "keyword1" and fieldName2 in ("keyword2,keyword3")) or (...) and (not(...))之类的查询。谢谢各位。如果是重写queryParser的toString(),能不能说下去哪能找到样例啊?
gerbility 2008-05-11
再问个问题:要怎么实现freetext的查询,就是用户输入类似(fieldName1 = "keyword1" and fieldName2 in ("keyword2,keyword3")) or (...) and (not(...))之类的查询。谢谢各位。
fys124974704 2008-05-12
public class RangeQueryDemo {

private final static String INDEX_STONE_PATH = "/home/sd0707/Lucene/Index/";

private static String searchType1 = "title";

private static String searchKey1 = "Account";

private static String searchType2 = "title";

private static String searchKey2 = "IOC:";

public static void main(String[] args) throws IOException {
// 建立IndexSearcher对象需要比较长的时间,建议使用单例模式
IndexSearcher searcher = new IndexSearcher(INDEX_STONE_PATH);
//设置开始时间
Date date1 = new Date();
//建立需要查询对象
Term t1 = new Term(searchType1, searchKey1.toLowerCase());
Term t2 = new Term(searchType2, searchKey2.toLowerCase());
//建立Query
Query q = new RangeQuery(t1,t2,false);//这里的true代表包含要搜索的,false代表不包含要搜索的
//获取查询结果
Hits hits = searcher.search(q);
System.out.println(hits.length());
System.out.println("查询全部的数量需要 " + (new Date().getTime() - date1.getTime()) + "ms");
for (int i = 0; i < hits.length(); i++) {
Document doc = hits.doc(i);
System.out.println(doc.getField("title").stringValue());
}
System.out.println("查询全部的数量需要 " + (new Date().getTime() - date1.getTime()) + "ms");
}

}

这是小弟曾经写过的,你可以去试试,看能不能帮你
gerbility 2008-05-12
谢谢ls的哥们,那问题2关于freetext的有人知道吗?
javaeyes 2008-05-12
什么是boolean模型? 你这样的问题boolean模型都能解决.
看BooleanQuery 去, 随意构建你自己想要的Query
gerbility 2008-05-12
嘿嘿,谢谢ls的。我是用BooleanQuery建立了一个,然后又用QueryParser建立了一个,先给老大看看,如果不合适再说。呵呵
Global site tag (gtag.js) - Google Analytics