Let??™s implement this method first, and then we??™ll discuss how it works.
CHAPTER 8 ?– SEARCHING THE CATALOG 232
Exercise: Implementing the Business Tier
1. The full-text search feature of MySQL ignores words that are shorter than a specified length.We want to
inform the visitor which words have been used for searching and which words were ignored. To support
this feature, we first need to find out the length that is already specified in our database by interrogating the
MySQL ft_min_word_len variable. Use phpMyAdmin to execute the following SQL statement in the
tshirtshop database:
SHOW VARIABLES LIKE 'ft_min_word_len';
If you haven??™t changed the value, ft_min_word_len should be 4 (see Figure 8-6).
Figure 8-6. Looking up the ft_min_word_len variable in phpMyAdmin
2. Let??™s now save the value of the ft_min_word_len you just found to the configuration file, making it easily
available from the application code. Open include/config.php, and add the following code:
/* Minimum word length for searches; this constant must be kept in sync
with the ft_min_word_len MySQL variable */
define('FT_MIN_WORD_LEN', 4);
3. Open business/catalog.php, and add the code of the Search() method:
// Search the catalog
public static function Search($searchString, $allWords,
$pageNo, &$rHowManyPages)
{
//The search result will be an array of this form
$search_result = array ('accepted_words' => array (),
'ignored_words' => array (),
'products' => array ());
// Return void if the search string is void
if (empty ($searchString))
return $search_result;
// Search string delimiters
$delimiters = ',.
Pages:
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345