phpdino;10979030 wrote:Is there some way I could give a higher rating to results with exact same words in the title?
yes. here is an example from my site, its raw so you will have to interpret it
$sql_1 = "SELECT url, author, title, body,
(
MATCH (title,author)
AGAINST ('$sql_search')
)
+
(
MATCH (body)
AGAINST ('$sql_search' )
)
AS relevance
FROM search
WHERE MATCH (title, body,author)
AGAINST ('$sql_search' IN BOOLEAN MODE)
$sql_within
HAVING relevance >0
ORDER
BY relevance DESC";
/* for 50% threshhold avoidance and fuzzy matching*/
$sql_2 = "SELECT url, author, title, body,
( (1.3 * (MATCH(title,author)
AGAINST ('$sql_search' IN BOOLEAN MODE)))
+
(0.6 * (MATCH(body)
AGAINST ('$sql_search' IN BOOLEAN MODE))) )
AS relevance
FROM search
WHERE ( MATCH(title,body,author)
AGAINST ('$sql_search' IN BOOLEAN MODE) )
$sql_within
HAVING relevance > 0 ORDER BY relevance DESC";
//if those fail, last ditch attempt
$sql_3 = "
SELECT url, author, title, body,
10*(
LENGTH(title) -
LENGTH(REPLACE(LOWER(title),LOWER('$sql_search'),'')))/LENGTH('$sql_search')
+
10*(
LENGTH(author) -
LENGTH(REPLACE(LOWER(author),LOWER('$sql_search'),'')))/LENGTH('$sql_search')
+
0.1*(
LENGTH(body) -
LENGTH(REPLACE(LOWER(body),LOWER('$sql_search'),'')))/LENGTH('$sql_search')
as relevance
FROM search
WHERE
( title REGEXP ' $sql_search ' OR body REGEXP ' $sql_search ' )
$sql_within
HAVING relevance>0
ORDER BY relevance DESC
";