I'm not aware of an ootb solution. What you could do is create a custom search token that handles the logic you need. You can add that token to the search scope that you use for the search components.
More info: https://ggullentops.blogspot.com/2019/01/extending-sxa-search-query-tokens.html
You need to create a ResolveSearchQueryTokensProcessor
. Override the public override void Process(ResolveSearchQueryTokensEventArgs args)
method:
First you need to search your token (loop over all SearchStringModel
s in args.Model
)
Each SearchStringModel defines a part of the query and has a value, a type and an operation:
- the type of the SearchStringModel is the first part
- the value of the model is the second part (e.g. "ItemsWithTheSameValueInField|FieldName")
- the operation is "must", "should" or "not"
Once you found the model, you need to create a new one that can be send to the index and remove the one you handled. Building the search model is something like:
protected virtual SearchStringModel BuildModel(string fieldName, string fieldValue)
{
var name = SomeBusinessLogicWithFieldName(fieldName);
var value = SomeBusinessLogicWithFieldValue(fieldValue);
return new SearchStringModel("custom", FormattableString.Invariant(FormattableStringFactory.Create("{0}|{1}", name, value)))
{
Operation = "must"
};
}
Add your processor the the <resolveSearchQueryTokens>
pipeline and it should appear as option in the search tokens so you can add it to the scope.
In your case you'll need to add the location logic (or any other logic you want) to the BuildModel. That function is custom, so you can also arrange the parameters as you want. You just need to be able to pass everything from the Process method.