Jump to content

[SOLVED] Excluding some features from search index


nestor44

Recommended Posts

Hi, my search index included features. I do not need to index all features. I want to index only 3 features and their values. Is it possible to exclude certain features from search index? I am using PS 8.1.5 for one shop and PS 9 for the second shop. I want to exclude some features from both shops.

Edited by nestor44
solved (see edit history)
Link to comment
Share on other sites

PrestaShop doesn't index feature names, only their values so you'll need to modify the function that retrieves just the values of the features you want. You can do it by adding an override to the Search class (sadly there are no hooks you can use). Below is an example of code you would place in override/classes/Search.php (you need to clear the cache when you add or remove files from the override directory):

 

<?php
class Search extends SearchCore {
    /**
     * @param Db $db
     * @param int $id_product
     * @param int $id_lang
     *
     * @return string
     */
    public static function getFeatures($db, $id_product, $id_lang)
    {
        if (!Feature::isFeatureActive()) {
            return '';
        }

        $features = '';
        $featuresArray = $db->executeS('
		SELECT fvl.value FROM ' . _DB_PREFIX_ . 'feature_product fp
		LEFT JOIN ' . _DB_PREFIX_ . 'feature_value_lang fvl ON (fp.id_feature_value = fvl.id_feature_value AND fvl.id_lang = ' . (int) $id_lang . ')
		WHERE fp.id_product = ' . (int) $id_product . '
        AND fp.id_feature IN (1,2,3)', true, false);
        foreach ($featuresArray as $feature) {
            $features .= $feature['value'] . ' ';
        }

        return $features;
    }
}

The above will only add the values of features with id_feature = 1, 2 or 3 (obviously you need to replace 1, 2 and 3 with the IDs of the three features you want included in search). The above override should work for any PrestaShop version from 1.6 -> 9.0 (this function hasn't changed in all that time).

  • Like 2
Link to comment
Share on other sites

  • nestor44 changed the title to [SOLVED] Excluding some features from search index

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...