2

I want to fetch people with similar interests based on common taxonomy tags.

I am following the Sitecore documentation section "Add a query item that uses a token" mentioned here:

https://doc.sitecore.com/xp/en/developers/sxa/19/sitecore-experience-accelerator/walkthrough--using-a-query-to-render-items.html

I have written a query and am getting the expected result but I don't find any way to get the sorted result.

enter image description here

e.g. I want to fetch people result order by updated date. I have tried the sort option using sort:<field-name> | value but did not help.

Request your support to achieve the sorted result.

Thanks, Hari

2 Answers 2

0

Use order by clause in your query:

query:$home//*[contains(@@templateid,'{templateid}') and (contains(@@taxonomyfield,'{taxonomytag}'))] order by @@updated desc

1
  • Hi Biswajit, Thanks for your inputs. I just tried putting your suggested query like custom:query|$home//*[contains(@@templateid,'{342696b0-2b67-406f-8e49-c7acc7894741}')] order by @@__updated desc in the Sitecore but did not get any result. I want to use sxa:TaggedWithAtLeastOneTagFromCurrentPage|SxaTags in the query and get the result with sorting order. Commented Mar 26, 2023 at 7:47
0

To Sort the results by updated date, you will need to use sort:__updated in the query builder dialog box. Your query should look like below: Make sure you have Sitecore_sxa_master_index rebuilt successfully.

+location:{685C0CDE-E82D-44AB-A88E-7E6000F2A1FB};template:{41FD7D9F-DF8B-404F-8FB2-66BF8777D381};sort:__updated

enter image description here

3
  • Hi Raman, Thanks for your inputs. I have tried your suggestions but am getting error as _Object reference not set to an instance of object at @Html.RenderingVariants().RenderVariant(variantField, Model.Item, Model.RenderingWebEditingParams, Model) in file ~\Views\Variants\Page Content.cshtml _ I think in normal case as you suggested sorting works but if I am using sxa:TaggedWithAtLeastOneTagFromCurrentPage|SxaTags along with sort in build query then it does not bring any result . What could I try pls? Commented Mar 26, 2023 at 7:33
  • I am able to get the sorted result with usage of solr index field __smallupdateddate_tdt then the Query looks like +template:{342696b0-2b67-406f-8e49-c7acc7894741};+sxa:TaggedWithAtLeastOneTagFromCurrentPage|SxaTags;sort:__smallupdateddate_tdt[desc] Sitecore __updated field is stored in the solr index as __smallupdateddate_tdt field Commented Mar 27, 2023 at 7:13
  • thanks @HariWaghamare. I just checked i was getting results with sxa:TaggedWithAtLeastOneTagFromCurrentPage|SxaTags as well. Glad that you are able to resolve with __smallupdateddate_tdt Commented Mar 27, 2023 at 7:15

Your Answer

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

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