Lucene.net:从搜索索引中分离建筑物指数(Lucene.net: Separate building Index from Searching the Index)

编程入门 行业动态 更新时间:2024-10-22 07:53:45
Lucene.net:从搜索索引中分离建筑物指数(Lucene.net: Separate building Index from Searching the Index)

我创建了一个网站,但我遇到了问题。 我想建立一个索引并使用它。

目前我有两个功能“创建一个文档存储到目录中”和“搜索”

当用户提交时:

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 sub

this works, but when i try this:

create_doc() sub submit() search(text) end sub

it'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 sub

Is 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)

更多推荐

本文发布于:2023-07-17 07:44:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1141144.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:建筑物   索引   指数   net   Lucene

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!