Sweeney Posted March 31, 2009 Share Posted March 31, 2009 I've been trying to make a simple search for a few weeks now. I'm not getting any errors however I'm not getting the results I'm looking for. When I search for items I know are in the columns listed it still tells me they are not there. For instance one of the columns has the word "falconman" however when searched for it gives me no results. Please Help!! <?php require "../_admin/config.php"; ?> <?php $phrase = array_key_exists('phrase', $_POST) ? trim(stripslashes(strip_tags($_POST['phrase']))) : ''; if(empty($phrase)){ echo "\n".'<p>No words placed in the search box. </p>'; }else{ // SQL injection prevention (double quote mark is allowed here but should probably be disallowed) $phrase = strtr($phrase, ',/\*&()$%^@~`?;', ' '); $phrase = trim($phrase); $phrase = str_replace('#180', '', $phrase); echo "\n".'<p>Searching for <i>'.htmlspecialchars($phrase).'</i>... </p>'; $key = 'text_index'; // Beware of the re-definition of $s in this query. $phrase = html_entity_decode($phrase, ENT_QUOTES); $res = mysql_connect($host, $user, $pass) or die(mysql_error()); mysql_select_db($db) or die(mysql_error()); if(!($res =mysql_query( 'SELECT `id` AS s, `link` AS c, `vid_title`, `vid_desc` FROM `'.$opts['videos'].'` WHERE `id` <> "1" AND MATCH(`vid_title`, `vid_desc`) AGAINST ("'.$phrase.'") LIMIT 10' ))){ echo "\n".'<p>No results for: <i class="red">'.$phrase.'</i></p>'; }else{ if(mysql_num_rows($res) == 0){ echo "\n".'<p>The search engine cannot find the page you are looking for.</p>'; echo "\n".'<p>This could be because it could not find any pages containing <i>'.$phrase.'</i>'; echo "\n".'<p>Alternatively, it might have found too many pages, and could not decide which one you wanted.</p>'; }else{ $i = 0; while($row = mysql_fetch_array($res)){ $s = substr(stristr(strip_tags($row['vid_title']), $phrase), 0, 120); if($s == ''){ $s = substr(strip_tags($row["vid_desc"]), 0, 120); } $i++; echo "\n".'<p>'.$i.'.) <a href="results.php?id='.$row['s'].'">'.htmlentities($row['c']).' - '.htmlentities($row['vid_title']).'</a> ... '.$s.'...</p>'; } } } // Save searches to monitor user activity $phrase_qry = sprintf("INSERT INTO vs_searches (id, phrase, ip) VALUES ('', '%s', '%s')", addslashes($phrase), addslashes($ua['ip'])); if(!($phrase_res = mysql_query($phrase_qry))){ $opts['error_msg'] .= 'Insert failed for search phrase'."\n".$phrase_qry."\n"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/151980-search-issues/ Share on other sites More sharing options...
premiso Posted March 31, 2009 Share Posted March 31, 2009 I take it you are doing a full text search. MySQL FullText Search Reference Read up on it there. More predominately at the 11.8.1. Natural Language Full-Text Searches The 50% threshold has a significant implication when you first try full-text searching to see how it works: If you create a table and insert only one or two rows of text into it, every word in the text occurs in at least 50% of the rows. As a result, no search returns any results. Be sure to insert at least three rows, and preferably many more. Users who need to bypass the 50% limitation can use the boolean search mode; see Section 11.8.2, “Boolean Full-Text Searches”. Check your test data, make sure that no more than 49% of the rows are being returned or else you will not get any results. Quote Link to comment https://forums.phpfreaks.com/topic/151980-search-issues/#findComment-798134 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.