Better Search
[resolved] Give post title more weight (2 posts)

  1. poer
    Posted 5 years ago #

    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') ";
    			$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.

  2. poer
    Posted 5 years ago #


    For my website purpose, I also add search excerpt (grabbed from search extract plugin) and search terms highlighter functions to the plugin.

    modified file

    Feel free to use it if you find it useful.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Better Search
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic