Shazwazza / Examine

A .NET indexing and search engine powered by Lucene.Net
https://shazwazza.github.io/Examine/
380 stars 123 forks source link

Adds new Fluent API Test to highlight issue between Fluent & NativeQuery #377

Closed warrenbuckley closed 1 month ago

warrenbuckley commented 9 months ago

Here you go @Shazwazza Here is a PR to support the issue/discussion/question asked in https://github.com/Shazwazza/Examine/issues/375

This is a fluent API test to highlight the issue between Fluent API not using the same exact query when you use it with NativeQuery()

warrenbuckley commented 9 months ago

Any thoughts on this at all @Shazwazza ?

Shazwazza commented 7 months ago

@warrenbuckley So there's a few things that aren't the 'same':

Firstly, in this test, neither of these queries returns any results :P

The fluent query results in:

{ Category: content, LuceneQuery: +__NodeTypeAlias:wviewlibrary +(+wWpPropLibraryAddress:"Scotland" +wWpPropLibraryAddress:"UK") }

The parsed native query results in:

{ Category: content, LuceneQuery: +(+__NodeTypeAlias:wviewlibrary +(+wWpPropLibraryAddress:scotland +wWpPropLibraryAddress:uk)) }

There's differences in both 'exact match' with quotes and also casing. The StandardAnalyzer will lowercase everything, that is how it works which is why the parsed Native query results in lower case.

You are using: locationPartsExamineValues.Add(new ExamineValue(Examineness.Escaped, part.Trim()));

This means that it will be an 'exact' match, or try to be, which results in the term being quoted (phrase match) and also in non-lowercase because you asked it to be exact.

If you change this to be "Explicit" instead of "Escaped" it will result in the same syntax, except the parsed native query will be bracketed.

Instead of using var locationPartsExamineValues = new List<IExamineValue>();, just use var locationPartsExamineValues = new List<string>(); and then pass in strings to GroupedAnd, this results in the ExamineValue used to be 'Explicit' which is the default.