You are here:  » Search for 2 words

Support Forum



Search for 2 words

Submitted by midsol on Tue, 2008-01-08 13:25 in

Hello there,

I am having some problems with my search function. Right now when I search for example Nokia N73 I am getting results with all kinds of Nokia phones while I am search specific for Nokia N73. When I search however for N73 it shows relevant results. But how can I get the search to search not only for the first word in the search but all words I enter in the search? How I can I set this?

Please let me know.

Greets,

Chris

Submitted by support on Tue, 2008-01-08 13:28

Hi Chris,

This is a result of Price Tapestry's "Full Text" indexing function ignoring words of less than 4 characters. There is a good work-around for this in the following thread:

http://www.pricetapestry.com/node/1552

Hope this helps!
Cheers,
David.

Submitted by midsol on Tue, 2008-01-08 13:48

Thanks for your quick reply David!

Submitted by support on Tue, 2008-01-08 13:53

Hi Chris,

No worries - although I just spotted a "mod to the mod" that's needed in this situation. The replacement code should instead be:

        $useFullText = TRUE;
        $words = explode(" ",$parts[0]);
        foreach($words as $word)
        {
          if (strlen($word) < 4)
          {
            $useFullText = FALSE;
          }
        }
        // if not using full text index, spaces must be removed from the query
        if (!$useFullText) $parts[0] = str_replace(" ","",$parts[0]);
        // the following line replaces the deleted line from the original code
        if ($useFullText)

This will force the basic search method if any of the words are less than 4 characters, which is a better fix in general.

Cheers,
David.

Submitted by TWDesigns on Fri, 2010-04-30 23:03

This looks like it may have changed with the newest version of PT? Because I am having a problem locating the code mentioned in the above Link. I am looking to have search terms find "all words" instead of partial words. For example if I search for "Men in Black" I get returns like "0.45mm Black Monofilament Cable Spool 100m Fishing Line".

Or/and is there a way to have a category drop down that they can use to narrow the search zone done to? So they could click DVD and it would only search in DVDs?

Thanks,
Tommy

Submitted by support on Sat, 2010-05-01 05:00

Hi Tommy,

The latest distribution of Price Tapestry includes the modification described above as it stands, (non full text search if any word less than 4 characters and uses AND logic in the query) however it is straight forward to make the non full text search perform an exact match on the query rather than look for individual words; which, as you've discovered, does mean that short words like "in" are matched within longer words.

To do this, in search.php look for the following code line 193:

          $where = implode(" AND ",$wheres);

...and REPLACE with:

          $where = "name LIKE '%".database_safe($parts[0])."%'";

Hope this helps!

Cheers,
David.