Skip to content

Instantly share code, notes, and snippets.

@tisto
Created July 17, 2013 08:01
Show Gist options
  • Save tisto/6018642 to your computer and use it in GitHub Desktop.
Save tisto/6018642 to your computer and use it in GitHub Desktop.
/*jshint strict: true, undef: true*/
/*global $,jQuery,window,document,localStorage,confirm,location,portal_url*/
(function ($) {
"use strict";
$("form#searchform").on("click", "input[type='submit']", function (event) {
event.preventDefault();
$('#solr-suggestions').remove();
var SearchableText = $("input[name='SearchableText']").val();
var url = portal_url + "/@@suggest-terms?term=" + SearchableText;
$.ajax({
url: url,
dataType: 'json',
success: function (data) {
if (data.length > 0) {
var suggestion_term = data[0].value.word;
var suggestion_link = portal_url + '/@@search?SearchableText=' + suggestion_term;
$('h1.documentFirstHeading').append(
$('<h4>', {'id': 'solr-suggestions'})
.append('<span>Did you mean </span>')
.append('<a href="' + suggestion_link + '">' + suggestion_term + '</a>')
.append('<span>?</span>')
);
}
},
});
});
}(jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment