Can I exclude an article from search results?

Have more questions? Submit a request

19 Comments

  • Alison Ford
    Comment actions Permalink

    I'm trying to add an article in draft mode, but I cannot see this option.  In edit mode there is no draft/published in the top right as indicated in the screen shot above.

     

    How do I control draft/published?

    0
  • Jessie Schutz
    Comment actions Permalink

    Hi Alison!

    As long as you're in edit mode, that option should definitely show up for you. Can you post a screenshot of what you're looking at?

    0
  • Dave Voll
    Comment actions Permalink

    I see there is mention of a jQuery code to hide a document from search results, would someone be able to give more info on how to accomplish this? I have an article that is hidden but published and viewable by anyone and hiding it from the search is my last thing to figure out so that it's only available to those with the link.

    0
  • Chris Wilson
    Comment actions Permalink

    Hi Dave!

    I too am trying to create an article that is published and only accessible if you have the link for it, and is not searchable.  Curious how you accomplished the first part of not making it appear in any categories/sections, did you use a div tag or something?  Thanks in advance for your help!

    0
  • Jessie Schutz
    Comment actions Permalink

    Hey, Dave and Chris!

    I did some poking around to see if anyone had actually posted code for this, and I didn't find anything for this specifically.

    However, I did find a tip from one of our Moderators, Andrea, with code to hide an article's author from search results

    My thought is that this code might be able to serve as a jumping off point, with some strategic changes made to hide the article completely.

    Keep us posted on how you get on! If you get stuck, let us know and I'll try to find a Moderator who can help you troubleshoot - we've got a couple folks who are good at this kind of thing. And if you do get it figured out on your own, it would make a great contribution for our Tips & Tricks section. :)

    0
  • Ian Maison
    Comment actions Permalink

    Hi, this does not really work for us as we don’t want to enforce our users to have to sign in, our restrict them to being part of an Organisation. We simply want to hide the articles from Category/Section/Article view, which we’ve done with curlybars, and then simply not have the hidden articles return in the Help Centre search results.

    Is there no way to do this?

    0
  • Jessie Schutz
    Comment actions Permalink

    Hey Ian!

    I can't speak to how it would work to restrict search results with JS, but I imagine you could probably figure out a way to do it.

    That said, it would be much easier to just restrict the individual sections you don't want your logged-out users to see. You can restrict them by tag or org, which will automatically hide them from logged-out users. No need to force anyone to log in or anything.

    0
  • Cale Shapera
    Comment actions Permalink

    Howdy,

    I have some code which works (albeit haggardly) for this. If you want to hide an article called "Secret Article", plug in the following code:

    if($('li.search-result a:contains("Secret Article")').length > 0)
      {
        $('li.search-result a:contains("Secret Article")').hide();
        $('li.search-result a:contains("Secret Article")').next().hide();
        $('li.search-result a:contains("Secret Article")').next().next().hide();
      }

    I had to run the .hide() function three times to hide the title, author, and details, respectively.

    This is useful if you have an article that you want to link to a certain subsection of your readers, but don't want people surfacing it in the Zendesk search.

    Hope this is of help to someone!

    2
  • Kalle Windefalk
    Comment actions Permalink

    Cale, would this work by using a label called "secret article"?

    1
  • Cale Shapera
    Comment actions Permalink

    Hi Kalle,

    No, this code wouldn't work by adding a label.

    The code works by detecting the title of the article. Whatever the title of the article you want to hide, change "Secret Article" in the code to the name of that article.

    Cheers,

    Cale

    0
  • Kalle Windefalk
    Comment actions Permalink

    Ah. Got it! Thanks a lot Cale

    1
  • Drew Kite
    Comment actions Permalink

    Hello Cale, 

    I am not sure if you are able to help, I am looking for a way to hide a whole category from the help centre search. I am not sure if you are anyone else knows how this can be done? 

    Many thanks,

    Drew

    1
  • Cale Shapera
    Comment actions Permalink

    Hi Drew,

    If your search results page includes the category, this should be possible.

    For example, on my search page, this is the category:

    If I check out the page in Chrome developer tools:

    We can see that the category name is displayed inside the <div> with a class "search-result-meta". So we can use jQuery selectors to find all the category links which include a specific term (the name of the category).

    In my example, if I wanted to hide the "Billing" category, my code would look something like this:

    if($('div.search-result-meta a:contains("Billing)').length > 0)
      { 
        $('div.search-result-meta').parent().hide();
      }

    I doubt the above code would actually work, but the idea would be to find every div that contains a link with your category name, and then, if the category name is present, hide the parent element (the <li> item that is displayed in the search results). With some fiddling, you can probably get it done.

    Hope this gets you on the right track!

    Cheers,
    Cale

    0
  • Drew Kite
    Comment actions Permalink

    Hello Cale, 

    Thank you for the quick reply. Unfortunately I believe you are correct that this will not work, the category is not displayed but the articles within it.

    I was hoping there may be a way to blanket remove all items from search that are associated to a category? 

    Many thanks for your reply
    Drew

    0
  • Cale Shapera
    Comment actions Permalink

    Hi Drew,

    I wish I had time to dig in to fixing this—I get a sick pleasure from solving these little problems—however, I'm quite busy right now. Perhaps try posting some code snippets along with your technical challenge to stackoverflow.

    If you can't wrangle through the jQuery, you could consider making the section containing the articles visible only to signed-in users. That would hide them from the search both in Google and on your site (if a user isn't logged in).

    That's the only other option I can think of offhand—good luck!

    Cheers,
    Cale

    0
  • Jamie Canada
    Comment actions Permalink

    Hi all,

    I'm not sure that everyone understood the intent of the original poster (OP). The idea is to have a public Zendesk article; however, some (or all) of the contents shouldn't be searchable via Zendesk's search feature.  The good people at Zendesk have been clear that there is no feature to disallow the search of an article, and they've even offered a few workarounds.

    I too use my own workaround for this situation and I think it falls more in line with what the OP had in mind. I'd like to share my solution with you. I use it for our XPunch employee time punch clock help desk, and you can see an example of just such a Zendesk article at https://xpunch.zendesk.com/hc/en-us/articles/360027671032-Product-Updates-and-Fixes

     

    So, here's the thing: this particular article is a product update page. Every time we introduce a product feature, update, or fix,we want to be able to let our users know about it.  The problem is that many words we use in this particular article would appear in a search when users are genuinely looking for product help—we don't want to confuse them by displaying a link to this list of product updates. For example, we might advise everyone in our Product Updates article that we've just added "timesheets" as a new feature to the employee time recorder, but we don't want the search keyword "timesheets" to point to this article in the search results—we only want articles that explain how to use timesheets correctly to workers that use XPunch.

    So, the fix was easy: create a cloud document (I used Google Docs, but you can use anything that can be embedded on Zendesk), and embed the document into your Zendesk article. Zendesk won't be able to add the contents of your document to its search engine.

    In the case of Google Docs, the embed code will look something like this:

    <iframe src="https://docs.google.com/document/d/e/2PACX-1vRTXW-buJZ-VOBzBA07X9ReE9dla9Aq3_DKnHMKEXLxcoqTBedOMdnXVqFOsnmgJm7H2NbTfKcvMPpY/pub?embedded=true" width="100%" height="480"></iframe>

    To summarize, yes, it's still a workaround to getting text to not appear in Zendesk's search engine, but it's a quick and easy fix that allows articles to be public, yet not searchable.

    0
  • Floris Bijker
    Comment actions Permalink

    Alright, sharing for who else stumbles upon this: I fiddled around with this, and got a little further, although it's also a bit of a Frankenstein workaround. 

    If you want to hide articles from a specific Section or Category, you can do the following:

    First, find your search results section, and specifically something like this:

    {{#each article_results}}
    <li class="search-result">

    Anywhere under there add the following (if you don't already have the {{meta}} object anywhere that is)

    <div class="hidden-articles-meta" style="display:none;">{{meta}}</div>

    You can choose to hide this or not, doesn't matter. The important thing is that with this, we pull in the Categories and Sections that the individual search results fall under.

    After that, a bit lower on the page, add the following jQuery script snippet:

    <script>
    $('li.search-result').has('div.hidden-articles-meta a:contains("Restricted Content")').remove();
    </script>

    This finds the div you added, with the class hidden-articles-meta. Then it checks if any links under it contain the words 'Restricted Content' (replace this with the name of the Section/Category you want to hide articles for).

    That should do the trick.

     

    I've found one issue with it though: It cuts the results out of the page, and doesn't fill them up with new results. So your paginations becomes a bit weird, as it could be that it cuts a lot of the results out and only leaves 2 results on the first page, with 10 results on the 2nd page. Anyone with a solution to that, please let me know ;)

     

    If Zendesk could add more objects, that would be greatly appreciated to make customization easier. In this case, Objects for article IDs, Category IDs etc would help. 

    0
  • Joe
    Comment actions Permalink

    Floris - I have a somewhat messy way to fix the "10 results" when you are excluding some of the search results.

    I created three javascript variables: (1) totalArticles that adds up all of the returned search results by placing it inside the {{#each article_results}} guide helper block, (2) hiddenArticles that used a similar jQuery snippet to the one you posted using .length instead of .remove() to add up the number of results that were removed, and (3) visibleResults which is just #1 minus #2.

    I then just used innerHTML to append the value of visibleResults before the rest of the "results for {{query}}" header.

    1
  • Michael Martello
    Comment actions Permalink

    I have a solution similar to Floris's for when you want to hide an entire section from search results, but this one does not require jQuery.

    Using Handlebars, you can hide a result from your search_results.hbs by wrapping the result in a hidden div if the result is in the section you want to hide. To hide a section called "Notifications", you would use code like this to start:

    {{#each path_steps}}
    {{#is name "Notifications"}}
    <div style="display: none;">
    {{/is}}
    {{/each}}

    And then close your div at the end of your template:

    {{#each path_steps}}
    {{#is name "Notifications"}}
    </div>
    {{/is}}
    {{/each}}

    The whole thing might look something like this:

    <section class="search-results-column">
    <h3 class="search-results-subheading">
    {{t 'knowledge_base'}}
    </h3>
    {{#if article_results}}
    <ul class="search-results-list">
    {{#each article_results}}
    {{#each path_steps}}
    {{#is name "Notifications"}}
    <div style="display: none;">
    {{/is}}
    {{/each}}
    <li class="search-result">
    <a href="{{url}}" class="search-result-link">{{title}}</a>
    {{#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}}">{{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 path_steps}}
    {{#is name "Notifications"}}
    </div>
    {{/is}}
    {{/each}}
    {{/each}}
    </ul>
    {{else}}
    <p>
    {{t 'no_results' query=query}}
    {{#link 'help_center'}}
    {{t 'browse_knowledge_base'}}
    {{/link}}
    </p>
    {{/if}}
    </section>

    The caveat Floris called out is the same; you will no longer have 10 results per page as results are hidden. I also want to call out that while this will hide results from the search results page, it will not hide anything from being suggested as one types in the search bar. One more thing: we don't have any categories in our help center, just sections, so it is possible you may have to tweak this code a little if you have both categories and sections. Still, I hope this is helpful for someone else!

    1

Please sign in to leave a comment.

Powered by Zendesk