diff --git a/assets/js/autocomplete/suggestions.js b/assets/js/autocomplete/suggestions.js index e21777227..7733da49b 100644 --- a/assets/js/autocomplete/suggestions.js +++ b/assets/js/autocomplete/suggestions.js @@ -21,6 +21,8 @@ const SUGGESTION_CATEGORY = { section: 'section' } +const DEFAULT_AUTOCOMPLETE_LIMIT = 10 + /** * Returns a list of autocomplete suggestion objects matching the given term. * @@ -28,7 +30,8 @@ const SUGGESTION_CATEGORY = { * @param {Number} limit The maximum number of results to return. * @returns {Suggestion[]} List of suggestions sorted and limited. */ -export function getSuggestions (query, limit = 8) { +export function getSuggestions (query, explicitLimit = null) { + const limit = explicitLimit || window.autocompleteLimit || DEFAULT_AUTOCOMPLETE_LIMIT if (isBlank(query)) { return [] } diff --git a/assets/js/search-bar.js b/assets/js/search-bar.js index 2e50e04e4..9d57b07c3 100644 --- a/assets/js/search-bar.js +++ b/assets/js/search-bar.js @@ -26,6 +26,7 @@ if (!isEmbedded) { function initialize () { addEventListeners() + setAutocompleteLimit() window.onTogglePreviewClick = function (event, open) { event.preventDefault() @@ -59,6 +60,15 @@ export function focusSearchInput () { searchInput.focus() } +function setAutocompleteLimit () { + const searchInput = qs(SEARCH_INPUT_SELECTOR) + const autocompleteLimit = parseInt(document.querySelector('meta[name="exdoc:autocomplete-limit"]').content) + if (autocompleteLimit) { + window.autocompleteLimit = autocompleteLimit + } + searchInput.setAttribute('autocomplete-limit', autocompleteLimit) +} + function addEventListeners () { const searchInput = qs(SEARCH_INPUT_SELECTOR) diff --git a/assets/test/autocomplete/suggestions.spec.js b/assets/test/autocomplete/suggestions.spec.js index 1f2357a9f..62b787341 100644 --- a/assets/test/autocomplete/suggestions.spec.js +++ b/assets/test/autocomplete/suggestions.spec.js @@ -123,7 +123,7 @@ describe('getSuggestions', () => { }) it('returns max 8 results', () => { - expect(getSuggestions('e').length).to.eql(8) + expect(getSuggestions('e').length).to.eql(10) }) it('returns no results if no match found', () => { diff --git a/lib/mix/tasks/docs.ex b/lib/mix/tasks/docs.ex index 9a6389590..6e1d15edd 100644 --- a/lib/mix/tasks/docs.ex +++ b/lib/mix/tasks/docs.ex @@ -365,6 +365,9 @@ defmodule Mix.Tasks.Docs do * `exdoc:autocomplete` - when set to "off", it disables autocompletion. + * `exdoc:autocomplete-limit` - Set to an integer to configure how many results + appear in the autocomplete dropdown. Defaults to 10. + * `exdoc:full-text-search-url` - the URL to use when performing full text search. The search string will be appended to the URL as an encoded parameter. You could use this to bring a custom search engine to your