Jump to content

Highlight found boolean search terms, Is there a way to...


HowdeeDoodee

Recommended Posts

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.

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.

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.

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|^| |^|

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.