Make WordPress Core

Opened 14 years ago

Closed 3 weeks ago

#15249 closed enhancement (maybelater)

Filtering get_search_sql for advanced queries

Reported by: sc0ttkclark's profile sc0ttkclark Owned by:
Milestone: 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 14 years ago.
Initial Patch including the new filters for Users / Comments
15249.2.patch (954 bytes) - added by sc0ttkclark 14 years ago.
Updated patch for latest SVN Revision (16692)
15249.3.patch (961 bytes) - added by sc0ttkclark 14 years ago.
Updated patch for new $wild var in user get_search_sql
15249.4.patch (1.3 KB) - added by sc0ttkclark 12 years ago.
Refreshing this patch w/ 3.5 trunk
15249.5.patch (1.2 KB) - added by sc0ttkclark 12 years ago.
Changing to use of apply_filters
15249.diff (1.0 KB) - added by wonderboymusic 11 years ago.
15249.2.diff (1.8 KB) - added by DrewAPicture 11 years ago.
hook docs

Download all attachments as: .zip

Change History (29)

#1 @sc0ttkclark
14 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
14 years ago

  • Type changed from feature request to enhancement

#4 @scribu
14 years ago

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

#5 @sc0ttkclark
14 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
14 years ago

Initial Patch including the new filters for Users / Comments

#6 @sc0ttkclark
14 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
14 years ago

Updated patch for latest SVN Revision (16692)

@sc0ttkclark
14 years ago

Updated patch for new $wild var in user get_search_sql

#7 @dd32
14 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
12 years ago

  • Owner scribu deleted
  • Status changed from new to assigned

@sc0ttkclark
12 years ago

Refreshing this patch w/ 3.5 trunk

#9 @sc0ttkclark
12 years ago

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

Refreshed the patch on this ticket for 3.5

#10 @scribu
12 years ago

Related: #21803

@sc0ttkclark
12 years ago

Changing to use of apply_filters

#11 @nacin
11 years ago

  • Component changed from Plugins to Query

#12 @wonderboymusic
11 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
11 years ago

hook docs

#13 @DrewAPicture
11 years ago

  • Keywords commit added; needs-docs removed

15249.2.diff adds hook docs.

#14 follow-up: @SergeyBiryukov
11 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
10 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
10 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
10 years ago

  • Focuses docs removed

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

#18 @sc0ttkclark
10 years ago

Sure, sounds good to me.

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


10 years ago

#20 @helen
10 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
9 years ago

  • Keywords needs-unit-tests added

#22 @sc0ttkclark
3 weeks ago

  • Resolution set to maybelater
  • Status changed from assigned to closed
Note: See TracTickets for help on using tickets.