Add autocomplete support when searching Danbooru from the Chrome address bar. If you type "danb<tab>" in the address bar then search for a tag, then autocomplete results from Danbooru will appear as search suggestions in Chrome. Note that the "Autocomplete searches and URLs" Chrome setting must be enabled for this to work. Ref: * http://dev.chromium.org/tab-to-search * https://developer.mozilla.org/en-US/docs/Archive/Add-ons/Supporting_search_suggestions_in_search_plugins * https://github.com/dewitt/opensearch/blob/master/mediawiki/Specifications/OpenSearch/Extensions/Suggestions/1.1/Draft%201.wiki
17 lines
411 B
Ruby
17 lines
411 B
Ruby
class AutocompleteController < ApplicationController
|
|
respond_to :xml, :json
|
|
|
|
def index
|
|
@tags = Tag.names_matches_with_aliases(params[:query], params.fetch(:limit, 10).to_i)
|
|
|
|
if request.variant.opensearch?
|
|
expires_in 1.hour
|
|
results = [params[:query], @tags.map(&:pretty_name)]
|
|
respond_with(results)
|
|
else
|
|
# XXX
|
|
respond_with(@tags.map(&:attributes))
|
|
end
|
|
end
|
|
end
|