calabiyau Posted May 18, 2007 Share Posted May 18, 2007 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>'; } Quote Link to comment https://forums.phpfreaks.com/topic/51943-search-displaying-sample-of-results-content-near-the-search-term/ Share on other sites More sharing options...
AV1611 Posted May 18, 2007 Share Posted May 18, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/51943-search-displaying-sample-of-results-content-near-the-search-term/#findComment-256129 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.