English 中文(简体)
Lucene.net: Separate building Index from Searching the Index
原标题:

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?

最佳回答

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)
问题回答

ahh, i think i ve got it ;-)

the first time i create a index i have to use

Dim directory As Directory = FSDirectory.GetDirectory("C:[...]luceneindex", True)
Dim indexwriter As IndexWriter = New IndexWriter("C:[...]luceneindex", analyzer, True)

and after indexing i have to use both with "False".

True everytimes creates an index? thanks =)





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签