Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion assets/js/autocomplete/suggestions.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@ const SUGGESTION_CATEGORY = {
section: 'section'
}

const DEFAULT_AUTOCOMPLETE_LIMIT = 10

/**
* Returns a list of autocomplete suggestion objects matching the given term.
*
* @param {String} query The query string to search for.
* @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 || 10
if (isBlank(query)) {
return []
}
Expand Down
10 changes: 10 additions & 0 deletions assets/js/search-bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ if (!isEmbedded) {

function initialize () {
addEventListeners()
setAutocompleteLimit()

window.onTogglePreviewClick = function (event, open) {
event.preventDefault()
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion assets/test/autocomplete/suggestions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
3 changes: 3 additions & 0 deletions lib/mix/tasks/docs.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down