Latest Posts

Content Search Web Part (CSWP) in SharePoint

In this article, we are going to look into the details about how we can use the Content Search web part in the SharePoint page, what are the different configurations, where we can use this web part and much more.

Add Content search Web part on page

  • Create a web part page
  • Edit the page and click on Add a Web Part.
  • Select the Content Search web part from the Content Rollup category
  • Select Content Search web part
  • By default, three lastly updated resources will be displayed on the page.

Configure Content Search Web Part

  • Edit the web part
  • We will go through all the important settings one by one.
  • Change Query: To change the query go to Search Criteria and click on Change Query.

BASICS TAB

cswp basics tab
  • Select a query: Select the Result source from where the results should come. There are some options like, recently updated, Images, videos, Pages, Documents, Wiki, etc... You can explore by clicking on the drop-down and according to your requirement, you can select the option.
  • Restrict by app: From the dropdown options, you can select whether you want the results from the current site collection, current site or any specific URL.
  • Restrict by tag: You can only show the results which are tagged to a specific term. There are a couple of options that you can explore which are pretty self-explanatory.

Click on Switch to Advanced mode

cswp basics tab advanced mode
  • You can use the Advanced option if you want to create a query using KQL (Keyword Query language). You can also use Query variables in advanced mode.

REFINERS TAB

cswp refiners tab
  • You can further drill down your results. The refiners you see in the left panel are the Managed properties which are selected as refiners in the search schema.
  • If you want the only content which is tagged to one of these refiners/managed property then you can just select them in the left panel and click on ADD.
  • Click on Show more link

    cswp refiners tab show more
  • Group results: You can select a Managed property from the drop-down to present the results in grouped stat by that Managed property.

SORTING TAB

cswp sorting tab
  • Sort by: You can apply to sort on your results by selecting a managed property from the drop-down list. You can click on the Add sort level to add additional sorting.
  • Ranking Model: You can choose a model from the drop-down which will be used to decide to rank the results in the web part.
  • Dynamic ordering: On top of the Ranking Model, you can promote or demote the results based on custom rules/conditions as shown in the screenshot.

SETTINGS TAB

cswp settings tab
  • Query Rules: Select whether you want to include the Query rules from the site level or not.
  • URL Rewriting: If items in the search results are returning from the catalog, then you can specify whether you want to apply URL rewriting or not.
  • Priority: Select the priority of the results displayed by this web part against the other search web parts. So, when there’s a heavy load on the search service, the queries will be run according to the priority set over here.
  • Caching: You can enable caching so that the results will be stored for a specific group. This will decrease the load time of the page for the group users where search results web part is kept. Make sure the results are the same for all the users from the group.

TEST TAB

  • Query text: This is the final query text, based on all settings done in previous tabs.
cswp test tab

Click on Show more

cswp test tab show more
  • Query template: Query which was defined in the BASICS tab or in selected result source.
  • Refined by: Shows the refiners applied in the REFINERS tab.
  • Grouped by: Shows the managed properties that were Grouped by in REFINERS tab
  • Applied query rules: Shows all the query rules applied to this query.
  • Query template variables: Shows all the query variables applied to the query.
  • User segment terms: You can add user segment term for this query and check how this query will work by clicking on Test Query

Important Notes:

  • In Query, the OR operator increases the complexity to execute compared to AND operator.
  • Better to execute the query using the exact keyword instead of using the wildcard (*) character.
  • A keyword is better than keyword phrase in the search query
  • Try to avoid adding sorting levels and dynamic ordering from SORTING TAB. Check if you can leverage the OOB sorting and Ranking Model from the sorting tab.

Additional Content Search web part (CSWP) settings

additional cswp settings
  • Number of items to show: You can specify the total number of results you want to show in the web part. By default, you can see 3 latest items in the web part.
  • Display Templates – Control: From the dropdown list, you can select the display template that you want for the entire control.
  • Display Templates – Item: From the dropdown list, you can select the design that you want for each list item/row item.
  • Don't show anything when there are no results: You can keep it ticked only, otherwise, it will leave space when there are no results.
  • Property Mappings: You can pick the managed properties/fields which are there in the Item Display Template.

After completing all the settings, you can press ok and close the Editing for the page. Your settings will reflect on the page instantly.

Conclusion:

We went through all the properties available to set for the search results web part. You can explore the properties more and accordingly set the CSWP web part.


We value your Feedback:

Page URL:

Name:

Email:


Suggestion:

© 2024 Code SharePoint