Hi David,
Quite a while ago you helped me change the sidebar filters on my site to tick boxes. I just noticed something odd on one of the filters which contains numbers that when for example a 5 is selected the 5.5 is picked up. I guess what is happening is a wildcard in the search. I wondered if you might possibly be able to suggest a change to the filter so that only exact matches are displayed?
Thanks in advance.
Best regards
Chris
Hi David,
Thanks for your quick response. I searched for the code above and the closest match I could find in search.php was:
{code saved}
I changed the line below:
$wheres[] = " size LIKE '%".database_safe($v)."%' ";
to a version using regex but the editor flagged an error in my code. Please could you confirm this looks like the correct section of code.
Thanks in advance.
Best regards
Chris
Hi Chris,
The line;
$wheres[] = " size LIKE '%".database_safe($v)."%' ";
...would convert to:
$wheres[] = " size REGEXP '[[:<:]]".database_safe($v)."[[:>:]]' ";
Cheers,
David.
--
PriceTapestry.com
Hi David,
Thanks for the above. I’ve replaced the code as suggested but the issue remains. If 5 is selected 5.5, 2.5 etc are returned also if .5 is selected 5.5, 2.5 etc are returned in the results. I’m wondering if the regex boundary is identifying the .[point] correctly...
Would be grateful for any suggestions you might have on how I might be able to resolve this.
Thanks in advance.
Bets regards
Chris
Hello Chris,
Ah - the decimal is considered a word boundary of course; sorry about that! An alternative then is to use LIKE with wildcards but concatenate the value between commas to cover first and last - have a go with;
$wheres[] = " CONCAT(',',size,',') LIKE '%,".database_safe($v).",%' ";
Hope this helps!
Cheers,
David.
--
PriceTapestry.com
Hi David,
Thanks for the above. The revised code seems to have resolved the issue.
Best regards
Chris
Hi Chris,
This can be done by using REGEXP and word boundary markers in place of LIKE / wildcards. I'm assuming you currently have something similar to the following code in search.php for a custom sizeFilter:
if ($sizeFilter)
{
$priceWhere .= " AND size LIKE '%".database_safe($brandFilter)."%' ";
}
The equivalent with REGEXP would be:
if ($sizeFilter)
{
$priceWhere .= " AND size REGEXP '[[:<:]]".database_safe($brandFilter)."[[:>:]]' ";
}
...and that will ensure whole word match only.
Cheers,
David.
--
PriceTapestry.com