Wednesday, 6 September 2017

Sitecore SXA search components


After discussing about various Sitecore SXA capabilities before, today I am writing something about the search components which comes as part of SXA base installation. (version 1.3)

Search comes with many out of the box components which can talk to each other:

I will show you how to use some of the above to create search for our site.
 Below are the steps which enable search with a simple text box and search button:
 

-          Enable Search configuration. All the components support Lucene and Solr, so it’s up to us what to use.
Go to “~\Website\App_Config\Include\z.Foundation.Overrides” folder and enable desired search config. Here I have used lucene so renamed and enabled: “Sitecore.XA.Foundation.Search.Lucene.config”

-          Once the config is enabled, we may need to rebuild the “sitecore_master_index”
-          Now simply go to your page/partial design and drag drop 2 components:
o   Search Box
o   Search Results
 


That should get your search working with results showing like this:


There are various features like auto complete, selecting max predictive results count, choosing a different Search Result Page, selecting scope etc.
The Search results are returned as JSON with SXA 1.3 version onwards.
We can simply use this URL in the browser to test if the search is returning results:
also, we can pass on query string parameters to see the results like:


We can also define various properties for Search results like the scope, page size, sort order etc.
Here, the scope setting tells the search where to look for the items. If left blank, then the scope is considered to be full site and may give us more results than expected.
Here, is where we can set the scope of the search:
-          Go to item:
/sitecore/content/Tenant Folder/Tenant/Website/Settings/Scopes
-          Right click and add a Scope
-          Create a simple query to define the scope:
 



Here, the location: Item ID is the item under which you want to search. This can be home item or any parent folder item.
+custom: templatename: Blog: this is the place where we can define the template name of the items to pick in the search.
Here, I want all items under home folder with blog template.
Now, if we select the created scope in Search Results component properties and refresh the page, I will only get blog items:

We can filter the search by adding more (facets)components to the search page like: Filter drop downs.
We can create search result facets by going to item:
/sitecore/content/ Tenant Folder / Tenant / Website /Settings/Facets
And add a new facet item which will add filter to the search: 

Make sure a correct field name is entered in the “Field Name” field, which will be used to facet the results.
Here, in this example we have blogs talking about various properties so we want to filter the property search based on number of bedrooms.
After adding the facet, we now drag and drop the filter drop down on the search page:


And choose the “Bedrooms” facet from the list:

Save and run the search page.
We can see the facet drop down filter being populated with the number for bedrooms and there count in items:


And, our search result changes based on our selection:


In above image, the search box is hidden which can be done by checking a check box in Search box control properties:


That’s it for this blog post.

1 comment:

  1. Nice article, one remark though, you should not disable/enable config to configure your search provider (anymore). Instead you should just set the search:define app setting, see https://doc.sitecore.net/sitecore_experience_platform/setting_up_and_maintaining/search_and_indexing/indexing/configure_a_search_and_indexing_provider

    ReplyDelete