[Plugin: Better Search] Give post title more weight
-
Hi, I really like Better Search, simpler and faster compare to search unleased and relevanssi.
For my site purpose, I modified the plugin to give post title more weight by replacing line 153 – 157:
$sql = "SELECT ID,post_title,post_content,post_excerpt,post_date, MATCH(post_title,post_content) AGAINST ('".$s."') AS score FROM ".$wpdb->posts." WHERE MATCH (post_title,post_content) AGAINST ('".$s."') AND post_status = 'publish' "; if ($bsearch_settings['include_pages']) $sql .= "AND (post_type='post' OR post_type = 'page') "; else $sql .= "AND post_type = 'post' ";
with the following code:
$sql = "SELECT ID, post_title, post_content, post_excerpt, CASE WHEN post_title LIKE '%".$s."%' THEN 1 ELSE 0 END AS titlematch, MATCH (post_title, post_content) AGAINST ('".$s."') AS score FROM ".$wpdb->posts." WHERE MATCH (post_title, post_content) AGAINST ('".$s."' IN BOOLEAN MODE) AND post_status = 'publish' "; $sql .= ($bsearch_settings['include_pages']) ? " AND (post_type='post' OR post_type = 'page') " : " AND post_type = 'post' "; $sql .= " HAVING score > 2 ORDER BY (titlematch * 1.5 + score) DESC ";
hope that it will give you more idea for the next plugin update.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘[Plugin: Better Search] Give post title more weight’ is closed to new replies.