You are here:  » Search in alternative words category hierarchy mapping


Search in alternative words category hierarchy mapping

Submitted by wesse249 on Mon, 2017-02-06 09:11 in

Hello David,

Is it possible to search through alternative words which i added at categories in category hierarchy mapping.

For example:

For the category "prullenbakken" i added these alternative words:

=Afvalemmer
=Afvalemmers
=Papierbak
=Prullenbak
=Prullenbakken
=afvalemmer
=afvalemmers
=papierbak
=test1234

So when somebody types test1234 in search i like to see the products standing in "prullenbakken".

Other question: Are alternatives words exactly working so you write it? I mean when i start a word with a capital letter do i also need to write the same word without capital letter?

Thank you very much.

Submitted by support on Mon, 2017-02-06 12:22

Hi,

That could be done but I would only really recommend this for very niche sites but if you would like to give it a go, edit search.php and look for the closing break; statement of the default: case of the main search SQL construction code, around line 324:

        break;

...and REPLACE with:

        $where = "(".$where.") OR (categoryid = (SELECT categoryid FROM `".config_databaseTablePrefix."categories_hierarchy` WHERE alternates
LIKE '%".database_safe($q)."%' ) )";
        break;

Regarding =Exact Match alternatives, yes - these are Case Sensitive. If you wanted to make it case insensitive, edit includes/admin.php and look for the following code at line 383:

    if (isset($admin_importCategoryMappings["=".$importRecord["category"]]))
    {
      $importRecord["category"] = $admin_importCategoryMappings["=".$importRecord["category"]];
    }

...and REPLACE with:

    if (isset($admin_importCategoryMappings["=".strtolower($importRecord["category"])]))
    {
      $importRecord["category"] = $admin_importCategoryMappings["=".strtolower($importRecord["category"])];
    }

And then the following code at line 434:

              if (strpos($importRecord["category"],$word) !== FALSE) $found++;

...and REPLACE with:

              if (strpos(strtolower($importRecord["category"]),$word) !== FALSE) $found++;

And then the following code at line 596:

          $admin_importCategoryMappings[$alternate] = $category["name"];

...and REPLACE with:

          $admin_importCategoryMappings[strtolower($alternate)] = $category["name"];

(note that this will also make keyword match alternatives case insensitive also)

Cheers,
David.
--
PriceTapestry.com

Submitted by wesse249 on Tue, 2017-02-07 07:58

Hallo David,

Why you don't recommend? Is it to heavy for the database?

Thanks

Jan Roel

Submitted by support on Tue, 2017-02-07 08:40

Hello Jan,

The method described above will require a full table scan of the `categories_hierarchy` table and may prevent the database from optimally using the other indexes normally intended for an efficient search however depending on the size of the database, server performance it may work well - the modifications can be easily reversed if it turns out to be too slow - just let me know if you're not sure of course...

Cheers,
David.
--
PriceTapestry.com