Search Synonyms for Zendesk Guide

9 Comments

  • Monica

    Interested in this as well.  It would be incredibly helpful to have a way to designate specific misspellings to the correct spelling so we don't have to label multiple help articles with the correct and common incorrect spellings.

    0
  • Jessie Schutz
    Zendesk team member

    Hey Andrew!

    There isn't anything built into the product that would do this for you, but I'm kind of wondering whether there's some kind of JavaScript hack that might allow it...I'm going to check with some of the coding gurus amongst our Moderators to see if there's anything there.

    0
  • Andrew Schreiner

    Hi Jessie, 

    Based on your suggestion, I've developed a code snippet that can do this. Add this to the js for the help center 

    $(document).ready(function() {
       InitializeSynonyms()
    });

    var synonymsets = new Array();
    function NewSynonymSet(key, synonyms) {
       var synonym = new Object();
       synonym.primary = key;
       synonym.keywords = synonyms;
       synonymsets.push(synonym);
    }

    function ChangeSearch(val)
    {
       var q = $(val).val();
       var query = q.toLowerCase().split(' ');
       for (var i = 0; i < query.length; i++) {
          for (var x = 0; x < synonymsets.length; x++) {
             var primary = synonymsets[x].primary;
             var keywords = synonymsets[x].keywords;
             if ($.inArray(query[i], keywords) > -1) {
                query[i] = primary;
             }
          }
       }
       var newQuery = '';
       for (var i = 0; i < query.length; i++) {
          newQuery += ' ' + query[i];
       }
       $('#query').val(newQuery.substring(1));
    }

    function InitializeSynonyms() {
       //always lowercase and can handle misspellings too.
       //Enter as many of these lines below as needed with different synonym sets
       NewSynonymSet('sleep', ['dream', 'hybernate', 'nap', 'sleeep']);
       $('#query').on('keyup', function () {
          ChangeSearch(this);
       });
       $('#query').on('paste', function () {
          ChangeSearch(this);
       });
    }

    1
  • Heather Rommel
    Community Moderator

    @Andrew - Thanks! I have a couple questions for you on this.  Does the above "activate" some sort of automatic translation of misspellings from a given database or source? Or is this line meant to be where we add all the possible synonyms/misspellings:  NewSynonymSet('sleep', ['dream', 'hybernate', 'nap', 'sleeep']);

    And again, thank you!!!

     

    0
  • Andrew Schreiner

    Hi Heather, 

    You would want to put multiple sets in there underneath the first for each one you would like to handle. I'll add a comment in the snippet above. There is no lookup to an outside source for synonyms so everything it looks at is entered manually.

     NewSynonymSet('sleep', ['dream', 'hybernate', 'nap', 'sleeep']);
     NewSynonymSet('sleep', ['dream', 'hybernate', 'nap', 'sleeep']);
     NewSynonymSet('sleep', ['dream', 'hybernate', 'nap', 'sleeep']);

    1
  • Jennifer Rowe
    Zendesk Documentation Team

    Andrew! I love this. What a cool idea!

    Can you pretty please share this as a tip!?

    It'd be nice to show a picture, but not sure what you'd show it...unless it's a mispelled word, then the resulting correct search results. Whatever you can do. But at least the description and code and users will love it!!!

    Thanks!

    0
  • Jennifer Rowe
    Zendesk Documentation Team

    You are awesome, Andrew. Thanks so much for sharing your tip!

    0
  • Jessie Schutz
    Zendesk team member

    Hooray! I love it when a plan comes together. :D

    0

Please sign in to leave a comment.

Powered by Zendesk