You are here:  » Search accuracy

Active Forum Topics


Search accuracy

Submitted by safari45 on Sat, 2020-06-20 20:16 in

Hi David, Many thanks for the great dedicated support you've continued to provide.

I would like to make search be more accurate. search result should be based on keyword (entire keyword) rather than key-letters in a keyword
for example when I search for "sko" (which means shoe in danish)

I expect the result to be as:
........... sko .............
Adidas Originals Campus Sko Navy
Adidas Originals Ozweego Ef4288 Sko Grå/grøn
Dame Sko - Black
-------------------------------------------------------------
But I also get these products in search results which are not related to the keyword "sko"

Christina Watches Skorpionen Charm i Forgyldt Sølv med Citrin
CHRISTINA, Skorpionen - 623-G63
Dickies Kortærmet Heavy Weight T-shirt (Hvid, 3XL)
Good Mood adult socks - KOALA, size 35-38
Grønt skotskternet tørklæde

is there a way to make search based on keyword rather than letters that are in the keyword.

Submitted by support on Mon, 2020-06-22 06:50

Hi,

Sure - to enable whole word match for searches where 1 or more keywords are less than 4 characters (meaning that the FULLTEXT index is not used), edit search.php and look for the following code beginning at line 299:

  $where = "(";
  $where .= "search_name LIKE '%".database_safe($word)."%'";
  if ($config_searchDescription)
  {
    $where .= " OR description LIKE '%".database_safe($word)."%'";
  }
  if (substr($word,-1)=="s")
  {
    $where .= " OR search_name LIKE '%".database_safe(substr($word,0,-1))."%'";
    if ($config_searchDescription)
    {
      $where .= " OR description LIKE '%".database_safe(substr($word,0,-1))."%'";
    }
  }
  $where .= ")";

...and REPLACE with:

  $where = "(";
  $where .= "name REGEXP '[[:<:]]".database_safe($word)."[[:>:]]'";
  if ($config_searchDescription)
  {
    $where .= " OR description REGEXP '[[:<:]]".database_safe($word)."[[:>:]]'";
  }
  if (substr($word,-1)=="s")
  {
    $where .= " OR name REGEXP '[[:<:]]".database_safe(substr($word,0,-1))."[[:>:]]'";
    if ($config_searchDescription)
    {
      $where .= " OR description REGEXP '[[:<:]]".database_safe(substr($word,0,-1))."[[:>:]]'";
    }
  }
  $where .= ")";

Cheers,
David.
--
PriceTapestry.com

Submitted by safari45 on Mon, 2020-06-22 13:16

Thanks for reply. I have tested the code, but not result are coming when I try to search.
i get no result.

Submitted by support on Mon, 2020-06-22 18:46

Hi,

I know you've been using the script for several years now, please could you undo the changes to as they were and then email me search.php from this installation and I'll check it out further with you...

Thanks,
David.
--
PriceTapestry.com

Submitted by support on Tue, 2020-06-23 06:48

Thanks for the file - sorry about that I hadn't changed search_name to name in the replacement - corrected above.

Cheers,
David.
--
PriceTapestry.com