Exclude an article from user search, exclude category/section from tiles

Answered

4 Comments

  • Karen D Snyder

    I also couldn't find an ideal solution to this. I am using jquery, but removing rather than hiding, so the remove function is used only once to remove the unwanted elements. The jquery solution is not ideal because it works for one page of search results, but if the search results go over one page, the pagination is messed up and the total number of results at the top of the page is not always correct. I could not find any way to fix that. 

    In case it's helpful to somebody, below is the code that removes articles with 'Forms' in the title from the search results. (We need to hide articles with 'Forms' in the title, because those articles contain HTML to display icons that users click to open forms. When those articles appeared in the search results, they looked very strange when opened, as they are code and not text.)

    var formsResults = $('.search-results-list .search-result a.search-result-link:contains("Forms")');
     if (formsResults.length) {
      formsResults.parent().remove(); // remove the elements where articles have 'Forms' in title

      // Adjust the number of results in search results heading
      var numResults = $('.search-results-list .search-result').length;
      var searchResultsHeading = $('.search-results-heading').text();
      var partialHeading = searchResultsHeading.substring(searchResultsHeading.indexOf('for'));
      $('.search-results-heading').text((numResults > 0 ? numResults : 'No') + ' ' + (numResults !== 1 ? 'results' : 'result') + ' ' + partialHeading);

      // Add 'no results' element for knowledge base or community if needed
      adjustSearchResultElement('Knowledge base', 'No results ' + partialHeading, '/hc/en-us', 'Browse knowledge base', 'home');
      adjustSearchResultElement('Community', 'No results ' + partialHeading, '/hc/en-us/community/topics', 'Browse Community');
      }

      // If search result list exists and contains no results, add 'no result' element
      function adjustSearchResultElement(searchResultType, elementText, browseLink, browseText, browseTitle) {
        var subHeadingSelector = '.search-results-subheading:contains("' + searchResultType + '")';
        var searchResultListSelector = subHeadingSelector + ' + .search-results-list';
        var searchResultSelector = subHeadingSelector + ' + .search-results-list .search-result';
        if ($(searchResultListSelector).length && $(searchResultSelector).length == 0) {
          var elementTitle = browseTitle ? 'title="' + browseTitle + '"' : '';
          var htmlToAppend = '<p>' + elementText + '. <a ' + elementTitle + ' href="' + browseLink + '">' + browseText + '</a></p>';
          $(subHeadingSelector).after(htmlToAppend);
        }
    }

    0
  • Brett Bowser
    Zendesk Community Team

    This is awesome. Thanks for taking the time to share this Karen!

    0
  • Molly Phillips

    I too would like the feature to remove individual articles or sections from search. While Karen's solution is great for her, it's not ideal for the rest of us.

    0
  • Karen D Snyder

    Molly Phillips

    My solution is definitely not ideal when there is more than one page of search results. I was given a suggestion at https://support.zendesk.com/hc/en-us/community/posts/360034053994-Allow-article-to-be-excluded-from-search-results of a different way to hide articles that have a certain string in the title, but I couldn't get it to work. You could try it and see if it works for you.

    0

Post is closed for comments.

Powered by Zendesk