TransWikia.com

Insert two values in SXA custom search query token (ResolveSearchQueryTokensProcessor)

Sitecore Asked by PSS on November 30, 2020

I am working with a custom SXA search query token. I want to Insert with two different values.

foreach (var val in values)
  {
     args.Models.Insert(i, this.BuildModel(itemFieldName, val));
  }
args.Models.Remove(model);

SearchStringModel:

protected virtual SearchStringModel BuildModel(string fieldName, string value)
{
  var name = fieldName;
  return new SearchStringModel("custom", FormattableString.Invariant(FormattableStringFactory.Create("{0}|{1}", name, value)))
  {
    Operation = "must"
  };
}

But this logic is not showing search results. Is there any way to achieve this functionality?

One Answer

The AND or OR operators in between the parts of your query are placed based on the Operation as set in the SearchStringModel.

In your case, the Operation is set to "must" - which is an AND. If you want an OR, you can use "should" here:

protected virtual SearchStringModel BuildModel(string fieldName, string value)
{
  var name = fieldName;
  return new SearchStringModel("custom", FormattableString.Invariant(FormattableStringFactory.Create("{0}|{1}", name, value)))
  {
    Operation = "should"
  };
}

Answered by Gatogordo on November 30, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP