From 7d7f15c4ccc3710ae1db01654c5dd4a1f3ad6127 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Fri, 8 Apr 2022 12:00:53 +0200 Subject: [PATCH] Do not add the `+` prefix to search terms matching an InnoDB stop word This is issue is effectively identical to the one fixed in commit 247d9cc51af9cd78395e2e7600bacbc2ffdf918b. --- .../search/mysql/MysqlSearchEngine.class.php | 54 ++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/wcfsetup/install/files/lib/system/search/mysql/MysqlSearchEngine.class.php b/wcfsetup/install/files/lib/system/search/mysql/MysqlSearchEngine.class.php index 5d9ab9ad28..ad31ea80b0 100644 --- a/wcfsetup/install/files/lib/system/search/mysql/MysqlSearchEngine.class.php +++ b/wcfsetup/install/files/lib/system/search/mysql/MysqlSearchEngine.class.php @@ -187,9 +187,16 @@ class MysqlSearchEngine extends AbstractSearchEngine if (!$prefix) { // Add a '+' prefix if no prefix is given, and + // the word is not a stopword, and // - the word is longer than the min token size, or // - the word is quoted. - if ($word[0] === '"' || \strlen($word) >= $this->getMinTokenSize()) { + if ( + !\in_array($word, $this->getStopWords()) + && ( + $word[0] === '"' + || \strlen($word) >= $this->getMinTokenSize() + ) + ) { $prefix = '+'; } } @@ -557,4 +564,49 @@ class MysqlSearchEngine extends AbstractSearchEngine return $this->minTokenSize; } + + /** + * @return string[] + */ + private function getStopWords(): array + { + return [ + 'a', + 'about', + 'an', + 'are', + 'as', + 'at', + 'be', + 'by', + 'com', + 'de', + 'en', + 'for', + 'from', + 'how', + 'i', + 'in', + 'is', + 'it', + 'la', + 'of', + 'on', + 'or', + 'that', + 'the', + 'this', + 'to', + 'was', + 'what', + 'when', + 'where', + 'who', + 'will', + 'with', + 'und', + 'the', + 'www', + ]; + } } -- 2.20.1