fix: Improve multi-partial word matching in search
This commit is contained in:
@@ -416,12 +416,8 @@ export default class SearchHelper {
|
|||||||
// limit length of search queries as we're using regex against untrusted input
|
// limit length of search queries as we're using regex against untrusted input
|
||||||
let limitedQuery = this.escapeQuery(query.slice(0, this.maxQueryLength));
|
let limitedQuery = this.escapeQuery(query.slice(0, this.maxQueryLength));
|
||||||
|
|
||||||
// if the search term is one unquoted word then allow partial matches automatically
|
const quotedSearch =
|
||||||
const queryWordCount = limitedQuery.split(" ").length;
|
limitedQuery.startsWith('"') && limitedQuery.endsWith('"');
|
||||||
const singleUnquotedSearch =
|
|
||||||
queryWordCount === 1 &&
|
|
||||||
!limitedQuery.startsWith('"') &&
|
|
||||||
!limitedQuery.endsWith('"');
|
|
||||||
|
|
||||||
// Replace single quote characters with &.
|
// Replace single quote characters with &.
|
||||||
const singleQuotes = limitedQuery.matchAll(/'+/g);
|
const singleQuotes = limitedQuery.matchAll(/'+/g);
|
||||||
@@ -440,7 +436,7 @@ export default class SearchHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
queryParser()(singleUnquotedSearch ? `${limitedQuery}*` : limitedQuery)
|
queryParser()(quotedSearch ? limitedQuery : `${limitedQuery}*`)
|
||||||
// Remove any trailing join characters
|
// Remove any trailing join characters
|
||||||
.replace(/&$/, "")
|
.replace(/&$/, "")
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user