remove direct chnuk search. only vector search

This commit is contained in:
team 1
2026-02-18 15:52:06 +01:00
parent ce03c65aca
commit b6e7c7cbab
2 changed files with 47 additions and 5 deletions

View File

@@ -0,0 +1,39 @@
<?php
declare(strict_types=1);
namespace App\Knowledge;
final readonly class QueryCleaner
{
public function __construct(
private StopWords $stopWords
) {
}
public function clean(string $query): string
{
$query = mb_strtolower($query);
$query = preg_replace('/[^\p{L}\p{N}\s]/u', ' ', $query);
$query = preg_replace('/\s+/u', ' ', $query);
$query = trim($query);
if ($query === '') {
return '';
}
$tokens = explode(' ', $query);
$stopWords = $this->stopWords->getStopWords(); // <-- wichtig: nutzt deine Klasse
$filtered = array_filter(
$tokens,
function (string $word) use ($stopWords): bool {
return $word !== ''
&& mb_strlen($word) > 2
&& !in_array($word, $stopWords, true);
}
);
return implode(' ', $filtered);
}
}