Frag das Portal durchsucht alles, neue Demo-Inhalte (0.66.0)
All checks were successful
CI / PHP 8.3 / mariadb:10.6 (pull_request) Has been skipped
CI / PHP 8.4 / mariadb:10.6 (pull_request) Has been skipped
CI / PHP 8.3 / mariadb:11.4 (pull_request) Has been skipped
CI / PHP 8.4 / mariadb:11.4 (pull_request) Has been skipped
CI / PHP 8.3 / mysql:8.0 (pull_request) Has been skipped
CI / PHP 8.4 / mysql:8.0 (pull_request) Has been skipped
CI / PHP 8.3 / mysql:8.4 (pull_request) Has been skipped
CI / PHP 8.4 / mysql:8.4 (pull_request) Has been skipped
CI / Browser-Tests (pull_request) Successful in 8m33s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 9m8s
CI / PHP 8.3 / mysql:8.4-1 (pull_request) Successful in 17m55s
CI / Build-Artefakte aktuell (pull_request) Successful in 9m50s

- Wissensquellen: Termine, Downloads, Formulare, Stellen, Ideen, Umfragen,
  Personen, eigene IT-Tickets/Geräte (OpenNIT, je Anfrage zwischengespeichert)
- Ranking mit IDF, Abfrage je Begriff, Abkürzungen als ganze Wörter,
  LIKE unabhängig von Groß-/Kleinschreibung (JSON-Spalten), Datum im Prompt
- Demo-Inhalte für einen Träger der Eingliederungshilfe (DemoData),
  mehrseitige PDFs, vorhandene Inhalte je Bereich entfernen

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Friederich Loheide 2026-10-07 20:01:00 +00:00
parent 1656cd8090
commit 3addc09c38
165 changed files with 2258 additions and 814 deletions

View file

@ -6,6 +6,7 @@ use App\Models\User;
use App\Plugins\PluginAccess;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Query\Builder as QueryBuilder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Throwable;
@ -67,7 +68,24 @@ class Knowledge
}
try {
foreach (array_slice(($source['search'])($user, $terms, $perSource), 0, $perSource) as $hit) {
// Einmal mit allen Begriffen, dazu je Begriff ein paar Treffer – sonst verdrängt ein
// häufiges Wort („Werkstatt“) die wenigen Einträge mit dem entscheidenden („Sammelplatz“)
$hits = array_slice(($source['search'])($user, $terms, $perSource), 0, $perSource);
if (count($terms) > 1) {
foreach ($terms as $term) {
$hits = [...$hits, ...array_slice(($source['search'])($user, [$term], 3), 0, 3)];
}
}
$seen = [];
foreach ($hits as $hit) {
if (isset($seen[$hit['url'].'|'.$hit['title']])) {
continue;
}
$seen[$hit['url'].'|'.$hit['title']] = true;
$documents[] = [
'source' => $key,
'label' => $source['label'],
@ -100,15 +118,48 @@ class Knowledge
{
return $query->where(function ($q) use ($columns, $terms) {
foreach ($terms as $term) {
// Kurze Begriffe („it“, „qm“) nur als ganzes Wort – sonst fände „it“ jedes „mit“
if (self::isShort($term)) {
$pattern = '(^|[^[:alnum:]])'.preg_quote($term).'([^[:alnum:]]|$)';
foreach ($columns as $column) {
$q->orWhereRaw(self::lowered($column).' REGEXP ?', [$pattern]);
}
continue;
}
$like = '%'.str_replace(['\\', '%', '_'], ['\\\\', '\\%', '\\_'], $term).'%';
foreach ($columns as $column) {
$q->orWhere($column, 'like', $like);
$q->orWhereRaw(self::lowered($column).' LIKE ?', [$like]);
}
}
});
}
/**
* Spalte klein geschrieben als Text – JSON-Spalten (z. B. Inhalte aus dem Baukasten) haben eine
* binäre Sortierung, dort wäre LIKE sonst groß-/kleinschreibungsabhängig.
*/
private static function lowered(string $column): string
{
return 'LOWER(CAST('.DB::getQueryGrammar()->wrap($column).' AS CHAR))';
}
public static function isShort(string $term): bool
{
return mb_strlen($term) <= 3;
}
/** Wie oft kommt der Begriff vor? Kurze Begriffe nur als ganzes Wort. */
public static function occurrences(string $haystack, string $term): int
{
return self::isShort($term)
? (int) preg_match_all('/(?<![\p{L}\p{N}])'.preg_quote($term, '/').'(?![\p{L}\p{N}])/u', $haystack)
: mb_substr_count($haystack, $term);
}
/** HTML in lesbaren Klartext (Absätze bleiben als Zeilenumbrüche erhalten) */
public static function plain(?string $html): string
{