2010-05-05 55 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