Jump to content

[almost SOLVED] Full text search, sub string search


grasnal

Recommended Posts

Can someone confirm that PrestaShop do not return positive search match if a searched string is a sub string of longer one? For example if I search for: "TB ST3" i want to find item with name "HDD SEAGATE 1TB ST31000528AS SATA II 32MB".

Maybe I messed something?

Link to comment
Share on other sites

I made "quick&dirty;" hack to force PrestaShop search sub string through at least product name.

This do not check product is active/inactive and visitor access right to list product (user groups). I don't have any idea is this safe at all. But it works :).

@rocky: can you help me solve above disadvantages

PrrestaShop version: 1.3.3
file: classes/Search.php
line: 185

change from:

$eligibleProducts = $db->ExecuteS('
       SELECT DISTINCT cp.`id_product`
       FROM `'._DB_PREFIX_.'category_group` cg
       INNER JOIN `'._DB_PREFIX_.'category_product` cp ON cp.`id_category` = cg.`id_category`
       INNER JOIN `'._DB_PREFIX_.'category` c ON cp.`id_category` = c.`id_category`
       INNER JOIN `'._DB_PREFIX_.'product` p ON cp.`id_product` = p.`id_product`
       WHERE c.`active` = 1 AND p.`active` = 1 
       AND cg.`id_group` '.(!$cookie->id_customer ?  '= 1' : 'IN (
           SELECT id_group FROM '._DB_PREFIX_.'customer_group
           WHERE id_customer = '.intval($cookie->id_customer).'
       )').'
       AND '.implode(' AND ', $whereArray));



to

$eligibleProducts = $db->ExecuteS('
      SELECT id_product FROM '._DB_PREFIX_.'product_lang WHERE id_lang = '.intval($id_lang).' AND name LIKE \'%'.$expr.'%\'
       UNION
       SELECT DISTINCT cp.`id_product`
       FROM `'._DB_PREFIX_.'category_group` cg
       INNER JOIN `'._DB_PREFIX_.'category_product` cp ON cp.`id_category` = cg.`id_category`
       INNER JOIN `'._DB_PREFIX_.'category` c ON cp.`id_category` = c.`id_category`
       INNER JOIN `'._DB_PREFIX_.'product` p ON cp.`id_product` = p.`id_product`
       WHERE c.`active` = 1 AND p.`active` = 1 
       AND cg.`id_group` '.(!$cookie->id_customer ?  '= 1' : 'IN (
           SELECT id_group FROM '._DB_PREFIX_.'customer_group
           WHERE id_customer = '.intval($cookie->id_customer).'
       )').'
       AND '.implode(' AND ', $whereArray));



added statment:

SELECT id_product FROM '._DB_PREFIX_.'product_lang WHERE id_lang = '.intval($id_lang).' AND name LIKE \'%'.$expr.'%\'
UNION
Link to comment
Share on other sites

  • 2 months later...
  • 5 months later...
  • 7 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...