difference between LinqToLucene and Lucene.Net.Linq

六月ゝ 毕业季﹏ 提交于 2019-12-03 13:20:11

LINQ to Lucene appears to be inactive. The last commit at time of writing was in October 2012 and the last discussion post asking if the project is active has gone unanswered since the same time frame.

LINQ to Lucene has some tight coupling to Entity Framework so it seems to me the project is designed to index data coming from EF for free text search.

Lucene.Net.Linq is a completely separate project that I started in 2012 and have been actively maintaining. This project does not have any coupling to EF or other libraries. It only depends on Lucene.Net, Common.Logging for logging, and Remotion.Linq for helping with LINQ query parsing and translation. I originally evaluated the possibility of contributing to LINQ to Lucene, but found that the tight coupling to EF and some other assumptions made the library inappropriate for my needs.

LINQ to Lucene cons:

  1. Not available on NuGet
  2. Not actively maintained
  3. Very limited in what you can put into a where clause
  4. Coupled to EF whether you want it or not

Lucene.Net.Linq pros:

  1. Actively maintained
  2. Packages (and symbols!) published to NuGet
  3. Better comprehension of complex queries
  4. Fluent and Attribute APIs to map properties to fields and control analysis, storage and indexing

Lucene.Net.Linq cons:

  1. Documentation could be better
  2. Only a handful of contributions outside my own
  3. Unclear performance vs vanilla Lucene.Net (not much performance testing has been done)

The documentation, such that it is, consists of the project README and sample code in the unit test project.

Lucene.Net.Linq does not have extension methods for every query that Lucene.Net supports natively. However, it does provide an escape hatch where you can pass in your own Query:

var result = customers
            .Where(new TermRangeQuery("CompanyName", "A", "C", includeLower: true, includeUpper: true))
            .ToList();

And it supports searching any indexed field with fuzzy match:

var result = customers
            .Where(c => (c.AnyField() == "amber").Fuzzy(1.0f))
            .ToList();

And it supports simple matching with == and !=:

var result = customers
            .Where(c => c.CustomerId != "Jason")
            .ToList();

Note that the meaning of == is controlled by how a given field is indexed. If the field is indexed as a keyword, exact matching takes effect. If the field is tokenized, stemmed, converted to lowercase, etc, then == would match any term in the field.

Itay BenNer

With this code:

var directory = FSDirectory.Open(AppDomain.CurrentDomain.BaseDirectory + "/index/recipes");

using(var provider = new LuceneDataProvider(directory, Lucene.Net.Util.Version.LUCENE_30)) {
    using(var session = provider.OpenSession < CatalogItemDocument > ()) {}

}

you could work with file system and not system memory.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!