Skip to content

Commit

Permalink
Merge pull request #301 from FriendsOfREDAXO/soundex_numeric
Browse files Browse the repository at this point in the history
Soundex nicht bei Zahlen verwenden - fix #300
  • Loading branch information
tyrant88 authored Nov 24, 2020
2 parents 4705486 + afa4f8d commit 2c1e3d7
Showing 1 changed file with 62 additions and 59 deletions.
121 changes: 62 additions & 59 deletions lib/search_it.php
Original file line number Diff line number Diff line change
Expand Up @@ -2049,9 +2049,9 @@ 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']) : '',
($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'
);
}
Expand Down Expand Up @@ -2134,75 +2134,78 @@ 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']) . "'";
}

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']) . "'";
}
$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(!empty($sounds)) {
$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 '<br><pre>'; var_dump($simwordQuerys);echo '</pre>'; // 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 '<br><pre>'; var_dump($simword);echo '</pre>';
$return['simwords'][$simword['typedin']] = array(
'keyword' => $simword['keyword'],
'typedin' => $simword['typedin'],
'count' => $simword['count'],
);
}
/*echo '<br><pre>' .sprintf("
SELECT * FROM (%s) AS t
%s
ORDER BY count",
implode(' UNION ', $simwordQuerys),
$this->similarwordsPermanent ? '' : 'GROUP BY keyword, typedin'
).'</pre>'; 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(!empty($simwordQuerys)) {
$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 '<br><pre>'; var_dump($simword);echo '</pre>';
$return['simwords'][$simword['typedin']] = array(
'keyword' => $simword['keyword'],
'typedin' => $simword['typedin'],
'count' => $simword['count'],
);
}
/*echo '<br><pre>' .sprintf("
SELECT * FROM (%s) AS t
%s
ORDER BY count",
implode(' UNION ', $simwordQuerys),
$this->similarwordsPermanent ? '' : 'GROUP BY keyword, typedin'
).'</pre>'; die();*/
$newsearch = [];
foreach ($this->searchArray as $keyword) {
if (preg_match('~\s~isu', $keyword['search'])) {
$quotes = '"';
} else {
$quotes = '';
}

$return['simwordsnewsearch'] = implode(' ', $newsearch);
}
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);
}
}

//print_r($this->searchArray);echo '<br><br>';
if ($this->similarwordsPermanent) {
Expand Down

0 comments on commit 2c1e3d7

Please sign in to comment.