2012-10-15 40 views
0

找到給出的單詞數在Lucene的(http://www.lucenetutorial.com/lucene-in-5-minutes.html)的教程,在Java中的Lucene庫

public class HelloLucene { 
public static void main(String[] args) throws IOException, ParseException { 
IndexWriter w = new IndexWriter(index, config); 
     addDoc(w, "Lucene lucene in Action"); 
     addDoc(w, "Lucene for Dummies"); 
     addDoc(w, "Managing Gigabytes"); 
     addDoc(w, "The Art of Computer Science"); 
     w.close(); 
String querystr = args.length > 0 ? args[0] : "lucene"; 
//... 
} 
} 

當我改變字符串上面所指示的那樣「的Lucene的Lucene在行動」,然後搜索關鍵字的文檔「lucene」,它找到字符串「Lucene lucene in Action」的匹配數1。我想發送一個字符串(例如「asd asd fds asd」)來運行並搜索「asd」並找到結果3.我怎樣才能通過使用查詢addDoc(w,「asd asd fds asd」); ???

它沒有給出所選行中的命中數。如果有擊中或命中,它會寫入1,如果沒有,則寫入0。

回答

1

我相信你要找的是矢量頻率的計算。

查看他們這個問題 - How to count term frequency for set of documents?

這 - Get highest frequency terms from Lucene index

如果我理解這個問題,你問如何計算的次數,一個詞組輸入(例如,「ASD」)發生在索引中的文檔中。在這種情況下,您需要計算矢量頻率項並比較您的搜索查詢,以確定是否存在匹配項和相應的出現次數。請記住,這將有助於匹配整個單詞,並且不旨在用於在索引文檔的語料庫中進行全文鄰近搜索。

1

我懷疑你可能會誤解你的例子中的某些東西。

我沒有看到任何內容,其中示例正在收集匹配文檔中匹配項的數量。也許作者使用這個詞是'命中'有點混淆的事情。

hits變量在那裏存儲匹配的文檔ID和分數ScoreDoc的集合。 hits[index].score是用來確定文檔匹配程度的最合適的方法。