Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not possible to search for fewer than 3 characters. #2014

Closed
jimconner opened this issue Mar 2, 2020 · 5 comments
Closed

Not possible to search for fewer than 3 characters. #2014

jimconner opened this issue Mar 2, 2020 · 5 comments

Comments

@jimconner
Copy link
Contributor

One of our mkdocs sites contains details about IBM MQ, but currently our users are telling us that they cannot find any documentation because when they search for 'MQ' it comes back saying 'No Results Found'.

There appears to be a hardcoded minimum search length configured in the doSearch() function within contrib/search/templates/search/main.js. If the search term query.length is >2 then the search is done, but if not then empty results are displayed instead. This is misleading - If the search is too short then a message should be displayed to indicate that is the reason why no results are available.

function doSearch () {
  var query = document.getElementById('mkdocs-search-query').value;
  if (query.length > 2) {
    if (!window.Worker) {
      displayResults(search(query));
    } else {
      searchWorker.postMessage({query: query});
    }
  } else {
    // Clear results for short queries
    displayResults([]);
  }
}

It would be really great to have a config parameter so that the minimum search length could be configured, but even without that, having a useful message appear to let users know that their search was too short would be really helpful for us - it would save us from having to answer the phone a few times a week to point people in the right direction.

@jimconner jimconner changed the title Not possible to search for less than 3 characters. Not possible to search for fewer than 3 characters. Mar 2, 2020
@waylan
Copy link
Member

waylan commented Mar 2, 2020

As I understand it, in most cases a search of less than 3 characters is not going to result in useful results, thus the default. However, there are some specific cases where a 2 character search could be useful. But those cases are relatively few and not a high priority for us. That being the case, we would be willing to consider a PR which added a config option to the search plugin, but otherwise are not likely to get to this feature anytime soon.

@jimconner
Copy link
Contributor Author

Thanks Waylan - I'll see if I can put together a respectable looking PR tomorrow.

@jimconner
Copy link
Contributor Author

Pull request 2018 now raised which changes the default message displayed if the search term was too short (but leaves the 'No results message' alone if there were actually no results returned).

The PR doesn't address the idea of making the minimum search length configurable, but it will be sufficient for our needs to stop our users getting confused.

@waylan
Copy link
Member

waylan commented Mar 9, 2020

As a reminder, a significant reason for the character limit is for the "live update" feature which some themes make use of. As an example, the mkdocs theme does not have a "search page" but instead provides a "search modal" which is available on all pages (you can find an example on https://mkdocs.org). As the user types, the search results are updated for each key press. Searches with no results which return a result would be extremely confusing to users.

In contrast, other themes, such as the readthedocs theme, have a search page, where the user types out their search terms and then submits. In that case, it might make more sense to not limit character count.

Perhaps this should be a theme option, which would also be user overridable. Or a plugin option would be a reasonable alternative. However, returning a message as a search result is not the right way to handle this. If you want to alter the "no results" default, then that would be something to take to the theme you are using.

@jimconner
Copy link
Contributor Author

Pull request now updated to handle taking a parameter min_search_length within the search plugin config.

@waylan waylan closed this as completed in 2505a90 Mar 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants