Skip to content

Commit

Permalink
IBX-7236: Suggestions only work with entire words (#37)
Browse files Browse the repository at this point in the history
* Fixed min search query lenght in autocomplete

* Added asterix to search query

* Fixed strlen to mb_strlen

* Fixed phpstan

* Added wildcards on both ends of token

* Fixed query wildcard

---------

Co-authored-by: Krzysztof Słomka <[email protected]>
Co-authored-by: Maciej Kobus <[email protected]>
  • Loading branch information
3 people authored Jan 8, 2024
1 parent f252988 commit 740d01f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/bundle/Controller/SuggestionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace Ibexa\Bundle\Search\Controller;

use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface;
use Ibexa\Search\Model\SuggestionQuery;
use Ibexa\Search\Service\SuggestionService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
Expand All @@ -17,14 +18,23 @@ final class SuggestionController extends AbstractController
{
private SuggestionService $suggestionService;

private ConfigResolverInterface $configResolver;

public function __construct(
SuggestionService $suggestionService
SuggestionService $suggestionService,
ConfigResolverInterface $configResolver
) {
$this->suggestionService = $suggestionService;
$this->configResolver = $configResolver;
}

public function suggestAction(SuggestionQuery $suggestionQuery): JsonResponse
{
$minQueryLength = $this->configResolver->getParameter('search.suggestion.min_query_length');
if (mb_strlen($suggestionQuery->getQuery()) < $minQueryLength) {
return $this->json([]);
}

$result = $this->suggestionService->suggest($suggestionQuery);

return $this->json($result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function onBuildSuggestionCollectionEvent(

$query = new Query(
[
'query' => new Query\Criterion\FullText($value),
'query' => new Query\Criterion\FullText($value . '*'),
'limit' => $limit,
]
);
Expand Down
1 change: 1 addition & 0 deletions src/lib/View/SearchViewFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public function handleSearchForm(FilterViewBuilderParametersEvent $event): void
if (!empty($search['section'])) {
$section = $this->sectionService->loadSection($search['section']);
}

if (!empty($search['content_types']) && \is_array($search['content_types'])) {
foreach ($search['content_types'] as $identifier) {
$contentTypes[] = $this->contentTypeService->loadContentTypeByIdentifier($identifier);
Expand Down

0 comments on commit 740d01f

Please sign in to comment.