1

In my SP site documents or list items are getting tagged with some taxonomy value.

I have a SP Page, where I have added Content search web part and the result shows in search results web part on page load.

Now what I want is when I click on one of the taxonomy value from the taxonomy based top navigation, the search results web part should show results based on respected taxonomy value.

So, how can I dynamically change the CSWP query based on top navigation click?

Thanks in advance.

0

I once had similar requirement, so I actually used Search result webpart, but you can check below code for Content Search webpart as well. Code is somewhat different for Content Search webpart, which you can check by this good article.

I had one site drop-down, list drop-down, keyword text-box and next to that search button which will search the result dynamically.

Below is the jquery code for on change event for site drop-down on content search that you can use:

  // Attach change event handler to Site dropdown
  $('#drpSites').change(function () {
        // Get selected product ID
        var sites = $(this).val();

        // Loop through Query Groups
        var groups = Srch.ScriptApplicationManager.get_current().queryGroups;

        $.each(groups, function () {
          // Look for query groups associated with a CSWP
          if (this.displays != null && this.displays.length > 0) {
            if (this.displays[0] instanceof Srch.ContentBySearch) {
              // Update and execute query
              var newQuery = 'contentType:Orders sites:' + prd;

              this.dataProvider.set_queryTemplate(newQuery);
              this.dataProvider.issueQuery();
            }
          }
        });
  });

So for your termset you can enter your query in newQuery variable to fetch data accordingly.

Hope this helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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