Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escaped value returns no results when it should #325

Closed
dealloc opened this issue Jan 8, 2023 · 2 comments
Closed

Escaped value returns no results when it should #325

dealloc opened this issue Jan 8, 2023 · 2 comments

Comments

@dealloc
Copy link

dealloc commented Jan 8, 2023

I'm dynamically building a query from parameters using the following function:

private IBooleanOperation BuildFacetFromList(IQuery query, List<string> facets, string field)
{
	if (facets.Count == 1)
		return query.Field(field, facets.First().Escape());

	return query.Group(group =>
	{
		var operation = group.Field(field, facets.First().Escape());
		return facets
			.Skip(1)
			.Aggregate(operation, (current, facet)
				=> current.Or().Field(field, facet.Escape())
			);
	});
}

When I run this code it results in a query something like this: +Language:fr +ContractType:"Intérimaire option contrat fixe"
image
However, running this query using Examine gives me this:
image
Whereas there's definitely results in the index that should match this query, which can be demonstrated by running the stringified query in the interface:
image
or even feeding it to the NativeQuery method:
image

I'm using Escape since (as seen in the screenshots) some parameters are multiple words but should be treated as a single term (otherwise irrelevant results are shown as well.

The field is indexed as FieldDefinitionTypes.FullText and has new StandardAnalyzer(LuceneVersion.LUCENE_48) as it's analyzer.

Currently my workaround is to take the string version and feed it to the parser again, but that feels like a hacky workaround I'd very much like to get rid of.

@mistyn8
Copy link

mistyn8 commented Aug 2, 2023

Having hit the issue myself and trying to create a failing test, NativeQuery doesn't leave your string input alone as you might think.
If you take a look at the raw query that NativeQuery generates I think you'll find that it's lowercased.. whereas Escape() will leave it upper case.
(lower casing being key for the phrase to match against the index??)

I noticed when writing out the generated queries to the test console..
#329 (comment)

@Shazwazza
Copy link
Owner

Escape() has a particular nuance, it is meant to be an exact match, not specifically a phrase, however, here's a proposed change #329 (comment)

I will close this and continue the discussion there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants