diff --git a/aio/src/app/search/search.worker.ts b/aio/src/app/search/search.worker.ts index 0874763303..f1c44bc30b 100644 --- a/aio/src/app/search/search.worker.ts +++ b/aio/src/app/search/search.worker.ts @@ -119,7 +119,8 @@ function queryIndex(query: string): PageInfo[] { try { if (query.length) { // First try a query where every term must be present - const queryAll = query.replace(/(^|\s)([^\s]+)/g, '$1+$2'); + // (see https://lunrjs.com/guides/searching.html#term-presence) + const queryAll = query.replace(/\S+/g, '+$&'); let results = index.search(queryAll); // If that was too restrictive just query for any term to be present @@ -129,7 +130,7 @@ function queryIndex(query: string): PageInfo[] { // If that is still too restrictive then search in the title for the first word in the query if (results.length === 0) { - // E.g. if the search is "ngCont guide" then we search for "ngCont guide title:ngCont*" + // E.g. if the search is "ngCont guide" then we search for "ngCont guide title:*ngCont*" const titleQuery = 'title:*' + query.split(' ', 1)[0] + '*'; results = index.search(query + ' ' + titleQuery); }