Monday 25 November 2019

Azure Search - Improving speed while getting facets only

If you want to get only facets from your search query - for some purposes as preparing filters list - remember to set limit to 0.

For example like this:

var facetResults = searchQuery.Take(0).GetFacets();

.Take(0) translates to $top=0 in Azure Search query. That will return something like this:

{
    "@odata.context": "https://{YOUR-SEARCH-SERVICE}.search.windows.net/indexes('my-index-web-index-99')/$metadata#docs(*)",
    "@odata.count": 857,
    "@search.facets": {
        "contenttype_facet_1": [
            {
                "count": 146,
                "value": "Content Type 1"
            },
            {
                "count": 134,
                "value": "Content Type 2"
            },
            {
                "count": 118,
                "value": "Content Type 3"
            },
        ],
        "topic_facet_1": [
            {
                "count": 176,
                "value": "Topic 1"
            },
            {
                "count": 70,
                "value": "Topic 2"
            },
            {
                "count": 62,
                "value": "Topic 3"
            },
            {
                "count": 52,
                "value": "Topic 4"
            }
        ],
        "subtopic_facet_1": [
            {
                "count": 49,
                "value": "Subtopic 1"
            },
            {
                "count": 32,
                "value": "Subtopic 2"
            }
        ]
    },
    "value": []
}

So only essential statistics data without actual results

Friday 1 November 2019

RenderField processor for tooltip links

A couple of days ago I've got a requirement from my client about inline tooltips functionality. Those tooltips needed to have formatted text so RTE field should be used.


I started with creating repository folder for those tooltips




Template for tooltip item was really simple, just one RTE field



To have a link which will open a tooltip I had to write a pipeline processor which
  • Will read RTE field content
  • Find internal links
  • Check if they point to tooltip item
    • If yes then process link



This pipeline processor must be run after field value is read, so after
Sitecore.Pipelines.RenderField.GetFieldValue, Sitecore.Kernel