You are here:  » Category Mapping Problem


Category Mapping Problem

Submitted by niajahi on Tue, 2017-01-31 18:03 in

Hi Dave,

I'm working with the latest PT build locally and am having a category mapping problem.

I'm using Webgains and PaidonResults xml datafeeds.

Most of the feeds have long category terms that contains ">" and "|" delimiters separating phrases and in the admin.php file, I have commented out lines 197-202 ( starting @ if ($importRecord["category"]) ) so that I can filter out the last category term.

I then interrogate the database to pull all the category terms so that I can better group them.

After entering the category mapping details on the site, and re-importing the feeds, all filtered categories are displayed rather than the mapped ones.

The flag $config_useCategoryHierarchy is still set to FALSE so I assumed it should show the mapped values that I entered?

I've searched the forum but couldn't find anything.

Any pointers?

Len

Submitted by support on Wed, 2017-02-01 10:05

Hello Len,

In order to be part of a compound index that significantly improves search performance, the category field is limited to 32 characters (it can actually be increased in some circumstances), but in addition, characters such as > and | will be stripped by the normalisation.

However, what will help here is first to permit any characters used as category delimiters in your feeds at the point at which the category value is normalised. To do this, edit includes/admin.php and look for the following code at line 199:

  $importRecord["category"] = tapestry_normalise($importRecord["category"]);

...and REPLACE with:

  $importRecord["category"] = tapestry_normalise($importRecord["category"],">|");

With that in place, for each feed that has this style of category name, add an Explode filter to the Category field, and on the configuration page for the new filter, in the Explode Character or String enter the character used e.g. ">" (without the quotes) and -1 as the return index. That will return the last value - e.g. lowest level subcategory which you can then use in mapping.

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by niajahi on Wed, 2017-02-01 14:12

Thanks David,

That works better!

On another note, what I didn't realise was that unmapped categories will show *as well* as the mapped ones. So now it's down to sorting those out into new categories.

Cheers again,
Len

Submitted by support on Wed, 2017-02-01 14:21

Hello Len,

I assume you're referring to the Category Search tool on the configuration page for a category mapping - it would be no problem to modify the search function so that it only returns unmapped categories. To try this, edit admin/helper.php and look for the following code at line 22:

    $sql = "SELECT DISTINCT(".$field.") FROM `".$config_databaseTablePrefix."products` WHERE ".$field." LIKE '%".database_safe($q)."%' ORDER BY ".$field." LIMIT 6";

...and REPLACE with:

    if ($field == "category")
    {
      $sql = "SELECT DISTINCT(category) FROM `".$config_databaseTablePrefix."products` WHERE category LIKE '%".database_safe($q)."%' AND category NOT IN (SELECT name AS category FROM `".$config_databaseTablePrefix."categories`) ORDER BY category LIMIT 6";
    }
    else
    {
      $sql = "SELECT DISTINCT(".$field.") FROM `".$config_databaseTablePrefix."products` WHERE ".$field." LIKE '%".database_safe($q)."%' ORDER BY ".$field." LIMIT 6";
    }

Cheers,
David.
--
PriceTapestry.com

Submitted by niajahi on Fri, 2017-02-10 22:08

Fantastic, thanks David!

Cheers,
Len

Submitted by Ride on Fri, 2017-06-16 16:16

Hi David,
I have 2 feeds, one has the character > as category delimiter and the second one has the slash (/) as category delimiter

I tried this mod, adding also the character /

$importRecord["category"] = tapestry_normalise($importRecord["category"],">|/");

Than added an explode filter for > on the first feed and an explode filter for / on the second feed

It works with the first feed (>) but not with the second one using the slash as a delimiter, when I import the second feed the category field is empty.

Any suggestion?
Thank you!

Submitted by support on Fri, 2017-06-16 16:51

Hi,

"/" is used as the delimiter in the regular expression used by the tapestry_normalise() function, so when provided as an allowed character it needs to be escaped by preceding with back-slash - have a go with:

$importRecord["category"] = tapestry_normalise($importRecord["category"],">|\/");

Hope this helps!

Cheers,
David.
--
PriceTapestry.com