diff --git a/src/Api/Controllers/SearchController.php b/src/Api/Controllers/SearchController.php index 6c5f82c..12fa40c 100644 --- a/src/Api/Controllers/SearchController.php +++ b/src/Api/Controllers/SearchController.php @@ -294,12 +294,31 @@ class SearchController extends ListDiscussionsController return $discussions; } - protected function buildAutocompleteQuery(string $search): MatchQuery - { - return (new MatchQuery('title.autocomplete', $search)) - ->operator('and') - ->boost(1.0); - } + + protected function buildAutocompleteQuery(string $search): BoolQuery + { + $query = BoolQuery::create(); + + // Title prefix match (stronger) + $query->add( + (new MatchQuery('title.autocomplete', $search)) + ->operator('and') + ->boost(1.0), + 'should' + ); + + // Content prefix match (weaker) + $query->add( + (new MatchQuery('content.autocomplete', $search)) + ->operator('and') + ->boost(0.4), + 'should' + ); + + $query->minimumShouldMatch(1); + + return $query; + } /** * Build the text-matching portion of the query.