我在一个正常的方式创建索引:Lucene net IndexWriter在UpdateDocument之后即使进行优化也会使索引大小加倍?
var directory = FSDirectory.Open(...);
var analyzer = ...
var indexWriter = new IndexWriter(directory, analyzer, true, IndexWriter.MaxFieldLength.UNLIMITED);
indexWriter.SetWriteLockTimeout(30000);
indexWriter.AddDocument(doc1);
indexWriter.AddDocument(doc2);
indexWriter.AddDocument(...);
indexWriter.Commit();
indexWriter.Optimize();
indexWriter.Close();
这就形成了5.8MB
指数现在我需要更新2个文件exactly..with 1个字在他们每个人的加入。 ..所以索引的大小应该由一个非常小的量而增加或者或者根本没有:
var indexWriter = new IndexWriter(directory, analyzer, false, IndexWriter.MaxFieldLength.UNLIMITED);
indexWriter.SetWriteLockTimeout(30000);
indexWriter.UpdateDocument(doc1);
indexWriter.UpdateDocument(doc2);
indexWriter.Commit();
**indexWriter.Optimize();**
indexWriter.Close();
此操作双打指数的大小,它让_0.cfs文件大小的方式ind ex之前是5.8mb ...并且在_2.xxx文件中创建了一个相同大小的全新索引...所以对于一个单词更改的两个文档,它将其加倍!
如果我重复这个操作,它也会继续这样做...所以它只会永远加倍。
我的想法是,优化调用应该优化它,而不是导致这样的事情?
如何阻止我的指数翻倍?
Thnx!
Thnx,做到了!我在c#中使用声明来包装IndexSearcher,该声明处理索引后,不要让它挂起来,这就做到了! Btw。你知道将IndexSearcher缓存为performanse会更聪明吗? 此外,如果我确实缓存它,是否有办法在晚上强制杀死所有搜索者(例如,当几乎没有人使用搜索器Web应用程序时,我的索引每天晚上由单独的应用程序执行一次)? –
是的,你应该试图尽可能保持Searcher打开的时间,因为内部lucene缓存底层IndexReader中的信息,这有助于提高性能。我通常做的是有一个管理器来保存我的IndexSearcher实例,通常每个索引为1。当我即将关闭我的IndexWriter时,我首先使用管理器关闭IndexSearchers,然后关闭IndexWriter。 –
我已经完成了我的索引优化。它的规模从370增加到826 GB,但文件现在只针对一个细分市场,并且在尝试了您的建议后尺寸不会缩小。你可以给我更多的建议吗?谢谢。 –