我创建了一个网站,但我遇到了问题。 我想建立一个索引并使用它。
目前我有两个功能“创建一个文档存储到目录中”和“搜索”
当用户提交时:
sub submit () create_doc() search(text) end sub这工作,但当我尝试这个:
create_doc() sub submit() search(text) end sub就像目录已被删除。
global: Dim analyzer As StandardAnalyzer = New StandardAnalyzer()Dim directory As Directory = FSDirectory.GetDirectory("C:\[...]luceneindex", True) Dim indexwriter As IndexWriter = New IndexWriter(directory, analyzer, True) Sub create_doc() Dim meindoc As New Document() im feldbodytext As Field = New Field("bodytext", textstring[...] meindoc.Add(feldbodytext) indexwriter.AddDocument(meindoc) indexwriter.Close() end sub Sub lucene_search(ByVal strSuchbegriff As String) Dim parser As QueryParser = New QueryParser("bodytext", analyzer) Dim query As Query = parser.Parse(strSuchbegriff) Dim hits As Hits = searcher.Search(query) [...] end sub是否有可能永久存储索引? 可能会出现问题。 索引作家gloabel,但关闭它本地?
I created a website but i have a problem. i want to build once an index und use it.
at the moment i have two functions "create a document an store it into the directory" and "searching"
when the user submit:
sub submit () create_doc() search(text) end subthis works, but when i try this:
create_doc() sub submit() search(text) end subit's like the directory has been deleted.
global: Dim analyzer As StandardAnalyzer = New StandardAnalyzer()Dim directory As Directory = FSDirectory.GetDirectory("C:\[...]luceneindex", True) Dim indexwriter As IndexWriter = New IndexWriter(directory, analyzer, True) Sub create_doc() Dim meindoc As New Document() im feldbodytext As Field = New Field("bodytext", textstring[...] meindoc.Add(feldbodytext) indexwriter.AddDocument(meindoc) indexwriter.Close() end sub Sub lucene_search(ByVal strSuchbegriff As String) Dim parser As QueryParser = New QueryParser("bodytext", analyzer) Dim query As Query = parser.Parse(strSuchbegriff) Dim hits As Hits = searcher.Search(query) [...] end subIs there a possibility to store the index permanently? could there be a problem init. the index writer gloabel, but close it local?
最满意答案
我认为你的问题是每次声明你的IndexWriter ,都会重新创建索引并删除索引的内容 - 这是因为第3个参数被传递给构造函数( True ):
Dim indexwriter As IndexWriter = New IndexWriter(directory, analyzer, True)您应该使用False来指示索引的现有内容应保持不变:
Dim indexwriter As IndexWriter = New IndexWriter(directory, analyzer, False)I think your problem is that each time you declare your IndexWriter, the index is being re-created and the contents of the index erased - this is because of the 3rd parameter being passed into the constructor (True):
Dim indexwriter As IndexWriter = New IndexWriter(directory, analyzer, True)You should instead use False, to indicate that the existing contents of the index should remain unchanged:
Dim indexwriter As IndexWriter = New IndexWriter(directory, analyzer, False)更多推荐
发布评论