Adding Synonym Sets to Help Center search for Guide

4 Comments

  • Jennifer Rowe
    Comment actions Permalink

    I love this idea! thanks for sharing it, Andrew.

    0
  • Heather Rommel
    Comment actions Permalink

    This is fantastic! Thank you!

    0
  • Vladan Jovic
    Comment actions Permalink

    Awesome! Thank you, Andrew!

    0
  • Amy Gracer
    Comment actions Permalink

    Finding lots of misspellings in my search results, so I wanted to give this a try. I added it to my JS, but still not getting the synonym results. 

    Any tip on what I might have done wrong?

    //Synonyms

    $(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('receiving', ['recieving', 'receivings', 'recievings',]);
    NewSynonymSet('commission', ['commissions', 'comission', 'comissions', 'commision', 'commisions']);

    $('#query').on('keyup', function () {
    ChangeSearch(this);
    });
    $('#query').on('paste', function () {
    ChangeSearch(this);
    });
    }

    //End synonyms

    0

Please sign in to leave a comment.

Powered by Zendesk