Wednesday, October 20, 2021

Sitecore sorting best practices and recommendation.

Sometimes applying a simple sorting based on title can create an issue, we need to be very careful about it.

Applying sorting based on title is not going to work, strange right?

Let's see this in detail.

The title is a text general field and the tokenizer will make tokens of the value so logically you can't do sorting on this field


In case if we want to do the sorting on the title field, It's recommended to create a copy field which will basically copy the data from the title and move into the target field and make sure that the target field is a string field so it will hold the string value and sorting can be done.

Example for the text or text general field 




With string field



Solution - How to add a copy field  - Reference - https://solr.apache.org/guide/6_6/copying-fields.html


<copyField source="cat" dest="text" maxChars="30000" />


Hope this will help to others.

Docker issue when you got an existing machine which configured for a diff account

 Recently, I got a chance to work on an important project as a firefighter for 4 weeks, I got the existing machine and my first issue was related to the docker, here is my learning and details for the fix.

Error -' You are not allowed to use Docker, you must be in the "docker-users" group


I got this error while running the docker, to fix this issue I follow this link 

basically, we need to add the user to the docker-user membership 


Now, after doing that, I got a diff error, which is as below


to fix that, please make sure you do the sign-out, the restart and disconnect option will not work.



I hope that will help others.

Wednesday, October 13, 2021

SXA Custom Token - Best practices to include the operation correctly.

 When implementing SXA custom token, it would be good to consider the options like must, should or not, this is already part of the SXA model, so basically we need to make sure to include the below conditions.

Pass the model operation name as a parameter -


 public override void Process(ResolveSearchQueryTokensEventArgs args)

        {

            if (args.ContextItem == null)

                return;

            for (int index = 0; index < args.Models.Count; ++index)

            {

                SearchStringModel model = args.Models[index];

                if (model.Type.Equals("sxa") && this.ContainsToken(model))

                {

                    string str = model.Value.Replace(this.TokenPart, string.Empty).TrimStart('|');

                    var fieldNames = str.Split('|').ToList();

                    if (fieldNames.Any() && fieldNames.Count == 2)

                    {

                        args.Models.Insert(index, this.BuildModel(fieldNames[0], fieldNames[1], model.Operation));

                        args.Models.Remove(model);

                    }

                }

            }

        }


  protected virtual SearchStringModel BuildModel(

            string replace,

            string fieldValue, string operation)

        {

            return new SearchStringModel("custom", FormattableString.Invariant(FormattableStringFactory.Create("{0}|{1}", replace.ToLowerInvariant(), fieldValue)))

            {

                Operation = operation

            };

        }

Model operation values - Just for the reference.



SXA boosting rule - Search Box Query

 As we know that Sitecore has provided a lot of rule-based boosting options, I found the below rule very useful in a recent implementation.





We can see the appropriate logs to see that boosting is applied correctly.

2021-10-13 22:34:12.460 INFO  (qtp23211803-22) [c:sitecore_sxa_dev_master_index s:shard1 r:core_node2 x:sitecore_sxa_dev_master_index_shard1_replica_n1] o.a.s.c.S.Request [sitecore_sxa_dev_master_index_shard1_replica_n1]  webapp=/solr path=/select params={q=((((((_template:(c03a48a03baf4ba09f10774f365841a4)+OR+_template:(911e99589fa64e85901eac0e0fc96009))+AND+((_path:(0513592509aa40188c47987bc6f9236a)+AND+searchable_b:(True))+OR+(_path:(e86fa7d2714741548e25c0bcdb9217fb)+AND+searchable_b:(True))+OR+(_path:(225d1bc67544492d8d752fdaa1a7151c)+AND+searchable_b:(True))+OR+(_path:(9377586f8345460b8dd01e24a451aeb6)+AND+searchable_b:(True))))+AND+sxacontent_txm:(lifestyle~0.5))+AND+_latestversion:(True))+AND+((content_t:(*lifestyle*))^5+OR+(-_name:("")++_name:[*+TO+*])))+AND+((title_t:(*lifestyle*))^5+OR+(-_name:("")++_name:[*+TO+*])))+AND+_val_:__boost&start=0&fq=_indexname:(sitecore_sxa_dev_master_index)&sort=title_t+asc&rows=5&wt=xml&version=2.2} hits=3 status=0 QTime=17