Java 索引时的Solr搜索

Java 索引时的Solr搜索,java,optimization,indexing,lucene,solr,Java,Optimization,Indexing,Lucene,Solr,我在优化下面的psedo代码时遇到问题,非常感谢您的帮助 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 在上面的代码中,在向索引添加新文档/术语时,我必须提交仅添加新文档的更改(我觉得成本很高),以便在下次打开new index searcher时看到新的更改 有什么办法可以提

我在优化下面的psedo代码时遇到问题,非常感谢您的帮助

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
在上面的代码中,在向索引添加新文档/术语时,我必须提交仅添加新文档的更改(我觉得成本很高),以便在下次打开new index searcher时看到新的更改

有什么办法可以提高性能吗。
仅供参考:我有3600万个术语需要编制索引。

您可以创建一个哈希集来消除内存中术语列表的重复,然后只为这些术语编制索引。伪代码如下所示:

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 set:=新哈希集 每学期 如果集合包含术语 跳到下一个迭代 其他的 将术语添加到集合中 结束 开放索引 对于集合中的每个术语 将术语添加到索引中 结束 封闭索引
我建议您只需创建第二个索引(在临时位置的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

谢谢你的快速回复。我提到的术语并不完全是指字符串。在搜索或将其添加到索引之前,我必须对每个术语进行大量的预处理。但在阅读了你的评论后,我明白了我可以在预处理后将它们编入新索引,并从新索引中提取唯一的术语,以便我进一步工作。再次感谢。