Skip to content

Instantly share code, notes, and snippets.

@dalegaspi
Last active August 29, 2015 14:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dalegaspi/20b7db4ef2d4d55be661 to your computer and use it in GitHub Desktop.
Save dalegaspi/20b7db4ef2d4d55be661 to your computer and use it in GitHub Desktop.
Gist for Solr with Twitter Typeahead
<form role="search">
<div class="form-group">
<div class="input-group col-sm-6">
<input id="querytxt" type="text" class="typeahead form-control" />
<span class="input-group-btn">
<button id="solrsearch" class="btn btn-primary" type="button"><span class="glyphicon glyphicon-search" />
</span>
</div>
</div>
</form>
var dsrc = new Bloodhound({
datumTokenizer: function(d) {
return Bloodhound.tokenizers.whitespace(d.value);
},
queryTokenizer: Bloodhound.tokenizers.whitespace,
limit: 10,
minLength: 3,
remote: {
url: 'http://{solrserver:solrport}/solr/{collection}/suggest?q=%QUERY',
ajax: {
dataType: 'jsonp',
data: {
'wt': 'json',
'rows': 5
},
jsonp: 'json.wrf'
},
filter: function(data) {
console.log(data.spellcheck.suggestions[1])
return $.map(data.spellcheck.suggestions[1].suggestion, function(data) {
return {
value: data
};
});
}
}
});
dsrc.initialize();
$('.typeahead').typeahead({
hint: true,
highlight: true,
minLength: 1
}, {
displayKey: 'value',
source: dsrc.ttAdapter()
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment