We are using a 3rd party custom module with Magento 2.4 to improve frontend default search feature’s UI. UI is improved with that but, search results are questionable.
For example lets say there are 3 products in store having text ‘Body’ , in SQL which matches to LIKE '%Body%'
.
When search text is just ‘bo’ it returns matching results. It returns results for search text ‘body’ also, but no matched results for search text ‘bod’- it returns empty resultset in last case, its not only with search texts of length of 3, it happens at different lengths, different texts.
The product filtration function from relevant model is given below. Can someone please suggest a way to improve this to work similar to a typical LIKE '%search text%'
search.
<?php
...
protected function getProductCollection($queryText)
{
$productResultNumber = $this->helperData->getProductResultNumber();
$this->layerResolver->create(LayerResolver::CATALOG_LAYER_SEARCH);
$productCollection = $this->layerResolver->get()
->getProductCollection()
->addAttributeToSelect(
[ProductFields::DESCRIPTION, ProductFields::SHORT_DESCRIPTION]
)
->setPageSize($productResultNumber)
->addSearchFilter($queryText);
$request = $this->objectManager->get('MagentoFrameworkAppRequestHttp');
if ($catId = $request->getParam('cat')) {
$cat = $this->objectManager->get(MagentoCatalogApiCategoryRepositoryInterface::class)->get($catId);
$productCollection->addCategoryFilter($cat);
}
return $productCollection;
}
...
?>
Thanks and Best Regards
Indunil