As the other guys said, I would say I'm starting to use Lucene.NET
Lucene has a pretty high learning curve, but I found a wrapper for it called " SimpleLucene " that can be found on CodePlex
Let me give you a few code blocks from a blog to show you how easy it is to use. I just started using it, but got it very quickly.
First, get some entities from your repository or in your case use the Entity Framework
public class Repository { public IList<Product> Products { get { return new List<Product> { new Product { Id = 1, Name = "Football" }, new Product { Id = 2, Name = "Coffee Cup"}, new Product { Id = 3, Name = "Nike Trainers"}, new Product { Id = 4, Name = "Apple iPod Nano"}, new Product { Id = 5, Name = "Asus eeePC"}, }; } } }
The next thing you want to do is create an index definition
public class ProductIndexDefinition : IIndexDefinition<Product> { public Document Convert(Product p) { var document = new Document(); document.Add(new Field("id", p.Id.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); document.Add(new Field("name", p.Name, Field.Store.YES, Field.Index.ANALYZED)); return document; } public Term GetIndex(Product p) { return new Term("id", p.Id.ToString()); } }
and create a search index for it.
var writer = new DirectoryIndexWriter( new DirectoryInfo(@"c:\index"), true); var service = new IndexService(); service.IndexEntities(writer, Repository().Products, ProductIndexDefinition());
So now you have a search index. The only thing to do is ... search! You can do some pretty interesting things, but it can be that simple: (for more detailed examples, see the blog or documentation on codeplex)
var searcher = new DirectoryIndexSearcher( new DirectoryInfo(@"c:\index"), true); var query = new TermQuery(new Term("name", "Football")); var searchService = new SearchService(); Func<Document, ProductSearchResult> converter = (doc) => { return new ProductSearchResult { Id = int.Parse(doc.GetValues("id")[0]), Name = doc.GetValues("name")[0] }; }; IList<Product> results = searchService.SearchIndex(searcher, query, converter);