chriseldredge / Lucene.Net.Linq

LINQ provider to run native queries on a Lucene.Net index
Other
151 stars 66 forks source link

Wildcard, Prefix and Fuzzy queries return no results #83

Closed rowandh closed 8 years ago

rowandh commented 9 years ago

Several type of Lucene queries are parsed incorrectly by FieldMappingQueryParser:

To reproduce:

This is due to the search field only being overridden with DefaultSearchProperty on certain QueryParser overrides:

but not:

Solution: We could override these methods and use them to remap the default search field. But this beholds us to any changes in the internals of QueryParser.

The correct solution is to inject the default search field to FieldMappingQueryParser's constructor rather than set it as a property.

Then we can add an override CreateQueryParser(string defaultField) to LuceneDataProvider, and remove the DefaultSearchProperty property from FieldMappingQueryParser.

I don't see any advantage to using a property to set this field - if a user wants to dynamically change the default search field for some reason, they can just use the factory method to create a new query parser.

However, this fix breaks backwards compatibility for anyone who is already using DefaultSearchProperty (although many of their queries will already be returning no results).

There is an interim solution:

I'm not sure how keen you are to introduce a change that breaks backwards compatibility, so I'll submit a PR shortly with my interim solution and tests.

rowandh commented 9 years ago

Missed some test cases in my initial PR. Somehow skipped over the fact that this affects all queries and not just queries where DefaultSearchProperty is set. I'll create another one.

chriseldredge commented 9 years ago

Merged to master.

chriseldredge commented 8 years ago

This was released in 3.6.0 today on nuget.org.