Opened 12 years ago
Closed 12 years ago
#21638 closed enhancement (duplicate)
Improve searching through posts
Reported by: | 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.
If we go with showing the 'title' matches before the 'content' matches, been testing something like this for the search query:
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.