Make WordPress Core

Opened 12 years ago

Closed 12 years ago

#21638 closed enhancement (duplicate)

Improve searching through posts

Reported by: azaozz's profile azaozz Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Query Keywords:
Focuses: Cc:

Description

Searching for a particular post in WordPress is a daunting task. It usually returns a lot of irrelevant matches and when there are several thousands posts, it's almost impossible to do.

There have been many discussions, ideas, even couple of GSoC projects about improving that search, however there have been no significant improvements as the best methods are too complicated for inclusion in core.

However there is one (low hanging/easy to do) thing that can improve search quality a lot, especially in the admin: separating the search by post_title and post_content.

The current search looks in both title and content at the same time. For most places (custom menus, internal linking, attaching orphaned attachments, etc.) it makes sense to search through the titles before the content or even have an option so the user can exclude searching through the content completely.

Change History (3)

#1 @azaozz
12 years ago

If we go with showing the 'title' matches before the 'content' matches, been testing something like this for the search query:

( SELECT * FROM wp_posts WHERE post_title LIKE '%searchterm%' AND ... )
UNION
( SELECT * FROM wp_posts WHERE post_content LIKE '%searchterm%' AND ... )
LIMIT 0, 20

This returns the posts whose titles match "searchterm" before the posts whose content matches it. Using UNION makes the set unique (no need for DISTINCT).

Seems to be a little bit slower than the current WHERE post_title LIKE '%searchterm%' OR post_content LIKE '%searchterm%' as UNION always creates temp table. On the other hand the search sorting can be enhanced by creating the temp table by hand, filling it with couple of SELECTs and then running another select with additional sorting, etc.

#2 @toscho
12 years ago

  • Cc info@… added

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.

#3 @scribu
12 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.