From ab7a4bb1aa4abe85ad86e14376a5f400d73b2df3 Mon Sep 17 00:00:00 2001 From: Tobias Krais Date: Tue, 24 Nov 2020 12:44:36 +0100 Subject: [PATCH 1/4] =?UTF-8?q?Soundex=20nur=20ausf=C3=BChren=20wenn=20nic?= =?UTF-8?q?ht=20numerisch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Siehe https://github.com/FriendsOfREDAXO/search_it/issues/300#issuecomment-732879280 --- lib/search_it.php | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/lib/search_it.php b/lib/search_it.php index ec6d7c1..330812d 100644 --- a/lib/search_it.php +++ b/lib/search_it.php @@ -2134,7 +2134,7 @@ function search($_search) $simwordQuerys = []; foreach ($this->searchArray as $keyword) { $sounds = []; - if ($this->similarwordsMode & SEARCH_IT_SIMILARWORDS_SOUNDEX) { + if ($this->similarwordsMode & SEARCH_IT_SIMILARWORDS_SOUNDEX && !is_numeric(soundex($keyword['search']))) { $sounds[] = "soundex = '" . soundex($keyword['search']) . "'"; } @@ -2145,20 +2145,22 @@ function search($_search) if ($this->similarwordsMode & SEARCH_IT_SIMILARWORDS_COLOGNEPHONE) { $sounds[] = "colognephone = '" . soundex_ger($keyword['search']) . "'"; } - $simwordQuerys[] = sprintf(" - (SELECT - GROUP_CONCAT(DISTINCT keyword SEPARATOR ' ') as keyword, - %s AS typedin, - SUM(count) as count - FROM `%s` - WHERE 1 - %s - AND (%s))", - $simWordsSQL->escape($keyword['search']), - self::getTempTablePrefix() . 'search_it_keywords', - ($this->clang !== false) ? 'AND (clang = ' . intval($this->clang) . ' OR clang IS NULL)' : '', - implode(' OR ', $sounds) - ); + if(count($sounds) > 0) { + $simwordQuerys[] = sprintf(" + (SELECT + GROUP_CONCAT(DISTINCT keyword SEPARATOR ' ') as keyword, + %s AS typedin, + SUM(count) as count + FROM `%s` + WHERE 1 + %s + AND (%s))", + $simWordsSQL->escape($keyword['search']), + self::getTempTablePrefix() . 'search_it_keywords', + ($this->clang !== false) ? 'AND (clang = ' . intval($this->clang) . ' OR clang IS NULL)' : '', + implode(' OR ', $sounds) + ); + } } //echo '
'; var_dump($simwordQuerys);echo '
'; // Eine SQL-Abfrage pro Suchwort From f40ea2e89e303898796290036cd290b85535057e Mon Sep 17 00:00:00 2001 From: Tobias Krais Date: Tue, 24 Nov 2020 12:49:48 +0100 Subject: [PATCH 2/4] Soundex nicht bei Nummern verwenden --- lib/search_it.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/search_it.php b/lib/search_it.php index 330812d..4e42117 100644 --- a/lib/search_it.php +++ b/lib/search_it.php @@ -2049,7 +2049,7 @@ private function storeKeywords($_keywords, $_doCount = true) $simWords[] = sprintf( "(%s, '%s', '%s', '%s', %s)", $simWordsSQL->escape($keyword['search']), - ($this->similarwordsMode & SEARCH_IT_SIMILARWORDS_SOUNDEX) ? soundex($keyword['search']) : '', + ($this->similarwordsMode & SEARCH_IT_SIMILARWORDS_SOUNDEX && !is_numeric(soundex($keyword['search']))) ? soundex($keyword['search']) : '', ($this->similarwordsMode & SEARCH_IT_SIMILARWORDS_METAPHONE) ? metaphone($keyword['search']) : '', ($this->similarwordsMode & SEARCH_IT_SIMILARWORDS_COLOGNEPHONE) ? soundex_ger($keyword['search']) : '', (isset($keyword['clang']) AND $keyword['clang'] !== false) ? $keyword['clang'] : '-1' From 2a423bb83bf1179f37c33bfea43fbc9a15ffa18c Mon Sep 17 00:00:00 2001 From: Tobias Krais Date: Tue, 24 Nov 2020 12:59:54 +0100 Subject: [PATCH 3/4] Fehlerbehebung wenn nur eine Zahl eingegeben wird --- lib/search_it.php | 76 ++++++++++++++++++++++++----------------------- 1 file changed, 39 insertions(+), 37 deletions(-) diff --git a/lib/search_it.php b/lib/search_it.php index 4e42117..e708663 100644 --- a/lib/search_it.php +++ b/lib/search_it.php @@ -2165,43 +2165,45 @@ function search($_search) //echo '
'; var_dump($simwordQuerys);echo '
'; // Eine SQL-Abfrage pro Suchwort // simwords - $simWordsSQL = rex_sql::factory(); - foreach ($simWordsSQL->getArray(sprintf(" - SELECT * FROM (%s) AS t - %s - ORDER BY count", - implode(' UNION ', $simwordQuerys), - $this->similarwordsPermanent ? '' : 'GROUP BY keyword, typedin' - ) - ) as $simword) { - //echo '
'; var_dump($simword);echo '
'; - $return['simwords'][$simword['typedin']] = array( - 'keyword' => $simword['keyword'], - 'typedin' => $simword['typedin'], - 'count' => $simword['count'], - ); - } - /*echo '
' .sprintf("
-            SELECT * FROM (%s) AS t
-            %s
-            ORDER BY count",
-                implode(' UNION ', $simwordQuerys),
-                $this->similarwordsPermanent ? '' : 'GROUP BY keyword, typedin'
-            ).'
'; die();*/ - $newsearch = []; - foreach ($this->searchArray as $keyword) { - if (preg_match('~\s~isu', $keyword['search'])) { - $quotes = '"'; - } else { - $quotes = ''; - } + if(count($simwordQuerys) > 0) { + $simWordsSQL = rex_sql::factory(); + foreach ($simWordsSQL->getArray(sprintf(" + SELECT * FROM (%s) AS t + %s + ORDER BY count", + implode(' UNION ', $simwordQuerys), + $this->similarwordsPermanent ? '' : 'GROUP BY keyword, typedin' + ) + ) as $simword) { + //echo '
'; var_dump($simword);echo '
'; + $return['simwords'][$simword['typedin']] = array( + 'keyword' => $simword['keyword'], + 'typedin' => $simword['typedin'], + 'count' => $simword['count'], + ); + } + /*echo '
' .sprintf("
+				SELECT * FROM (%s) AS t
+				%s
+				ORDER BY count",
+					implode(' UNION ', $simwordQuerys),
+					$this->similarwordsPermanent ? '' : 'GROUP BY keyword, typedin'
+				).'
'; die();*/ + $newsearch = []; + foreach ($this->searchArray as $keyword) { + if (preg_match('~\s~isu', $keyword['search'])) { + $quotes = '"'; + } else { + $quotes = ''; + } - if (array_key_exists($keyword['search'], $return['simwords'])) { - $newsearch[] = $quotes . $return['simwords'][$keyword['search']]['keyword'] . $quotes; - } else { - $newsearch[] = $quotes . $keyword['search'] . $quotes; - } - } + if (array_key_exists($keyword['search'], $return['simwords'])) { + $newsearch[] = $quotes . $return['simwords'][$keyword['search']]['keyword'] . $quotes; + } else { + $newsearch[] = $quotes . $keyword['search'] . $quotes; + } + } + } $return['simwordsnewsearch'] = implode(' ', $newsearch); } @@ -2280,7 +2282,7 @@ function search($_search) $match = '(' . implode(' + ', $Amatch) . ' + 1)'; // build WHERE-String - $where = '(' . implode($this->logicalMode, $A2Where) . ')'; + $where = count($A2Where) > 0 ? '(' . implode($this->logicalMode, $A2Where) . ')' : '1'; //$where = sprintf("( MATCH (%s) AGAINST ('%s' IN BOOLEAN MODE)) > 0",implode(',',$searchColumns),implode(' ',$Awhere)); // language From afa4f8d54d99e6423bc327947afcc9788c2fc695 Mon Sep 17 00:00:00 2001 From: Tobias Krais Date: Tue, 24 Nov 2020 13:25:33 +0100 Subject: [PATCH 4/4] Finale Fehlerbehebungen --- lib/search_it.php | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/lib/search_it.php b/lib/search_it.php index e708663..9d85283 100644 --- a/lib/search_it.php +++ b/lib/search_it.php @@ -2051,7 +2051,7 @@ private function storeKeywords($_keywords, $_doCount = true) $simWordsSQL->escape($keyword['search']), ($this->similarwordsMode & SEARCH_IT_SIMILARWORDS_SOUNDEX && !is_numeric(soundex($keyword['search']))) ? soundex($keyword['search']) : '', ($this->similarwordsMode & SEARCH_IT_SIMILARWORDS_METAPHONE) ? metaphone($keyword['search']) : '', - ($this->similarwordsMode & SEARCH_IT_SIMILARWORDS_COLOGNEPHONE) ? soundex_ger($keyword['search']) : '', + ($this->similarwordsMode & SEARCH_IT_SIMILARWORDS_COLOGNEPHONE && !is_numeric(soundex($keyword['search']))) ? soundex_ger($keyword['search']) : '', (isset($keyword['clang']) AND $keyword['clang'] !== false) ? $keyword['clang'] : '-1' ); } @@ -2134,18 +2134,18 @@ function search($_search) $simwordQuerys = []; foreach ($this->searchArray as $keyword) { $sounds = []; - if ($this->similarwordsMode & SEARCH_IT_SIMILARWORDS_SOUNDEX && !is_numeric(soundex($keyword['search']))) { + if ($this->similarwordsMode && SEARCH_IT_SIMILARWORDS_SOUNDEX && !is_numeric(soundex($keyword['search']))) { $sounds[] = "soundex = '" . soundex($keyword['search']) . "'"; } - if ($this->similarwordsMode & SEARCH_IT_SIMILARWORDS_METAPHONE) { + if ($this->similarwordsMode && SEARCH_IT_SIMILARWORDS_METAPHONE) { $sounds[] = "metaphone = '" . metaphone($keyword['search']) . "'"; } - if ($this->similarwordsMode & SEARCH_IT_SIMILARWORDS_COLOGNEPHONE) { + if ($this->similarwordsMode && SEARCH_IT_SIMILARWORDS_COLOGNEPHONE && !is_numeric(soundex($keyword['search']))) { $sounds[] = "colognephone = '" . soundex_ger($keyword['search']) . "'"; } - if(count($sounds) > 0) { + if(!empty($sounds)) { $simwordQuerys[] = sprintf(" (SELECT GROUP_CONCAT(DISTINCT keyword SEPARATOR ' ') as keyword, @@ -2161,11 +2161,11 @@ function search($_search) implode(' OR ', $sounds) ); } - } + } //echo '
'; var_dump($simwordQuerys);echo '
'; // Eine SQL-Abfrage pro Suchwort // simwords - if(count($simwordQuerys) > 0) { + if(!empty($simwordQuerys)) { $simWordsSQL = rex_sql::factory(); foreach ($simWordsSQL->getArray(sprintf(" SELECT * FROM (%s) AS t @@ -2203,10 +2203,9 @@ function search($_search) $newsearch[] = $quotes . $keyword['search'] . $quotes; } } + $return['simwordsnewsearch'] = implode(' ', $newsearch); } - - $return['simwordsnewsearch'] = implode(' ', $newsearch); - } + } //print_r($this->searchArray);echo '

'; if ($this->similarwordsPermanent) { @@ -2282,7 +2281,7 @@ function search($_search) $match = '(' . implode(' + ', $Amatch) . ' + 1)'; // build WHERE-String - $where = count($A2Where) > 0 ? '(' . implode($this->logicalMode, $A2Where) . ')' : '1'; + $where = '(' . implode($this->logicalMode, $A2Where) . ')'; //$where = sprintf("( MATCH (%s) AGAINST ('%s' IN BOOLEAN MODE)) > 0",implode(',',$searchColumns),implode(' ',$Awhere)); // language