You are here:  » How to make custom fields searchable?

Support Forum



How to make custom fields searchable?

Submitted by gunarbod on Mon, 2012-08-06 15:56 in

Hi David,

i've added the custom field "subcategory" to productsmapping_configure.php and it works fine. Too make it searchable, I've also added the field to the products-table and to the fields array in search.php.

$fields = array("merchant","category","subcategory","brand");

However, searching for the keywords entered in "subcategory", these products don't show up. What else do I have to do?

Thanks for your help!
Gunar

Submitted by support on Mon, 2012-08-06 16:37

Hi Gunar,

In addition to adding your new field "subcategory" to the line that you identified, it would also need to be permitted through to that section of code in the switch/case construct. Immeditately above the line that you have identified, you will see:

      case "brand":

...REPLACE that with:

      case "brand":
      case "subcategory":

And then, you will be able to search your new subcategory field using:

search.php?q=subcategory:Subcatgegory Name:

Cheers,
David.
--
PriceTapestry.com

Submitted by gunarbod on Mon, 2012-08-06 16:57

Hi David,

thanks for your reply. Unfortunately, the products still don't show up for the keywords entered in the "subcategory" field.

For example this mapped product ({link saved}) has the category "Kontaktlinsen" and the subcategory "Tageslinsen". It appears within the "Kontaktlinsen"-category ({link saved}) but not within the "Tageslinsen"-category ({link saved}).

As far as I can see, search.php searches the products-table - not the productsmap-table, right? So maybe the keywords stored in productsmap need to be stored in products too when running the import?

Cheers,
Gunar

Submitted by support on Tue, 2012-08-07 08:15

Heloo Gunar,

As it stands, the subcategory would only be found when searching e.g.

/search.php?q=subcategory:Tageslinsen:.

However, if you did want to include it in based search - no problem. First of all, disable use of the full text index by changing line 8 in config.advanced.php to:

  $config_useFullText = FALSE;

Next, in search.php, look for the following code at line 229:

    $where .= "search_name LIKE '%".database_safe($word)."%'";

...and REPLACE with:

    $where .= "search_name LIKE '%".database_safe($word)."%'";
    $where .= " OR subcategory = '".database_safe($word)."'";

Cheers,
David.
--
PriceTapestry.com