2011-04-15 115 views
0

我在優化有問題,以下psedo代碼的任何幫助表示讚賞Solr的搜索,而索引

for every term 
open new index searcher 
do search 
if found 
skip and search for next term 
else 
add it to index 
commit 
close searcher 

在上面的代碼,同時增加新的文檔/學期索引,我必須承諾只是增加一個新的變化doc(我感到代價高昂)看到下次新的索引搜索器會發生新的變化。

有沒有什麼辦法可以提高性能。供參考:我有3600萬條款被索引。

回答

1

您可以創建一個HashSet來重複刪除內存中的術語列表,然後索引這些術語。僞代碼如下所示:

 
set := new HashSet 
for each term 
    if set contains term 
    skip to next iteration 
    else 
    add term to set 
end 
open index 
for each term in set 
    add term to index 
end 
close index 
+0

感謝您的快速回復。我提到的這個術語並不完全是指一個字符串。在搜索或將其添加到索引之前,我必須對每個術語進行大量的預處理。但在閱讀完您的評論後,我明白我可以在預處理後將它們編入索引,並從新索引中提取獨特的術語以供我的進一步工作。再次感謝。 – Aditya 2011-04-15 19:27:13

0

我建議你簡單地創建第二個索引(在RAMDirectory或上的臨時位置FSDirectory)。將第二(臨時)索引中未找到的所有條款/文檔添加到最後併合並兩個索引。

open index for searching 
for every term 
    open new index searcher 
    do search 
    if found 
    skip and search for next term 
    else 
    add it to the second index 
end 
close searcher 
commit temp index 
merge temp index into primary index 
commit primary index