How to exclude Community posts from Guide search results?

9 Comments

  • Ifra Saqlain
    Community Moderator
    Most Engaged Community Member - 2022
    Most Engaged Community Member of The Year - 2021

    Hey Beth Borghi,

    In the latest Copenhagen version, there is a filter in the sidebar and users can use it to exclude only posts on Help Center.

     

    Hope it helps you :)

    Thanks

    0
  • Beth

    Thanks for the reply, Ifra! I'm aware of this, and trying to remind/train users to filter as well - however, since we changed to the Copenhagen theme recently, they're not in the habit yet and a bit unhappy about this. ;) Was hoping there was a way to limit it altogether - thanks!

    0
  • Ifra Saqlain
    Community Moderator
    Most Engaged Community Member - 2022
    Most Engaged Community Member of The Year - 2021

    Hey Beth Borghi, use the below code for your search results template.

    <section class="container">
    {{#if results}}
      <ul class="search-results-list">
        {{#each results}}
            <li class="search-result">
              <a href="{{url}}" class="search-result-link" title="{{title}}"> {{title}} </a>
                <span class="search-result-meta-count">
                {{comment_count}}
              </span>
              {{#if vote_sum}}
              <span class="search-result-votes meta-count">{{vote_sum}}</span>
              {{/if}}
              <ul class="meta-group">
                <li>
                  <ol class="breadcrumbs search-result-breadcrumbs">
                    {{#each path_steps}}
                    <li title="{{name}}">
                      <a href="{{url}}" title="{{name}}">{{name}}</a>
                    </li>
                    {{/each}}
                  </ol>
                </li>
                <li class="meta-data">
                  {{#link 'user_profile' id=author.id}} {{author.name}} {{/link}}
                </li>
                <li class="meta-data">{{date created_at timeago=true}}</li>
              </ul>
              <div class="search-result-description">{{text}}</div>
            </li>
         {{/each}}
         {{else}}
          <p>
            {{t 'no_results' query=query}} 
          </p>
       </ul>
     {{/if}}
     {{pagination}}
    </section>
    0
  • Beth

    Hi Ifra Saqlain, thank you for the follow up! I used the above code and it limited the knowledge base articles and only showed the Community posts - I actually want it to do the opposite, and only show KB articles and no Community posts. Is that possible? Thank you!

    0
  • Ifra Saqlain
    Community Moderator
    Most Engaged Community Member - 2022
    Most Engaged Community Member of The Year - 2021

    Hi Beth Borghi, 

    You can hide community post via custom JS on search results to show only KB articles.

     

    I). Add the template name to search results page.

    <script>
      templateName = "search_results";
    </script>


    Screenshot for the same:

     

    II). Now, copy and paste the below code to the your script.js file.

    $(document).ready(function() {
      if(templateName == "search_results") {
        $('.breadcrumbs.search-result-breadcrumbs li:nth-child(2) a:contains("Community")').parents(".search-result-list-item").hide();
      }
    })


    Screenshot for the same:

     

    Make sure, document_head.hbs file has jQuery Lib:

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

     

     

    Hope you will get your solution :)

    Thanks

     

    0
  • Ifra Saqlain
    Community Moderator
    Most Engaged Community Member - 2022
    Most Engaged Community Member of The Year - 2021

    Update:

    • Exclude Community posts from Guide search results while searching any query.
    • But, when Community tab in Type section or select any Brand in Source section in sidebar, your search results would be default.
    $(document).ready(function() {
      if(templateName == "search_results") {
          if (window.location.href.indexOf("community") < 1) {
              if (window.location.href.indexOf("source") < 1) {
                 $('.breadcrumbs.search-result-breadcrumbs li:nth-child(2) a:contains("Community")').parents(".search-result-list-item").hide();
            }
         } 
      } 
    })




    Screenshot:

     

     

    0
  • MC Guenette

    Hey Ifra Saqlain

    Sorry to bother you, but I feel like you're the closest person I have found for a potential solution. So I'll ask here and if you're able to help I will post it in another thread to help others!

    We're looking to hide articles (Categories) from search. Reason is, we're sending only direct links for a couple of categories. With that, I need to be able to hide articles/categories from the search form.

    I have tried a couple of things, but no luck. 

    Hope you're able to help, we do use labels. ie. sc_apps is one of them, I also used CSS to hide categories via ID's everywhere else.

    Thank you sooooo much in advance or anyone else possibly jumping in here.

    2
  • Ryan Frye

    Hello, 

    I got this mostly working, but the pagination is off. For us, when executing a search it shows 6 results on the first page, then 4 on the second page, and 11 on the third page, etc. Is there a way to make it so each page shows 25 results for example? 

    Thanks! 

    0
  • Greg Katechis
    Zendesk Developer Advocacy

    Hi Ryan! Due to the nature of the provided solution, there really wouldn't be a way to get the results you're looking for. That's because we are returning the number of results and the script simply hiding the results from the community. Short of a product solution that changes the underlying search algorithm, there would not be a way to get the same experience with the hidden results as you have with all of the contend being visible.

    The best place to get that feedback is in our feedback forum for Guide. I checked through the most popular posts in there and I was surprised that I didn't see this feedback already captured, despite it being a pretty reasonable request. Just take a look at the posts that explain the best way to get traction on your feedback and hopefully one of our product managers will be able to provide some insight for you!

    0

Please sign in to leave a comment.

Powered by Zendesk