Prev | Current Page 335 | Next

Emilian Balanescu and Cristian Darie

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

The
minimum word length is stored in the FT_MIN_WORD_LEN constant. The FT_MIN_WORD_LEN should be kept in
sync with the ft_min_word_len MySQL server variable.
The reason to know this value in our PHP code is that we want to tell the visitor which words have been
removed when doing searches. First, we find out which words are removed by comparing their length with the
FT_MIN_WORD_LEN. This way, we split the searched words into two sets??”the accepted words and ignored
words??”and put them in an associative array in which we??™ll also store the search results and return it as the
method??™s result.
The Search() method of the business tier is called from the presentation tier with the following parameters
(notice that all of them except the first one are the same as the parameters of the data tier Search() method):
??? $searchString contains the search string entered by the visitor.
??? $allWords is ???on??? for all-words searches.
??? $pageNo represents the page of products being requested.
??? $rHowManyPages represents the total number of results pages.
The function starts by declaring an associative array named $search_result, which will store the results of the
product search.
// 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 ());
As you can see, the array contains three other arrays, with self-descriptive names.


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