[英]Lucene.net with IndexSearcher/IndexWriter in a Web Application
[英]Lucene IndexSearcher causing OutOfMemoryException
这是我搜索Lucene索引的代码,
String DocPath=@"c:\Test1.txt";
if (File.Exists(DocPath))
{
StreamReader Reader = new StreamReader(DocPath);
StringBuilder Content = new StringBuilder();
Content.Append(Reader.ReadToEnd());
if (Content.ToString().Trim() != "")
{
FSDirectory Direc = FSDirectory.Open(new DirectoryInfo(IndexDir));
IndexReader Reader = IndexReader.Open(Direc, true);
IndexSearcher searcher = new IndexSearcher(Reader);
QueryParser parser = new QueryParser(Lucene.Net.Util.Version.LUCENE_30, "Content", new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29, new FileInfo(Application.StartupPath + Path.DirectorySeparatorChar + "noise.dat")));
BooleanQuery.MaxClauseCount = Convert.ToInt32(Content.ToString().Length);
Query query = parser.Parse(QueryParser.Escape(Content.ToString().ToLower()));
TopDocs docs = searcher.Search(query, Reader.maxDoc);
}
}
在这段代码中,我打开一个15MB的文本文件并将其提供给索引搜索器。 搜索需要很长时间,显然会抛出OutOfMemoryException
。 它甚至需要时间来解析查询。 索引大小约为16K docs。
我建议你改变你的方法。 使用该文档,存储包含文件哈希的附加字段,例如MD5哈希。
使用您的输入计算它的哈希并为该哈希发出查询,并将匹配的文档与您的输入进行比较以获得相等性。
它将更加强大,并且可能性能更高。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.