Re: Search thoughts
| From: | Richard Heyes | Date: | Sat, 19 Jul 2008 14:32:00 +0000 |
| Subject: | Re: Search thoughts | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-277075@lists.php.net to get a copy of this message | ||
Mark Kelly wrote:
Hi. On Saturday 19 July 2008, Richard Heyes wrote:Well no. LIKE is slow and so is in_array(). Admittedly it's not a busy site, but still. How much traffic do you have and what's your hardware? Are your queries cached and subsequently repeated? Do you pre cache common queries? Cheers. -- Richard HeyesCurrently the site in question uses a very basic LIKE in MySQL, eg %blah%, but naturally this finds terms such as hjkblahbjkk - which is not desired. Or such matches should be ranked lower than something that matches the exact word blah.I did this with 2 queries, and no need for messing with points etc (unless you particularly want to). Start with "LIKE 'word'" query and pull the results into a results array. Then do the same query but with "LIKE '%word%'" and loop through append the results to the results array. Use something like "if (!in_array($thisResult,$resultSet))" while appending to avoid duplicates.