java - Lucene 文档提升

标签 java lucene scoring

我在 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();

提前谢谢您 阿瑟雷亚

最佳答案

仅查看代码很难说可能出了什么问题,需要尝试以下几件事:

  1. 使用 Luke 打开索引并查看文档的分数(包含“chris”)
  2. 不确定您是否绕过了一个或其他 setboost 调用。

    if (specialString.equals("chris")) doc.setBoost((float)(100000.1)); 别的 doc.setBoost((float)(0.00001));

关于java - Lucene 文档提升,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2770549/

相关文章:

machine-learning - SVM——评分函数

Java,如何删除ArrayList中的整数项

Java Lucene NRT 搜索不工作

java - Lucene updateDocument不删除文档

java - 使用 Lucene 索引文本文档时出现异常,使用 SnowballAnalyzer 进行清理

python - 如何在sklearn中使用make_scorer自定义评分函数

elasticsearch - Elasticsearch看似随机得分和匹配

java - 在netty服务器中读取JSON数据

java - Tomcat 使用堆栈而不是队列?为什么使用堆栈而不是队列或其他池更好?

java - manipule jBPM 5.4 模拟定时器事件的时间