Prev | Current Page 336 | Next

Emilian Balanescu and Cristian Darie

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

The accepted_words array
will store the words that will be used for searching, and ignored_words will be populated with the words that
will be ignored from searching. The presentation tier will use this data to inform the visitor which words have been
searched for and which have been ignored. The products array will store the list of products that match the
search string.
Next, Search() verifies that the search string isn??™t empty. If it is, the empty $search_result array is returned,
indicating that no search results have been found:
// Return void if the search string is void
if (empty ($searchString))
return $search_result;
CHAPTER 8 ?–  SEARCHING THE CATALOG 235
Once we??™ve made sure the search string isn??™t empty, we start filtering the words.Words that are shorter than the
FT_MIN_WORD_LEN are sent to the ignored_words array, and they are ignored by MySQL when performing the
search. The other words are saved to the accepted_words, array; they will be used for searching. Because
MySQL doesn??™t inform you which words have been used for searching and which have been ignored, we need
check the ignored and accepted words in the business tier. When splitting the search string into individual words,
we consider that the possible word separators are the comma (,), the dot (.), the semicolon (;) and the space. Any
other character the visitor types in the search box will be considered part of a word.


Pages:
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348