Change filtering query

Help for integrating the Laravel package
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
v.ananiev
Posts: 4
Joined: 24 Nov 2019, 02:28

Change filtering query

Post by v.ananiev » 10 Dec 2019, 23:36

Hello!

We are trying to find a way to change how filtering for our shop work. As much as I can guess, by default it splits the typed string to all words, ignores all that are 2 characters or less, and searches with "%word-one% OR %word-two% OR ... ". This logic doesn't work well when, for example, we type something like "Apple iPhone 7" or "Samsung Galaxy S9" because we get results for other products that contain at least one of the words in the searched string.

Could you please help with ideas or ways to change how the filtering works?

Thank you in advance!

User avatar
aimeos
Administrator
Posts: 8027
Joined: 01 Jan 1970, 00:00

Re: Change filtering query

Post by aimeos » 11 Dec 2019, 15:34

Aimeos uses standard MySQL full text search by default (or the one offered by PosgreSQL) which is similar to:

Code: Select all

"Samsung%" OR "Galaxy%" OR "S9%"
Product texts matching all or more than one word are ranked higher but MySQL skips word with 3 chars or less, so "S9" won't be used at all (depends on the MySQL server config).

If you need exact matchs, you can use the "Standard" text index manager:
https://github.com/aimeos/aimeos-core/b ... andard.php
Configuration:

Code: Select all

'mshop' => array(
    'index' => array(
        'manager' => array(
            'text' => array(
                'name' => 'Standard',
            ),
        ),
    ),
),
Be aware that MySQL is unable to use indexes then and your search will be painfully slow if you have a lot of products!

If you need a better full text search which is fast too, then have a look at Solr and the Solr extension from the Aimeos company:
https://aimeos.com/extensions#c606
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

v.ananiev
Posts: 4
Joined: 24 Nov 2019, 02:28

Re: Change filtering query

Post by v.ananiev » 12 Dec 2019, 00:02

Thank you for the answer!

That throws some light on how things work exactly.

If these are the only options, the default will have to do, as the "Standard" configuration actually didn't return any products even when trying with copying the exact name of a product and searching with it.

Do you think an extension to the Index/Manage/Text/Standard class could be made that is configured to search by "mindte.value LIKE '%Some phrase or something%' "? I think this will be the ideal way for our case - at least for what our client wants.

Thank you very much again!

User avatar
aimeos
Administrator
Posts: 8027
Joined: 01 Jan 1970, 00:00

Re: Change filtering query

Post by aimeos » 12 Dec 2019, 14:59

You can create your own full text search creating a new text index manager, inheriting from the standard class and overwrite these lines: https://github.com/aimeos/aimeos-core/b ... p#L59-L108
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

v.ananiev
Posts: 4
Joined: 24 Nov 2019, 02:28

Re: Change filtering query

Post by v.ananiev » 17 Dec 2019, 05:42

Hello again and sorry for asking stupid questions once more.

When inspecting the query that is generated in the end by looking at the mysql general log, for the part where the exact search term is replaced

Code: Select all

POSITION( $3 IN mindte2."value" ) > 0 
, it goes in like

Code: Select all

POSITION( ' +Apple* +iPhone* 7*' IN mindte2.`value` ) > 0 
We are currently using 2018.04 version of Aimeos, and as far as I can see, in newer versions this file class doesn't even exist there since 2018.10 version. (https://github.com/aimeos/aimeos-core/b ... /MySQL.php)

So, without updating to newer version, my only option is to extend the Standard Text Manager class and modify the query. Does it matter where exactly the extending class is placed within the project? And is this the way that the config should look like?

Code: Select all

 
'mshop' => [
    'index' => array(
        'manager' => array(
            'text' => array(
                'name' => 'Path\To\CustomStandard',
            ),
        ),
    ),
],
 

User avatar
aimeos
Administrator
Posts: 8027
Joined: 01 Jan 1970, 00:00

Re: Change filtering query

Post by aimeos » 17 Dec 2019, 15:26

In 2018.10, the code has been moved to the text index manager:
https://github.com/aimeos/aimeos-core/b ... p#L80-L101

If you need to create your own custom index manager, file location matters. If you configure this:

Code: Select all

'mshop' => [
    'index' => array(
        'manager' => array(
            'text' => array(
                'name' => 'MyProject',
            ),
        ),
    ),
],
 
Then, your custom manager must be in

Code: Select all

./ext/<yourext>/lib/custom/src/MShop/Index/Manager/Text/MyProject.php
Please note that 2018.04 isn't supported any more at all and 2018.10 only by the extended LTS program of the Aimeos company:
https://aimeos.com/support#c428
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply