From 0d51e5d9121b85b60f95c3f0821e1bdcc6080472 Mon Sep 17 00:00:00 2001 From: Daniel Klabbers Date: Tue, 14 Dec 2021 12:05:27 +0100 Subject: [PATCH] feat: add partial word match with low weighting --- src/Api/Controllers/SearchController.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Api/Controllers/SearchController.php b/src/Api/Controllers/SearchController.php index 9bd9ae7..57b03b8 100644 --- a/src/Api/Controllers/SearchController.php +++ b/src/Api/Controllers/SearchController.php @@ -57,7 +57,8 @@ class SearchController extends ListDiscussionsController if (! empty($search)) { $filterQuery ->add($this->sentenceMatch($search)) - ->add($this->wordMatch($search)); + ->add($this->wordMatch($search)) + ->add($this->partialMatch($search)); } $builder = (new Builder($this->elastic)) @@ -198,9 +199,13 @@ class SearchController extends ListDiscussionsController protected function wordMatch(string $q) { - return (new MatchQuery('content', $q))->boost(.3); + return (new MatchQuery('content', $q))->boost(.5); } + protected function partialMatch(string $q) + { + return (new MatchQuery('content', "*$q*"))->boost(.2); + } protected function getGroups(User $actor): Collection {