Add autocomplete to search form
CODEBASE-100: Add the opensearch style autocomplete to the input field on the search form.
JSON response is already available via opensearch method of the catalog controller. Need AJAX to to generate autocomplete suggestions box.
Original reporter: jkeck
jrochkind: bullk change, pushing past 3.1 in preperation for 3.0.
http://twitter.github.com/bootstrap/javascript.html#typeahead ?
There is, I'm pretty sure, no good fits-all-use-cases works-with-various-solr-versions way to do autocomplete from a solr index. The current "opensearch" autocomplete is pretty broken.
So I'd say please don't do this as a default built-in feature. It seems like a great candidate for a plug-in gem.
If it's really variable across solr versions, then maybe, but if it's easily disabled (by overriding a partial ) and it works with 4 (and 3, perhaps), that seems more than enough coverage to warrant it.
On Fri, Nov 2, 2012 at 3:09 PM, Jonathan Rochkind [email protected]:
There is, I'm pretty sure, no good fits-all-use-cases works-with-various-solr-versions to do autocomplete from a solr index. The current "opensearch" autocomplete is pretty broken.
So I'd say please don't do this as a default built-in feature. It seems like a great candidate for a plug-in gem.
— Reply to this email directly or view it on GitHubhttps://github.com/projectblacklight/blacklight/issues/129#issuecomment-10026364.
I think with RSolr::Ext now merged into Blacklight, we could do a decent job of it at least for the 80% case.
Is autocomplete on search form text box working on the latest version? It doesn't seem to work under 5.8.1.
No. This is an open ticket to add that feature to Blacklight. We've been working on a similar feature in sul-dlss/spotlight using twitter's typeahead.js that may lend itself to extracting upstream:
https://github.com/sul-dlss/spotlight/blob/master/app/controllers/spotlight/catalog_controller.rb#L41-49 https://github.com/sul-dlss/spotlight/blob/master/app/assets/stylesheets/spotlight/typeahead.css https://github.com/sul-dlss/spotlight/blob/master/app/assets/javascripts/spotlight/search_typeahead.js https://github.com/sul-dlss/spotlight/blob/master/app/assets/javascripts/spotlight/blocks/item_text_block.js#L93-94
Thanks for the info, I tried spotlight and followed the install instruction here https://github.com/sul-dlss/spotlight but http://localhost:3000/spotlight/default-exhibit reported Couldn't find Spotlight::Exhibit with 'id'=default-exhibit any idea?
Is this working on spotlight already? If I understand correctly if we add "id_ng" and "full_title_ng" and define EdgeNGram filter for these fields, the search box on the home menu will have autocomplete function, or it needs other setting to add autocomplete to the search box on the home menu?
Yes, we have code in spotlight (linked above) that implements autocomplete. Yes, you need to have data in solr to support it. EdgeNGrams gives you partial word matches, but you may have other indexing considerations as well.
It seems it is not activated in the search box on the home page, is there some setting we can use to activate it? Thanks!
The autocomplete is present in the sir-trevor widgets when adding items to pages (i.e. the home, feature, or about pages).
So can it be added to the search box on the home page?
It theoretically could although that's probably not what you want. We've developed and configured the spotlight autocomplete feature for a very specific use-case, that is, the ability to begin typing in the title of an object and allow the user to select a single item (which we then store the ID of the object in the sir-trevor JSON serialization).
The use-case that it sounds like you may want is a little more complicated than that and what we've done wouldn't really yield the result you're looking for (unless you're trying to get people to bypass the search results and go directly to the record returned in the autocomplete).
The links above show you how we did that in Spotlight, and should be really helpful in instructing you how to implement something closer to what you're going to want.
If you're feeling up to it, wrap the code up in a gem to extend blacklight and let us know about it. This way other folks in the community can potentially adopt the functionality. You could also submit a Pull Request to Blacklight to add the feature in core, but a gem may be a better way to go initially and allows you to use your code w/o being on a fork of Blacklight.
Thanks! Maybe instead of storing the ID of the object, we can add the object title in the search box.
Here's another example of autocomplete using a Solr suggester: https://github.com/sul-dlss/earthworks/pull/241
Fixed in #1288