I'm currently running Lucene.net in a web application and am wondering about the best method, performance-wise.
我目前正在一个Web应用程序中运行Lucene.net,我想知道最好的方法,性能方面。
I currently have it set up so that all index writes get processed together in a scheduled process, along with optimizing the index.
我目前已将其设置为使所有索引写入在计划过程中一起处理,同时优化索引。
However for searching - I'm currently opening and closing the searcher per search, which I know isn't ideal.
但是对于搜索 - 我目前正在按搜索打开和关闭搜索器,我知道这并不理想。
What do you think would be the best approach in this situation?
在这种情况下,您认为最佳方法是什么?
I'll need to close and reopen the index searcher once the updates/optimization is processed so the scheduled process (which is a windows console app) needs to communicate it's finished to the web application.
一旦处理了更新/优化,我就需要关闭并重新打开索引搜索器,这样预定的进程(这是一个Windows控制台应用程序)需要将它完成传递给Web应用程序。
2 个解决方案
#1
5
I just integrated Lucene.NET into BugTracker.NET. I'm not sure that what I did is the best, but it seems to be working well.
我刚刚将Lucene.NET集成到BugTracker.NET中。我不确定我所做的是最好的,但它似乎运作良好。
I create the index at app startup.
我在app启动时创建索引。
I create a searcher and keep it around so that the index isn't reloaded with each search. All threads share the same searcher. When the searcher searches, it grabs a lock.
我创建了一个搜索器并保留它,以便每次搜索都不会重新加载索引。所有线程共享同一个搜索者。当搜索者搜索时,它会抓住锁。
Meanwhile, I have an IndexWriter that updates the index when there is a data change. It is just changing a little bit so it does its task quick. When it runs, it grabs the same lock, destroys the searcher, updates the index, and the re-recreates the searcher. The new searcher stays around until the next update of the index. The searcher always is working with an up-to-date index.
同时,我有一个IndexWriter,可以在数据发生变化时更新索引。它只是改变了一点,所以它快速完成任务。当它运行时,它会抓取相同的锁,销毁搜索器,更新索引,然后重新创建搜索器。新的搜索者会一直待到下一次更新索引。搜索者总是使用最新的索引。
You can get the BugTracker.NET source and look at the files my_lucene.cs and search_text.aspx. It's all in those two files, and there isn't that much code.
您可以获取BugTracker.NET源并查看文件my_lucene.cs和search_text.aspx。这些都在这两个文件中,并没有那么多代码。
#2
0
You could call to the readers IsCurrent() method to check if there is a new version of the index available, and if it's then reopen it. Couldn't be the best way, but is easy enough and if your requirements are not very big it will be sufficient.
您可以调用读者IsCurrent()方法来检查是否有可用的索引的新版本,如果它然后重新打开它。不是最好的方法,但很容易,如果你的要求不是很大,那就足够了。
#1
5
I just integrated Lucene.NET into BugTracker.NET. I'm not sure that what I did is the best, but it seems to be working well.
我刚刚将Lucene.NET集成到BugTracker.NET中。我不确定我所做的是最好的,但它似乎运作良好。
I create the index at app startup.
我在app启动时创建索引。
I create a searcher and keep it around so that the index isn't reloaded with each search. All threads share the same searcher. When the searcher searches, it grabs a lock.
我创建了一个搜索器并保留它,以便每次搜索都不会重新加载索引。所有线程共享同一个搜索者。当搜索者搜索时,它会抓住锁。
Meanwhile, I have an IndexWriter that updates the index when there is a data change. It is just changing a little bit so it does its task quick. When it runs, it grabs the same lock, destroys the searcher, updates the index, and the re-recreates the searcher. The new searcher stays around until the next update of the index. The searcher always is working with an up-to-date index.
同时,我有一个IndexWriter,可以在数据发生变化时更新索引。它只是改变了一点,所以它快速完成任务。当它运行时,它会抓取相同的锁,销毁搜索器,更新索引,然后重新创建搜索器。新的搜索者会一直待到下一次更新索引。搜索者总是使用最新的索引。
You can get the BugTracker.NET source and look at the files my_lucene.cs and search_text.aspx. It's all in those two files, and there isn't that much code.
您可以获取BugTracker.NET源并查看文件my_lucene.cs和search_text.aspx。这些都在这两个文件中,并没有那么多代码。
#2
0
You could call to the readers IsCurrent() method to check if there is a new version of the index available, and if it's then reopen it. Couldn't be the best way, but is easy enough and if your requirements are not very big it will be sufficient.
您可以调用读者IsCurrent()方法来检查是否有可用的索引的新版本,如果它然后重新打开它。不是最好的方法,但很容易,如果你的要求不是很大,那就足够了。