1

I am using the multi-list with search field in my project. I have many items to render within (approx 400), so it's not possible for the users to scroll through and choose a specific one. There is one item named "Gracy-Timoth" when I type in the search box "gra" it's not giving me the "gracy-timoth" in fact it's showing all empty, but when I pass the complete name "gracy", it gives me the result. I want to get result on typing the partial words such as "gra" for "gracy-timoth".

I am using the below query as Datasource for multi-list with search.

StartSearchLocation={00000000-0000-0000-0000-000000000000}&TemplateFilter={00000000-0000-0000-0000-000000000000}

here I am passing the correct guid accordingly. Any suggestion on this issue? Thanks in advance.

2 Answers 2

0

Welcome to Sitecore Stack Exchange. I think by default sitecore is doing an exact search of the text entered in the search box (for example test1), if you take a look in the saerch log it will have a query like this:

?q=((((-_group:(66a1aed3af694bcab42171c1e6331a98)  *:*) AND (((_content:(test1) OR _name:(test1) OR _displayname:(test1)) AND _path:(110d559fdea542ea9c1c8a5df7e70ef9)) AND _latestversion:(True))) AND _datasource:(sitecore)) AND _latestversion:(1))&start=0&rows=20&fl=*,score&fq=_indexname:(sitecore_master_index)&wt=xml

Unfortunately there is no OOTB way to change the search query unless specifying * in the search box like tes*. One option would be to try to append this * to the text from javascript when sitecore makes the search call, the field is using the js file /sitecore/shell/Controls/BucketList/BucketList.js, you can take a look at the event $('filterBox' + self.clientId).observe('keyup', function () {.

If you want to change the query from code you would need to change the existing implementation. When performing a search you will see that it is calling /sitecore/shell/Applications/Buckets/Services/Search.ashx, which is built in the Sitecore.Buckets.Client dll in the namespace ItemBuckets.Services.Search.

namespace ItemBuckets.Services
{
  /// <summary>Search End Point</summary>
  public class Search : SearchHttpTaskAsyncHandler, IRequiresSessionState
  {

This class inherits from the SearchHttpTaskAsyncHandler which has a method that extracts the query from the parameters:

public void ExtractSearchQuery(NameValueCollection parameters)
{
   case "fromBucketListField":
      if (parameters[index] != "*")
      {
         this.searchQuery.Add(new SearchStringModel()
         {
            Type = "text",
            Value = parameters[index],
            Operation = "must"
          });
          continue;
       }

You would need to built your own implementation of Search.ashx and you can override the path specified in the field code source in Sitecore.Buckets.FieldTypes.BucketList:

public class BucketList : SearchList
{
   protected override string ScriptParameters => string.Format("'{0}'", (object) string.Join("', '", (object) this.ID,     
    (object) this.ClientID, (object) this.PageNumber, (object) "/sitecore/shell/Applications/Buckets/Services/Search.ashx"

You can take a look at an example of a custom implementation here http://sitecoreexperiences.blogspot.com/2015/08/serving-non-sitecore-data-in-sitecore_51.html

0

You can search for part of the words in the searchbox by using the * character. For example in your case it would be gra*.

2
  • but I want it to be dynamic like I am not passing any static keyword in the query. it's taking from the search box. So it would be great if somehow I can get the value of that search box then I can use the below query StartSearchLocation={00000000-0000-0000-0000-000000000000}&TemplateFilter={00000000-0000-0000-0000-000000000000}&Filter=Display name:*value from searchbox* May 25, 2021 at 15:52
  • 1
    @GauravSoni you can just use the gra* in the searchbox. You don’t need to hardcode this. May 25, 2021 at 20:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.