Lucene 文档提升
我在 lucene boosting 方面遇到问题,我试图提升与指定的(名字)字段匹配的特定文档 我已经发布了部分代码,
private static Document createDoc(String lucDescription,String primaryk,String specialString){
Document doc = new Document();
doc.add(new Field("lucDescription",lucDescription, Field.Store.NO, Field.Index.TOKENIZED));
doc.add(new Field("primarykey",primaryk,Field.Store.YES,Field.Index.NO));
doc.add(new Field("specialDescription",specialString, Field.Store.NO, Field.Index.UN_TOKENIZED));
doc.setBoost ((float)(0.00001));
if (specialString.equals("chris"))
doc.setBoost ((float)(100000.1));
return doc;
}
为什么这不起作用?
public static String dbSearch(String searchString){
List<String> pkList = new ArrayList<String>();
String conCat="(";
try{
String querystr = searchString;
Query query = new QueryParser("lucDescription", new StandardAnalyzer()).parse(querystr);
IndexSearcher searchIndex = new IndexSearcher("/home/athreya/docsIndexFile");
// Index of the User table--> /home/araghu/aditya/indexFile.
Hits hits = searchIndex.search(query);
System.out.println("Found " + hits.length() + " hits.");
for(int iterator=0;iterator<hits.length();iterator++) {
String primKey=hits.doc(iterator).get("primarykey");
System.out.println(primKey);
pkList.add(primKey);
}
searchIndex.close();
先感谢您 阿瑟雷亚
I am having problem with lucene boosting, Iam trying to boost a particular document which matches with the (firstname)field specified
I have posted the part of the code
private static Document createDoc(String lucDescription,String primaryk,String specialString){
Document doc = new Document();
doc.add(new Field("lucDescription",lucDescription, Field.Store.NO, Field.Index.TOKENIZED));
doc.add(new Field("primarykey",primaryk,Field.Store.YES,Field.Index.NO));
doc.add(new Field("specialDescription",specialString, Field.Store.NO, Field.Index.UN_TOKENIZED));
doc.setBoost ((float)(0.00001));
if (specialString.equals("chris"))
doc.setBoost ((float)(100000.1));
return doc;
}
why is this not working?
public static String dbSearch(String searchString){
List<String> pkList = new ArrayList<String>();
String conCat="(";
try{
String querystr = searchString;
Query query = new QueryParser("lucDescription", new StandardAnalyzer()).parse(querystr);
IndexSearcher searchIndex = new IndexSearcher("/home/athreya/docsIndexFile");
// Index of the User table--> /home/araghu/aditya/indexFile.
Hits hits = searchIndex.search(query);
System.out.println("Found " + hits.length() + " hits.");
for(int iterator=0;iterator<hits.length();iterator++) {
String primKey=hits.doc(iterator).get("primarykey");
System.out.println(primKey);
pkList.add(primKey);
}
searchIndex.close();
Thank you in advance
Athreya
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
很难说仅查看代码可能会出现什么问题,可以尝试以下几件事:
不确定您是否绕过了一个或另一个 setboost来电。
if (specialString.equals("chris"))
doc.setBoost((float)(100000.1));
别的
doc.setBoost ((float)(0.00001));
Hard to say what could be wrong just looking at the code, couple of things to try:
Unsure if you are bypassing one or the other setboost calls.
if (specialString.equals("chris"))
doc.setBoost ((float)(100000.1));
else
doc.setBoost ((float)(0.00001));