0

I'm using Order's increment ID in the search by keyword field to get the search results. However, it only works with 00000XXXX and not by XXXX. Search by keyword is using Fulltext searching but how to get the results with the like query?

enter image description here

enter image description here

Please share the solution.

1
  • I don't have any solution for this (right now) but I will soon have to customize that searching process too. If you find any solution I would be glad to see it. From what I've seen the todo task will be to declare a new index that the search will use + extends pieces of ui components. Not an easy task I would say at least 1 work day from scratch ? That being said, I found strange the behaviour you have. I think it's due to a miss configuration you may have cause id are integers and should not have these 0 before which explain whe the search don't catch them. Yours ids looks like increment ids
    – Claims
    Feb 28, 2022 at 16:54

1 Answer 1

3

Yes, I just reached the full-text search file at the below class path.

Magento\Framework\View\Element\UiComponent\DataProvider\FulltextFilter.php

There is one apply(Collection $collection, Filter $filter) function is using MATCH() AGAINST SQL Query.

Important part of the function :

$collection->getSelect()
        ->where(
            'MATCH(' . implode(',', $columns) . ') AGAINST(?)',
            $this->escapeAgainstValue($filter->getValue())
        );

In order to use the LIKE SQL query, we have to replace this important part with the like query like below.

$whereCondition = '';
        foreach ($columns as $key => $field) {
            $condition = $field . " LIKE '%".$filter->getValue()."%'";
            $whereCondition .= ($key === 0 ? '' : ' OR ') . $condition;
        }
        $collection->getSelect()->where($whereCondition);

This will change the whole search collection query with filters MATCH AGAINST to LIKE clause query.

I hope this comes helpful to anyone in the future.

ALL I MENTIONED IS THE VENDOR FILE. PLEASE MAKE SURE TO OVERRIDE THE FILE IN THE CUSTOM MODULE.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.