Recent searches
No recent searches
Adding Synonym Sets to Help Center search for Guide
Posted Oct 13, 2017
I posted a question earlier this week on how to perform synonym searches in Guide. It was suggested that there wasn't anything currently that does this, so I decided to make my own to share.
For us, we have some products that are frequently misspelled but no way (unless we tag all of them) to have them return in the search results or direct the user to the correct spelling. This solution enables you to add synonyms to your Help Center search.
Add this to the js file for your Help Center/Guide. You can add multiple synonym sets by copying and pasting the following line of code to handle both synonyms and spelling mistakes.
NewSynonymSet('sleep', ['dream', 'hybernate', 'nap', 'sleeep']);
//Start Code
$(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);
});
}
//End Code
1
7 comments
Jennifer Rowe
I love this idea! thanks for sharing it, Andrew.
0
Heather Rommel
This is fantastic! Thank you!
0
Vlad
Awesome! Thank you, Andrew!
0
Amy Gracer
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
Alejandro Colon
Active Feature Request (please vote):
Feature Request: Add the ability to add Synonym Sets to Help Center search for Guide
@...
I just posted a Feature Request for this at the link below. If you would like to see this feature please head over there and show your support. Please make sure to add an upvote and comment even if it is simply a "+1"
Also, you may consider adding it to your post to get the feature request more visible.
https://support.zendesk.com/hc/en-us/community/posts/360046768394-Feature-Request-Add-the-ability-to-add-Synonym-Sets-to-Help-Center-search-for-Guide
1
Louis Eloff
Hi all,
I am currently trying to solve the same challenge, especially with misspellings.
I have added the above code to our script.js on the Guide site, but it seems to only work for one of the "synonyms" in my test list. I added a few synonym lines below the sample ones, as follows, but it only works for the 2nd one (Sleep), when I search for "slep" on the HC. The others all say "No results" when searching. I made sure that articles exist for the primary words. Any ideas what I might be doing wrong? Thanks in advance!!
0
Brett Bowser
Hey Louis,
It looks like you've yet to receive a response related to your question.
While we at Zendesk are rather limited on what we can assist with on our end, we do have some great documentation that may help point you toward the desired solution you're looking for.
Customizing your Help Center theme (Guide Professional and Enterprise)
Help Center CSS Cookbook
Help Center Templates Introduction
Help Center Javascript Cookbook
Tips for using HTML to customize your Help Center
If you don't have the necessary resources available to assist with customizing your Help Center, we do have a Professional Services team that can assist at an additional cost. This is something you'll want to discuss with your account manager so if you're interested, I'm happy to get you in touch if needed.
Cheers!
-1