Jump to content

Recommended Posts

Okay I'm thinking maybe this can't be done, but I would love it if someone could think of some idea of how I might approach this.  I'm making my first search engine and want to have it so that the link in the results would be a little snippet of text around the search term as it is found in the contents.  I thought I had a way to do it, but it only works if the search term is found exactly in the contents, not if it is some grammatical variant like PHP CODE versus WHAT IS PHP CODE.  The PHP CODE works with this method becuase the words PHP CODE exist exactly like that in the contents, however php/mysql picks up the PHP CODE within WHAT IS PHP CODE and gets a result, but my method breaks down.  Anyone have any idea how this is done?  Like with google results.  I'm not looking for code, just some general guidance of a way I might approach this.  Or can it not be done with php?

 

include('../daniel_connections.php');
$search = $_POST['search'];

$search = strip_tags($search, ' ');

echo "<h4>Search Results for:<br/> ".$search."</h4>";
echo '<div id="content">';
echo '<h5>Results from Blog Entries:</h5>';
$query = "SELECT * FROM blog WHERE MATCH (body) AGAINST ('".$search."')";
$result = mysql_query($query,$connect);
while ($row = mysql_fetch_array($result))
{

echo '<a href="blog.php?search=blog&id='.$row['id'].'">'.$row['title'].'</a>';

$split = explode($search,$row['body']);
$split_num = count($split);
srand(time());
$random = (rand()%$split_num);



$string = $split[$random];




$string = substr($string, 0, 300);
echo '<h5>'.$string.'</h5>';
}

not sure but let's say you want to search for "RED MEAT RECIPES"

$str="RED MEAT RECIPES";

$search=explode(' ',$str);

then search for any items in the array

 

it would find anything with RED, MEAT, or RECIPIES.  You could then maybe do some fancy percentage based on how many "hit words" are found...

 

Or, did I totally miss your question

 

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.