I want to change SXA search box algorithm to support exact matching, when I search with a work like "National Day", it returns results that contains "National" or "Day" or "National Day", I want it to returns results that contains "National Day" as a whole only.
This is not possible out of the box, although we've been discussing this today and there is a chance we will change it in future releases.
If you want to change it on your own you need to implement your own SearchService. It might sound scary but in fact, you just need to inherit from SXA SearchService
and override ContentPredicate()
method. Take a look at original implementation, you will notice that we are using there Contains
LINQ method which is comparing search query with AggregatedContent field. Probably you just need to replace Contains
with Equals
.
After this just replace SXA implementation of ISearchService with your one in the DI container.
-
-
Hi Dawid, as you mentioned there might be chance that we may get out of the box feature like exact match search. Just checking if this is still in discussion or we have something like this in new version? – ironman Feb 10 at 16:57
-
@ironman
ContentPredicate
method has been slightly updated. Because of some low level problems with search provider we are using both methods -Contains()
andEqual()
- like this:predicate.And(i => i.AggregatedContent.Contains(t) || i.AggregatedContent.Equals(t, StringComparison.InvariantCultureIgnoreCase))
. But this was more like a bug fix rather then implementing properly design feature. Search features unfortunate still needs to wait... – Dawid Rutkowski Feb 11 at 14:36