Last active
August 29, 2015 14:06
-
-
Save dalegaspi/20b7db4ef2d4d55be661 to your computer and use it in GitHub Desktop.
Gist for Solr with Twitter Typeahead
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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