Hi there,
Is it possible to search product title and brand name at the same time?
Many Thanks
Bob
David
This new set up is working well if I search through the search box alone. But if I search through the search box and want to search for a brand within a category so e.g. w=category:virus+protection:esoft(esoft=brand I am searching for) the search reverts back to product title searches only. I know this because I can get relevant results in this combined category+brand search if the brand name is within the product title. But not otherwise.
Any ideas where I should look for to correct this, if possible at all?
Many Thanks.
Bob
Hi Bob,
When the query is brand:something or category:something the SQL is generated by a separate bit of code; so another modification will be required to make the 3rd part search the brand field as well as the product name.
The code is currently as follows on line 43 of search.php:
if (isset($parts[2])) if ($parts[2]) $where .= "AND search_name LIKE '%".database_safe(tapestry_search($parts[2]))."%'";
To include the brand field in this where clause, modify as follows:
if (isset($parts[2])) if ($parts[2]) $where .= "AND (search_name LIKE '%".database_safe(tapestry_search($parts[2]))."%' OR brand LIKE '%".database_safe(tapestry_search($parts[2]))."%')";
That should do the trick...
Cheers,
David.
Hi Bob,
There shouldn't be any problem combining the brand with the product name for the full text index. First you would need to build the index by running the following SQL:
ALTER TABLE products ADD FULLTEXT INDEX (name,brand)
The easiest way to do this is if you have phpMyAdmin or similar MySQL administration tool. However, you can create the index by writing a short script to execute the required SQL:
buildIndex.php:
<?php
set_time_limit(0);
ignore_user_abort();
require("includes/common.php");
$sql = "ALTER TABLE `".$config_databaseTablePrefix."products` ADD FULLTEXT INDEX (name,brand)";
database_queryModify($sql,$result);
print "Done.";
?>
If you have thousands of products this script may take some time. Ideally, you would only run this against an empty database immediately after installation. You only need to do this once. After the index has been created MySQL will automatically update it whenever you import feeds. Now, to change the code to use the new index you simply need to do a Search and Replace on search.php...
Search:
MATCH name
Replace:
MATCH name,brand
There are only 3 instances of this, within the section of code that constructs the search SQL around about line 65. I would recommend studying the code first just to make sure you can see where the changes need to go so that you can check that the search and replace worked correctly.
Hope this helps!
Cheers,
David.