2010-05-05 57 views
0

我有Lucene的提高,荫努力提高其与(名字)字段匹配指定 特定文件我已经发布的代码Lucene的文档推进

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

预先感谢您 Athreya

回答

1

很难说有什么可能是错的只是看代码,几件事情尝试:

  1. 打开与卢克的指数,看到了(包含“chris”)
  2. 不确定您是否绕过其中一个或另一个setboost调用。

    if(specialString.equals(“chris”)) doc.setBoost((float)(100000.1)); else doc.setBoost((float)(0.00001));

+0

好的,谢谢你的回复 – Greenhorn 2010-05-05 16:35:09

+0

if(specialString.equals(“chris”))doc.setBoost((float)(100000.1)); else doc.setBoost((float)(0.00001));这里 我在这里试图取消提升,如果没有找到文档,并最大化它,如果找到,以便文档的分数,如果发现将是高的 – Greenhorn 2010-05-05 16:37:11

+0

好吧,但上面的代码似乎违反直觉,也许把un-boost放在else语句中。还要看看使用卢克的索引,这会告诉你更多关于得分的信息。 – Mikos 2010-05-05 21:22:18