Deepak Agarwal
Deepak Agarwal

Reputation: 468

Issue with using wildcards with lucene .net QueryParser

I have following code for Lucene .Net search:

enter image description here

If I use query like:

AccountId:1 AND CompanyId:1 AND CreatedOn:[636288660000000000 TO 636315443990000000] AND AuditProperties.FriendlyName.NewValue:CustomerId|235

It works fine with exact match with CustomerId = 235.

However, if I try to search for a wildcard match like for example:

AccountId:1 AND CompanyId:1 AND CreatedOn:[636288660000000000 TO 636315443990000000] AND AuditProperties.FriendlyName.NewValue:CustomerId|*235*

it doesn't fetch me any results. I think it is still going for an exact match with value "*235*" Am I missing anything here?

Thanks!

Upvotes: 0

Views: 593

Answers (1)

NightOwl888
NightOwl888

Reputation: 56849

As per the QueryParser syntax documentation, the character | is not supported. However, it is not very clear whether you intended it to be a logical OR or a literal character.

Logical OR

The correct syntax for logical OR is either CustomerId OR *235*, CustomerId *235* or CustomerId||*235*.

Also, if this is meant to be a logical OR, you have to allow for a leading wildcard character as pointed out in Howto perform a 'contains' search rather than 'starts with' using Lucene.Net.

parser.AllowLeadingWildcard = true;

Literal |

To search for a literal pipe character, you should escape the character so the parser doesn't confuse it with a logical OR.

CustomerId\|*235*

Upvotes: 1

Related Questions