[wp-trac] [WordPress Trac] #7394: Search: order results by relevance

WordPress Trac wp-trac at lists.automattic.com
Mon Aug 20 19:53:15 UTC 2012


#7394: Search: order results by relevance
-------------------------+-----------------------------
 Reporter:  markjaquith  |       Owner:
     Type:  enhancement  |      Status:  assigned
 Priority:  normal       |   Milestone:  Future Release
Component:  General      |     Version:  2.6
 Severity:  normal       |  Resolution:
 Keywords:  has-patch    |
-------------------------+-----------------------------

Comment (by azaozz):

 #21638 was closed as duplicate.

 To continue the discussion from there:
 Replying to [http://core.trac.wordpress.org/ticket/21638#comment:2 toscho]
 > Could this be extended to the following order:
 >
 > 1. Results with exact matches for the search phrase.
 > 2. All words from search phrase in any order.
 > 3. Some words from the search phrase.

 Yes, that would make the search even better when it's multi-word:

 {{{
 ( SELECT * FROM wp_posts WHERE post_title LIKE '%one two three%' AND ... )
 UNION
 ( SELECT * FROM wp_posts WHERE post_content LIKE '%one two three%' AND ...
 )
 UNION
 ( SELECT * FROM wp_posts WHERE post_title LIKE '%one%' AND post_title LIKE
 '%two%' AND ... )
 UNION
 ( SELECT * FROM wp_posts WHERE post_content LIKE '%one%' AND post_content
 LIKE '%two%' AND ... )
 UNION
 ( SELECT * FROM wp_posts WHERE (post_title LIKE '%one%' OR post_title LIKE
 '%two%') AND ... )
 LIMIT 0, 20
 }}}

 Not sure we should do the `OR` case for post_content. That usually returns
 tons of results (we don't do it at the moment too).

 On my test install with about 2000 posts this query performs relatively
 well, 0.1 - 0.2 sec. with limit 50 and very common search terms.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/7394#comment:18>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list