mirror of
https://github.com/squidfunk/mkdocs-material.git
synced 2024-06-14 11:52:32 +03:00
Catch errors in search worker
This commit is contained in:
parent
2fa347aaae
commit
b31061dbeb
@ -181,21 +181,13 @@ export class Search {
|
|||||||
* page. For this reason, section results are grouped within their respective
|
* page. For this reason, section results are grouped within their respective
|
||||||
* articles which are the top-level results that are returned.
|
* articles which are the top-level results that are returned.
|
||||||
*
|
*
|
||||||
* Rogue control characters must be filtered before handing the query to the
|
|
||||||
* search index, as lunr will throw otherwise.
|
|
||||||
*
|
|
||||||
* @param query - Query string
|
* @param query - Query string
|
||||||
*
|
*
|
||||||
* @return Search results
|
* @return Search results
|
||||||
*/
|
*/
|
||||||
public search(query: string): SearchResult[] {
|
public search(query: string): SearchResult[] {
|
||||||
query = query
|
if (query) {
|
||||||
.replace(/(?:^|\s+)[*+-:^~]+(?=\s+|$)/g, "")
|
try {
|
||||||
.trim()
|
|
||||||
|
|
||||||
/* Abort early, if query is empty */
|
|
||||||
if (!query)
|
|
||||||
return []
|
|
||||||
|
|
||||||
/* Group sections by containing article */
|
/* Group sections by containing article */
|
||||||
const groups = this.index.search(query)
|
const groups = this.index.search(query)
|
||||||
@ -223,6 +215,16 @@ export class Search {
|
|||||||
return fn(this.documents.get(section.ref) as SectionDocument)
|
return fn(this.documents.get(section.ref) as SectionDocument)
|
||||||
})
|
})
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
/* Log errors to console (for now) */
|
||||||
|
} catch (err) {
|
||||||
|
// tslint:disable-next-line no-console
|
||||||
|
console.warn(`Invalid query: ${query} – see https://bit.ly/2s3ChXG`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Return nothing in case of error or empty query */
|
||||||
|
return []
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user