Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

Things I've read (or think I've read) in various places include the following:

  • One IndexWriter, many IndexReaders
  • When the index is updated, reset/ re-initialise the IndexReaders

Are there any other useful tips or resources I should read before starting?

Thanks,
Kieron

like image 903
Kieron Avatar asked May 23 '11 17:05

Kieron


People also ask

What version of Lucene is used in Java?

While it is about the Java version, Lucene.NET is an almost exact port to C#, so it is easy to use the concepts in you code. Just a warning, Lucene.NET 4.8 is .NET Standard 2.0 and can be easily used in a .NET Core application, but the API is different from the 3.0.3 version, which is not .NET Standard, only .NET Framework 4.6.

What is Lucene net?

Lucene.net is a .net port of Lucene, an open source full text search engine written in java. Lucene.net when incorporated into .Net applications provides full text search functionality. And also, Lucene.Net can be used to index entity framework objects to facilitate easy searching, thanks to LINQ to Lucene project.

How to use MVC and web API in the same project?

Use different ASP.NET frameworks like MVC and Web API in the same project Take advantage of the ASP.NET Scaffolding framework to automatically create Controllers and Views to perform CRUD operations based on your model classes Expose the same set of information in machine- and human-readable formats using the right tool for each job

What is core ASP NET NET?

ASP.NET Core apps are lightweight and modular, with built-in support for dependency injection, enabling greater testability and maintainability. Combined with MVC, which supports building modern web APIs in addition to view-based apps, ASP.NET Core is a powerful framework with which to build enterprise web applications.


1 Answers

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.
  • Don't over use the SetMaxBufferedDocs property.
  • Use the Search hits (TopDocs and ScoreDoc[]) object to retrieve the index search results.
  • Index writing is an expensive operation, so use it sparingly.
  • Know the data that you will be indexing as some data types (I.E., dates) can be difficult to search on if they are not stored consistently.

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.
  • There is no UPDATE functionality within Lucene so a document needs to be deleted and re-added.
  • You can't sort / OrderBy on a tokenized field.

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.

like image 113
Kane Avatar answered Nov 13 '22 11:11

Kane