forked from Ponysearch/Ponysearch
Use query params for browser autocomplete
Sending query params over GET seems to be the only way to be able to enable autocomplete in the browser. This commit adds the necessary URL formatting to opensearch.xml. In order to identify queries coming from the URL bar (rather than an AJAX request), which requires a different JSON format and MIME type, the request headers are checked for "X-Requested-With: XMLHttpRequest" which is added by jQuery request.
This commit is contained in:
parent
3c45fb7a99
commit
1ea35605d1
2 changed files with 5 additions and 5 deletions
|
@ -13,6 +13,6 @@
|
|||
</Url>
|
||||
{% endif %}
|
||||
{% if autocomplete %}
|
||||
<Url rel="suggestions" type="application/json" template="{{ host }}autocompleter"/>
|
||||
<Url rel="suggestions" type="application/x-suggestions+json" template="{{ host }}autocompleter?q={searchTerms}"/>
|
||||
{% endif %}
|
||||
</OpenSearchDescription>
|
||||
|
|
|
@ -790,13 +790,13 @@ def autocompleter():
|
|||
results.append(raw_text_query.getFullQuery())
|
||||
|
||||
# return autocompleter results
|
||||
if request.form.get('format') == 'x-suggestions':
|
||||
return Response(json.dumps([raw_text_query.query, results]),
|
||||
mimetype='application/json')
|
||||
|
||||
if request.headers.get('X-Requested-With') == 'XMLHttpRequest':
|
||||
return Response(json.dumps(results),
|
||||
mimetype='application/json')
|
||||
|
||||
return Response(json.dumps([raw_text_query.query, results]),
|
||||
mimetype='application/x-suggestions+json')
|
||||
|
||||
|
||||
@app.route('/preferences', methods=['GET', 'POST'])
|
||||
def preferences():
|
||||
|
|
Loading…
Reference in a new issue