Search Suggest Route settings and customise

Hi. We are running a Shopware installation v6.2.3. There is a Search feature on the site with Suggested results shown in dropdown. The dropdown currently holds 10 results but we would like to increase this, there is no where in the documentation to show where this limit of 10 is set. Firstly is it possible to increase this limit. Also, we would like to filter on the search result list to prevent a specific set of products from showing and possibly have the results in some order. We are using the SuggestPageLoader from SW Core - Is it possible to add a filter and sorting to the suggest page loader (overriding the class with our own custom class). The core code is this:

public function load(Request $request, SalesChannelContext $salesChannelContext): SuggestPage
{
$page = $this->genericLoader->load($request, $salesChannelContext);

    $page = SuggestPage::createFrom($page);

    $page->setSearchResult($this->productSuggestRoute->load($request, $salesChannelContext)->getListingResult());

    $page->setSearchTerm($request->query->get('search'));

    $this->eventDispatcher->dispatch(
        new SuggestPageLoadedEvent($page, $salesChannelContext, $request)
    );

    return $page;
}

}

I also want to add that I have looked at the Admin dashboard settings page and we have no „Search“ settings option - which i have seen being used on some YouTube videos on the subject. Is there something missing in our installation?

Ok, so i have sorted out Filtering using an Event Subscriber for Product Suggestion criteria and adding the neccessary filter on the search.

Hey there, i know this post is a bit old but do you happen to have the solution laying around? I’m struggling with adding filters for the product suggestion and would appreciate if you’d share your solution.

I made a custom product listing loader (not exactly 100% sure if it’s the correct way).
I had to duplicate basically the whole loading function because of private functions.

        <service id="TwoMoons\Decorator\ProductListingLoaderDecorator" decorates="Shopware\Core\Content\Product\SalesChannel\Listing\ProductListingLoader">
            <argument type="service" id="TwoMoons\Decorator\ProductListingLoaderDecorator.inner"/>
            <argument type="service" id="twomoons.logger" />
            <argument type="service" id="sales_channel.product.repository"/>
            <argument type="service" id="Shopware\Core\System\SystemConfig\SystemConfigService" />
            <argument type="service" id="Shopware\Core\Content\Product\SalesChannel\ProductCloseoutFilterFactory" />
            <argument type="service" id="Symfony\Component\HttpFoundation\RequestStack"/>
        </service>
class ProductListingLoaderDecorator extends ProductListingLoader
{
    private $decoratedService;
    private LoggerInterface $logger;
    private readonly SalesChannelRepository $productRepository;
    private readonly SystemConfigService $systemConfigService;
    private readonly AbstractProductCloseoutFilterFactory $productCloseoutFilterFactory;

    public function __construct(
        #[AutowireDecorated]
        ProductListingLoader $decoratedService,
        LoggerInterface $logger,
        SalesChannelRepository $productRepository,
        SystemConfigService $systemConfigService,
        AbstractProductCloseoutFilterFactory $productCloseoutFilterFactory,
        RequestStack $requestStack
        
        )
    {
        $this->decoratedService = $decoratedService;
        $this->logger = $logger;
        $this->productRepository = $productRepository;

        $this->systemConfigService = $systemConfigService;
        $this->productCloseoutFilterFactory = $productCloseoutFilterFactory;
        $this->requestStack = $requestStack;
        
    }

    public function load(Criteria $criteria, SalesChannelContext $context): EntitySearchResult
    {
        $request = $this->requestStack->getCurrentRequest();
        if (!$request) {
            return $this->decoratedService->load($criteria, $context);
        }
        // Check by route name
        $routeName = $request->attributes->get('resolved-uri');

        if ($routeName == '/suggest') {
            $criteria->setLimit(25); // displays 25 items
        }

        $this->handleAvailableStock($criteria, $context);

        $ids = $this->productRepository->searchIds($criteria, $context);
        $aggregations = $this->productRepository->aggregate($criteria, $context);
        $searchResult = $this->productRepository->search($criteria, $context);

        $result = new EntitySearchResult(ProductDefinition::ENTITY_NAME, $ids->getTotal(), $searchResult->getEntities(), $aggregations, $criteria, $context->getContext());
        $result->addState(...$ids->getStates());

        return $result;


maybe this helps :slight_smile: I used it to only display 5 results, to make the search results bigger