Make WordPress Core

Opened 12 years ago

Last modified 5 years ago

#20044 new enhancement

Enable search for pages by slug

Reported by: ekitomat's profile ekitomat Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.7
Component: Query Keywords: needs-testing needs-patch
Focuses: Cc:

Description

Would be nice to be able to search a page by its slug. Might need to be a bit different depending on the permalink-strategy.

Steps to reproduce(with Post name-permalinks enabled):

  1. Create a new page with a specific slug
  2. Save page
  3. Search for the exact slug-name

Attachments (5)

20044.diff (681 bytes) - added by kovshenin 11 years ago.
Adds the page_name column to query's search
20044.2.diff (1.6 KB) - added by wonderboymusic 10 years ago.
20044.3.diff (2.6 KB) - added by wonderboymusic 10 years ago.
20044.4.diff (3.3 KB) - added by jeremyfelt 10 years ago.
20044.5.diff (4.2 KB) - added by nacin 10 years ago.

Download all attachments as: .zip

Change History (21)

#1 @dd32
11 years ago

  • Component changed from Permalinks to Query

@kovshenin
11 years ago

Adds the page_name column to query's search

#2 @kovshenin
11 years ago

  • Keywords has-patch needs-testing added; needs-patch removed

20044.diff uses the page_name column with LIKE, just like the post title and content. Needs testing, preferably on a large dataset with query caching disabled, not entirely sure how this will hit performance.

#3 @wonderboymusic
11 years ago

  • Milestone changed from Awaiting Review to 3.7

Moving to 3.7 for discussion.

#4 @nacin
11 years ago

  • Milestone changed from 3.7 to Future Release

#7394 necessitates this doesn't move forward yet.

#5 @wonderboymusic
10 years ago

  • Keywords needs-testing removed
  • Milestone changed from Future Release to 3.9
  • Version set to 3.7

20044.2.diff refreshes and adds Unit Tests.

#6 @wonderboymusic
10 years ago

20044.3.diff implements this as a filter on query_search_fields, which is more flexible than just jamming post_name in there. Because at that point, why not also add post_excerpt? This puts the onus on the developer to make the right decision in regards to performance.

Added query/search.php to unit tests.

#7 @DrewAPicture
10 years ago

  • Keywords needs-docs added

'query_search_fields' filter needs docs.

#8 @nacin
10 years ago

I'd also like to see the filter simply be for post fields, so 'post_content', 'post_title', etc., rather than having an explicit table reference inside the filter.

@jeremyfelt
10 years ago

#9 follow-up: @jeremyfelt
10 years ago

  • Keywords needs-docs removed

20044.4.diff checks anything passed in the filter against an array of allowed search fields—post_title, post_content, post_name, and post_excerpt—and then sets up the query.

I left out other posts fields from the allowed list as they don't seem applicable. Docs added to the query_search_fields filter as well.

#10 in reply to: ↑ 9 @DrewAPicture
10 years ago

  • Keywords needs-testing added
  • Severity changed from trivial to normal

Replying to jeremyfelt:

20044.4.diff checks anything passed in the filter against an array of allowed search fields—post_title, post_content, post_name, and post_excerpt—and then sets up the query.

I left out other posts fields from the allowed list as they don't seem applicable.

Just to be clear, the filter in 20044.4.diff effectively expands the available search fields to also include post_excerpt and post_name *only*. Does it not limit the usefulness of the filter to say, "You can customize the search fields, but are limited to choosing within this list of four?".

Docs added to the query_search_fields filter as well.

Very nice :)

Last edited 10 years ago by DrewAPicture (previous) (diff)

#11 @nacin
10 years ago

In 27474:

Add unit tests for searching by relevance.

props wonderboymusic.
see #7394, #20044.

#12 @nacin
10 years ago

I managed to not commit the original tests from #7394, which was to have added tests/query/search.php.

post_content_filtered should also be made available.

@nacin
10 years ago

#13 @nacin
10 years ago

  • Keywords punt added

20044.5.diff cleans things up a bit.

That said, this doesn't help with ordering. In fact, #7394 kind of gets in the way here (it was fixed after this ticket was opened). You could add more fields to search, or even remove some, but it doesn't affect the ordering — a perfect post_name match ends up on the final page of results. That's not a great experience. Some earlier patches on #7394 allowed for the reverse: it helped with ordering but not with which fields were searched. Seems like we should add both tools at once.

#14 @nacin
10 years ago

  • Milestone changed from 3.9 to Future Release

#15 @samuelsidler
10 years ago

  • Keywords punt removed

#16 @chriscct7
8 years ago

  • Keywords needs-patch added; has-patch removed

Needs an improved patch based on nacin's last one per his comment

Note: See TracTickets for help on using tickets.