WordPress.org

Make WordPress Core

Opened 8 years ago

Last modified 2 years ago

#15249 assigned enhancement

Filtering get_search_sql for advanced queries

Reported by: sc0ttkclark Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 3.1
Component: Query Keywords: needs-patch needs-unit-tests
Focuses: Cc:

Description

Currently in the code for 3.1 (trunk) there are no filters running on the new function get_search_sql which would be useful for plugins to perform more complex MySQL functionality on specific columns.

I suggest adding a filter ;)

Attachments (7)

15249.patch (1.8 KB) - added by sc0ttkclark 8 years ago.
Initial Patch including the new filters for Users / Comments
15249.2.patch (954 bytes) - added by sc0ttkclark 7 years ago.
Updated patch for latest SVN Revision (16692)
15249.3.patch (961 bytes) - added by sc0ttkclark 7 years ago.
Updated patch for new $wild var in user get_search_sql
15249.4.patch (1.3 KB) - added by sc0ttkclark 6 years ago.
Refreshing this patch w/ 3.5 trunk
15249.5.patch (1.2 KB) - added by sc0ttkclark 6 years ago.
Changing to use of apply_filters
15249.diff (1.0 KB) - added by wonderboymusic 4 years ago.
15249.2.diff (1.8 KB) - added by DrewAPicture 4 years ago.
hook docs

Download all attachments as: .zip

Change History (28)

#1 @sc0ttkclark
8 years ago

At the moment, it appears this function has disappeared from trunk for whatever reason. It's no longer in /wp-includes/classes.php so I'll keep an eye out for where it's being moved to before patching.

#2 @scribu
8 years ago

  • Type changed from feature request to enhancement

#4 @scribu
8 years ago

For search, we already have the 'posts_search' filter. Should figure out what to do with that.

#5 @sc0ttkclark
8 years ago

In both cases (comment.php / user.php within /wp-includes/), as long as the array passed to get_search_sql is within $this then it can be useful as it is now there is no information available as to what fields are being searched unless the dev copies that code - making it less future proof. Thoughts?

@sc0ttkclark
8 years ago

Initial Patch including the new filters for Users / Comments

#6 @sc0ttkclark
8 years ago

  • Keywords has-patch needs-review added

Added patch that includes the new filters for Users / Comments - implemented in comment.php and user.php (not within get_search_sql function itself due to the lack of information the function is given like no access to $this)

@sc0ttkclark
7 years ago

Updated patch for latest SVN Revision (16692)

@sc0ttkclark
7 years ago

Updated patch for new $wild var in user get_search_sql

#7 @dd32
7 years ago

  • Keywords 3.2-early added
  • Milestone changed from Awaiting Review to Future Release

All the Search SQL's should have consistent filters to allow for other search engines to be droped in amongst other things.

This needs a review to ensure that all required locations are changed.

#8 @scribu
6 years ago

  • Owner scribu deleted
  • Status changed from new to assigned

@sc0ttkclark
6 years ago

Refreshing this patch w/ 3.5 trunk

#9 @sc0ttkclark
6 years ago

  • Keywords dev-feedback added; needs-review 3.2-early removed

Refreshed the patch on this ticket for 3.5

#10 @scribu
6 years ago

Related: #21803

@sc0ttkclark
6 years ago

Changing to use of apply_filters

#11 @nacin
4 years ago

  • Component changed from Plugins to Query

@wonderboymusic
4 years ago

#12 @wonderboymusic
4 years ago

  • Focuses docs added
  • Keywords needs-docs added; dev-feedback removed
  • Milestone changed from Future Release to 4.0

Refreshed against our new code structure. These need filter docs.

@DrewAPicture
4 years ago

hook docs

#13 @DrewAPicture
4 years ago

  • Keywords commit added; needs-docs removed

15249.2.diff adds hook docs.

#14 follow-up: @SergeyBiryukov
4 years ago

  • Keywords 2nd-opinion added; commit removed

What would be a use case for these filters?

We already have comments_clauses and pre_user_query. We've also added user_search_columns in 3.6.

#15 in reply to: ↑ 14 @DrewAPicture
4 years ago

Replying to SergeyBiryukov:

What would be a use case for these filters?

In retrospect, I'd kind of like to see a consistent approach taken with search SQL filters as alluded to by @dd32 in comment:7. Maybe even a single get_search_sql filter with multiple contexts.

#16 @sc0ttkclark
4 years ago

+1 on get_search_sql single filter

The use case here is for plugins like Pods which may add additional tables to WordPress, to be able to further refine a query to search values in the related table. For instance, someone can extend a Post Type with a table-based Pod, which lets you essentially create a table that contains columns of custom fields and only those fields that you need (each table has a matching id column that matches up to wp_posts).

So, you could provide those custom fields in your query as normal, and Pods will detect if they are covered by the separate table or not, and adjust the query as needed, to be able to join it's table by ID and search that custom field column.

#17 @DrewAPicture
4 years ago

  • Focuses docs removed

@sc0ttkclark: Would you care to patch up a single hook approach instead?

#18 @sc0ttkclark
4 years ago

Sure, sounds good to me.

This ticket was mentioned in IRC in #wordpress-dev by helen. View the logs.


4 years ago

#20 @helen
4 years ago

  • Keywords needs-patch added; has-patch 2nd-opinion removed
  • Milestone changed from 4.0 to Future Release

Sounds like this needs a new patch, and late for 4.0.

#21 @chriscct7
2 years ago

  • Keywords needs-unit-tests added
Note: See TracTickets for help on using tickets.