fuzzy search in thread

This commit is contained in:
JM 2026-04-22 20:19:09 +02:00
parent 3e2f3f9585
commit 5774879331
2 changed files with 54 additions and 40 deletions

View File

@ -377,6 +377,7 @@ class SearchController extends ListDiscussionsController
} }
if ($this->matchWords) { if ($this->matchWords) {
$should->add((new MatchQuery('content', $search))->operator('and')->boost(1.8 * $boost), 'should'); $should->add((new MatchQuery('content', $search))->operator('and')->boost(1.8 * $boost), 'should');
$should->add((new MatchQuery('content.autocomplete', $search))->operator('and')->boost(0.30 * $boost), 'should');
} }
return $should; return $should;

View File

@ -581,29 +581,42 @@ HELP;
]; ];
} }
$contentMapping = [
'type' => 'text',
'analyzer' => 'flarum_analyzer',
];
// Only add the autocomplete subfield for non-CJK languages.
if ($language !== 'cjk') {
$contentMapping['fields'] = [
'autocomplete' => [
'type' => 'text',
'analyzer' => 'flarum_title_autocomplete',
'search_analyzer' => 'flarum_title_search',
],
];
}
return [ return [
'_meta' => ['index_compat_version' => self::INDEX_COMPAT_VERSION], '_meta' => ['index_compat_version' => self::INDEX_COMPAT_VERSION],
'properties' => [ 'properties' => [
'join_field' => ['type' => 'join', 'relations' => ['discussion' => 'post']], 'join_field' => ['type' => 'join', 'relations' => ['discussion' => 'post']],
'discussion_id' => ['type' => 'integer'], 'discussion_id' => ['type' => 'integer'],
'content' => ['type' => 'text', 'analyzer' => 'flarum_analyzer'], 'content' => $contentMapping,
'title' => $titleMapping, 'title' => $titleMapping,
'rawId' => ['type' => 'integer'], 'rawId' => ['type' => 'integer'],
'created_at' => ['type' => 'date'], 'created_at' => ['type' => 'date'],
'updated_at' => ['type' => 'date'], 'updated_at' => ['type' => 'date'],
'is_private' => ['type' => 'boolean'], 'is_private' => ['type' => 'boolean'],
'is_sticky' => ['type' => 'boolean'], 'user_id' => ['type' => 'integer'],
'groups' => ['type' => 'integer'], 'groups' => ['type' => 'keyword'],
'tags' => ['type' => 'integer'],
'recipient_groups' => ['type' => 'integer'],
'recipient_users' => ['type' => 'integer'],
'comment_count' => ['type' => 'integer'], 'comment_count' => ['type' => 'integer'],
'view_count' => ['type' => 'integer'], 'tags' => ['type' => 'keyword'],
'is_sticky' => ['type' => 'boolean'],
'is_hidden' => ['type' => 'boolean'], 'is_hidden' => ['type' => 'boolean'],
], ],
]; ];
} }
/** /**
* Query ES for rawIds already indexed in $targetIndex for the given $joinRelation and ID range. * Query ES for rawIds already indexed in $targetIndex for the given $joinRelation and ID range.
* Retries on transient ES failures (NoNodesAvailableException / other ElasticsearchException) * Retries on transient ES failures (NoNodesAvailableException / other ElasticsearchException)