Hi;
I am trying to implement a search engin, and i want the most relevant results that must sit on top of the other ones. but my code does not always bring out right result, could anyone help, thanks
////////////////////
my code
I am trying to implement a search engin, and i want the most relevant results that must sit on top of the other ones. but my code does not always bring out right result, could anyone help, thanks
Code:
create table keyword_relevance
( id tinyint not null primary key auto_increment
, Description varchar(99)
);
insert into keyword_relevance (Description) values
('I like to play games')
,('One game, two games, eh')
,('There''s no keyword')
,('The games keyword is present only once')
,('The games keyword is present only once in a longer sentence')
,('The games keyword is present only once in a really really really really really really long sentence')
,('Games games')
,('Games beautiful games')
,('')
,(null)
,('Games')
,('Games ')
,(' Games');
////////////////////
my code
Code:
$search_string=$_POST['search_string'];
$sql="select distinct count(*) as occurences, id, Description
from keyword_relevance
where (";
while(list($key,$val)=each($search_string)){
if($val<>" " and strlen($val) > 0){
$sql .=" Description like '%" . $val . "%' or";
}
}
$sql=substr($sql,0,(strLen($sql)-3));//this will eat the last OR
$sql .= ") group by id order by occurences DESC";