HowdeeDoodee Posted May 24, 2007 Share Posted May 24, 2007 I have a boolean search feature for my site. On the standard non-boolean search features I have highlighting of the found terms. I want to be able to highlight found terms of a boolean search. Is there a way to highlight found search terms for a boolean result set? OR Is there a way to explode the result string of the Select statement and pick out the words used by the embedded MySql boolean search engine? Here is the query statement... $query2 = " SELECT *, MATCH(Topic, Subtopic) AGAINST ('$all $none $any' IN BOOLEAN MODE) FROM View2_ConcordFT WHERE MATCH(Topic, Subtopic) AGAINST ('$all $none $any' IN BOOLEAN MODE) LIMIT $startrecord, $display"; Here is the result statement... $result2 = mysql_query($query2) or die("The query $query2 failed. MySQL said: " . mysql_error()); Thank you in advance for any replies. Quote Link to comment https://forums.phpfreaks.com/topic/52883-highlight-found-boolean-search-terms-is-there-a-way-to/ Share on other sites More sharing options...
corbin Posted May 24, 2007 Share Posted May 24, 2007 By a boolean search you mean users could search for something like "Cars NOT trains"? Or maybe "PHP AND C++"? You could always just do like you said and explode the sql results and then buffer the content, allowing you to replace the strings with highlighted version of them using some fancy regular expressions or something. Quote Link to comment https://forums.phpfreaks.com/topic/52883-highlight-found-boolean-search-terms-is-there-a-way-to/#findComment-261130 Share on other sites More sharing options...
HowdeeDoodee Posted May 24, 2007 Author Share Posted May 24, 2007 Thank you Corbin for the response. In regard to your comment, can you give me some examples as to how to explode the sql results and buffer the content? I know the theory you present. What I need is the code or code examples. Thank you again. Quote Link to comment https://forums.phpfreaks.com/topic/52883-highlight-found-boolean-search-terms-is-there-a-way-to/#findComment-261177 Share on other sites More sharing options...
HowdeeDoodee Posted May 27, 2007 Author Share Posted May 27, 2007 I have solved or resolved this issue. With the following function. To run the function, you need to create a stopword file name stopwords.php. A sample of the file contents is below. In my example, if the user inputs any of the words or all of the words dog, red, or max, those words will be stripped from the user input and replaced by a blank space. function stopwordfilter($userinput){ //This function filters stopwords from the users input. $FileName="stopwords.php"; $list = file ($FileName); foreach ($list as $value) { list ($stopword,$filter,) = explode ("|^|", $value); $userinput = eregi_replace($stopword, $filter, $userinput); } return $userinput; } //see if the stopwords filter works $userinput = stopwordfilter($userinput); //these lines go in a file called stopwords.php //if the user types in or inputs any of these words, these words will be replaced by a blank space. dog|^| |^| red|^| |^| max|^| |^| Quote Link to comment https://forums.phpfreaks.com/topic/52883-highlight-found-boolean-search-terms-is-there-a-way-to/#findComment-262379 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.