-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use middleman-search for a search box? #11
Comments
Nothing out of the box, but feel free to adapt the code we use in our website for searching. More info in this blogpost. |
thank you for your reply. One thing is pretty unclear for me. Where do you get your .json file for lunr? |
That's the index file autogenerated by the extension once you activate it. It defaults to |
@Jeeppler let me know if you've managed to solve this, so we close the issue |
I was able to solve this. The code you provided to me works fine. The only thing is you use the var result = _(lunrIndex.search(request.term)).take(50).pluck('ref').map(function(ref) {
return lunrData.docs[ref];
}).value(); took me a while to figure out that the underscore belongs to the I did not want to learn another library and decided to use pure JavaScript for that part: var max_search_entries = 50;
var result = []; //initialize empty array
lunrIndex.search(request.term).forEach( function (item, index) {
if ( index < max_search_entries ) {
result.push(lunrData.docs[item.ref]);
}
}); The code does exactly the same. |
Since this is an issue and therefor hard to find I would like to see the source code, the blogpost and your website link in the repo Thanks for your help. |
@Jeeppler thank you, the replacement code you posted worked! |
@macandcheese would you mind sending a PR with a proposal for adding the explanation to the |
@matiasgarciaisaia Hi - unfortunately I can't add much more as I just used the code above! The error in console is "Uncaught ReferenceError: _ is not defined", and the code above from @Jeeppler solves for that as it doesn't require anything from lodash. |
Does middleman-search provide any tag or function which can be used for a search box?
The text was updated successfully, but these errors were encountered: