AnswerBun.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!

Related Questions

Using WFFM 9.0 rev. 180503 with Sitecore 9.1

1  Asked on August 23, 2021 by david-masters

   

Can not install Sitecore.CLI for Sitecore 10

1  Asked on February 21, 2021 by nikola-kramaric

   

How to become a Sitecore MVP?

3  Asked on February 10, 2021 by tamas-varga-sitecore

   

Azure Deploy of CM + Reporting

2  Asked on February 6, 2021 by dave-g

     

Get Sitecore From submission attempts

1  Asked on January 12, 2021 by mohamed-yaseen

     

Ask a Question

Get help from others!

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