doc: extensions: kconfig: improve search capabilities

This patch modifies the Kconfig search _algorithm_ so that it aligns
with how menuconfig search works:

- Input is splitted into multiple search terms (space based split)
- Both Kconfig option name and prompt are used
- Regex search is used instead of match, it is less efficient but will
  search the whole string, leading to more results.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
Gerard Marull-Paretas 2022-08-09 12:11:08 +02:00 committed by Carles Cufí
commit e526b407d2

View file

@ -289,11 +289,23 @@ function doSearch() {
} }
/* perform search */ /* perform search */
let pattern = new RegExp(input.value, 'i'); const regexes = input.value.trim().split(/\s+/).map(
element => new RegExp(element.toLowerCase())
);
let count = 0; let count = 0;
const searchResults = db.filter(entry => { const searchResults = db.filter(entry => {
if (entry.name.match(pattern)) { let matches = 0;
const name = entry.name.toLowerCase();
const prompt = entry.prompt ? entry.prompt.toLowerCase() : "";
regexes.forEach(regex => {
if (name.search(regex) >= 0 || prompt.search(regex) >= 0) {
matches++;
}
});
if (matches === regexes.length) {
count++; count++;
if (count > searchOffset && count <= (searchOffset + MAX_RESULTS)) { if (count > searchOffset && count <= (searchOffset + MAX_RESULTS)) {
return true; return true;