Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.