Prev | Current Page 330 | Next

Emilian Balanescu and Cristian Darie

"Beginning PHP and MySQL E-Commerce: From Novice to Professional, Second Edition"

First, it
finds the words that are most relevant to those you??™re searching for. Then these words are appended to your
initial query string, and the search is performed again.
This method increases the number of search results, but also increases the chance of getting nonrelevant
products. You can see the official documentation of this feature at http://dev.mysql.com/doc/
refman/5.1/en/fulltext-query-expansion.html.
To enable query expansion, you need to add WITH QUERY EXPANSION to the search criteria as shown
in the following code snippet:
SELECT name, description FROM product
WHERE MATCH (name, description) AGAINST ("flower" WITH QUERY EXPANSION)
ORDER BY MATCH (name, description) AGAINST ("flower" WITH QUERY EXPANSION) DESC;
Search for ???flower??? with query expansion retrieves 75 results. Executing the same search without query
expansion, you get only 15 results. The data tier code presented in the following pages doesn??™t use query
expansion, but you can add it very easily if you want to.
Writing the Stored Procedures for Searching Functionality
You are ready now to implement your web site??™s search functionality. If you??™d like to learn more
about the inner workings of the MySQL full-text, consult its official documentation at
http://dev.mysql.com/doc/refman/5.1/en/fulltext-search.html
CHAPTER 8 ?–  SEARCHING THE CATALOG 230
Exercise: Writing the Database Searching Code
1.


Pages:
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342