简体   繁体   English

对于将 Lucene.NET 集成到 ASP.NET MVC 应用程序中是否有任何建议?

[英]Are there any recommendations for integrating Lucene.NET into an ASP.NET MVC application?

I'm wondering if there are any recommendations, best practises or top-tips for integrating a Lucene.NET based search into an ASP.NET MVC web application?我想知道对于将基于 Lucene.NET 的搜索集成到 ASP.NET MVC web 应用程序中是否有任何建议、最佳实践或重要提示?

Things I've read (or think I've read) in various places include the following:我在各个地方读过(或认为我读过)的内容包括以下内容:

  • One IndexWriter , many IndexReader s一个IndexWriter ,多个IndexReader
  • When the index is updated, reset/ re-initialise the IndexReader s更新索引时,重置/重新初始化IndexReader s

Are there any other useful tips or resources I should read before starting?在开始之前我应该阅读任何其他有用的提示或资源吗?

Thanks,谢谢,
Kieron基龙

Here are my tips (in no particular order):以下是我的建议(排名不分先后):

  • Choose the most appropriate locking mechanism.选择最合适的锁定机制。
  • Use the SetRAMBufferSizeMB to reduce the disk I/O overhead when writing the index.使用 SetRAMBufferSizeMB 来减少写入索引时的磁盘 I/O 开销。
  • Don't over use the SetMaxBufferedDocs property.不要过度使用 SetMaxBufferedDocs 属性。
  • Use the Search hits (TopDocs and ScoreDoc[]) object to retrieve the index search results.使用搜索命中(TopDocs 和 ScoreDoc[])object 检索索引搜索结果。
  • Index writing is an expensive operation, so use it sparingly.索引写入是一项昂贵的操作,因此请谨慎使用。
  • Know the data that you will be indexing as some data types (IE, dates) can be difficult to search on if they are not stored consistently.了解您将要编制索引的数据,因为如果存储不一致,某些数据类型(IE、日期)可能难以搜索。

A few gotchas from one of my previous projects were:我之前的一个项目中的一些问题是:

  • I had to use the BooleanQuery to do a traditional AND operation for searching multiple fields.我必须使用 BooleanQuery 来执行传统的 AND 操作来搜索多个字段。
  • There is no UPDATE functionality within Lucene so a document needs to be deleted and re-added. Lucene 中没有更新功能,因此需要删除并重新添加文档。
  • You can't sort / OrderBy on a tokenized field.您不能对标记化字段进行排序 / OrderBy。

I would suggest looking at the source code for RavenDb as it is built on top of Lucene and uses a number of best practices.我建议查看 RavenDb 的源代码,因为它构建在 Lucene 之上并使用了许多最佳实践。

RavenDb is definitely the easiest way to go here -- it really is lucene++. RavenDb 绝对是 go 最简单的方法——它真的是 lucene++。

In terms of how to use it, I'd recommend looking at the SubText blogging engine.至于如何使用它,我建议看一下 SubText 博客引擎。 Code is MIT licensed so you can just use it in your project and it has a very well designed index writer/reader.代码是 MIT 许可的,所以你可以在你的项目中使用它,它有一个设计良好的索引编写器/阅读器。

In our apps, we tend to have one writer and a separate app with many readers.在我们的应用程序中,我们倾向于有一个作家和一个拥有许多读者的独立应用程序。 The locking strategy can be key here--especially make sure the readers don't try and lock the index.锁定策略在这里可能很关键——尤其是确保读者不要尝试锁定索引。 I'm blanking on the specific term we had to use to make this happen.我对我们必须用来实现这一点的特定术语表示空白。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM