Problem/Motivation
In node_search_execute() there is this:
$query = db_select('search_index', 'i', array('target' => 'slave'))->extend('SearchQuery')->extend('PagerDefault');
So there are two query extenders, each decorating the last. Pager needs to be last for paging to work correctly.
However, when execute() is called from PagerDefault, preExecute() is then called before execute() is called on the decorated extender (SearchQuery in this case) object. SearchQuery relies on adding a search_* tag in its execute() method.
By this point preExecute() has already been called from PagerDefault - this then runs hook_query_alter() and any hook_query_TAG_alter()s based on the tags. At this point the search_* tag has not yet been added. So unfortunately, E.g. hook_query_search_node_alter() will never get invoked. Also, hook_query_alter() implementations will never see the search_* tag.
Proposed resolution
Move the adding of search_* tags to preExecute() instead.
Remaining tasks
User interface changes
API changes
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | interdiff-2364069-6.txt | 2.05 KB | damiankloip |
| #6 | 2364069-6.patch | 4.17 KB | damiankloip |
| #2 | 2364069-2-PASS.patch | 4.34 KB | damiankloip |
| #2 | 2364069-2-tests-only-FAIL.patch | 2.8 KB | damiankloip |
Comments
Comment #1
damiankloip commentedComment #2
damiankloip commentedWith some tests...
Comment #4
fabianx commentedGiven this has tests and is easy enough => RTBC
Did we check there is no similar bug in 8.0.x?
Comment #5
David_Rothstein commentedYeah, let's confirm if there is an equivalent Drupal 8 bug first and move the issue there first if so, then backport...
All the code in Drupal 8 looks very similar, so my best guess would be that the bug does exist there too, but I didn't test it.
Comment #6
damiankloip commentedNo, this is not a problem in D8. It was already fixed. Looks like the fix never made it back to D7 - great! ;)
Anyway, the change in 8.0.x is to add the tag in the searchExpression method instead. So let's do that to keep parity between them. Tests should still pass because the tag will be added before preExecute() still.
Comment #7
fabianx commentedRTBC (based on tests still passing), thanks! The backport looks even better!
Comment #10
damiankloip commentedSo that is back then?
Comment #13
damiankloip commentedAnd back.
Comment #16
David_Rothstein commentedTestbot fluke.
Comment #19
David_Rothstein commentedLooks like a testbot fluke.
Comment #22
fabianx commentedComment #25
fabianx commentedComment #26
David_Rothstein commentedCommitted to 7.x - thanks!
Fixed a few small issues with the code comment on commit:
Comment #28
David_Rothstein commentedActually, should these tests (and maybe the code comments that were added here) be forward-ported to Drupal 8?
It seems that Drupal 8 has some tests for the search query altering (see the testQueryAlter() method) but not as comprehensive as the ones here.
Comment #29
hass commentedThis patch is not working properly. Try this:
This goes back to #2116391: Tag user_search_execute() query for realname and other modules and #2117881: How extend query conditions via hook_query_alter()?. I hoped you fixed it here, but no - it is still broken.
Comment #30
damiankloip commenteduser_search_execute doesn't use the Search extender so why should it add those tags? This is working fine.
Also, your example is really bad, with no context.
Comment #31
hass commentedWhat do you mean? Have you seen the lonk to my full example?
The code looks like a generic patch, but is not. It implements inconsistent behaviour and this is bad as every core search should have the same type of tag. User search is missing the tag for sure and I really need this for realname module.
There is a patch in my linked issue. Can you RTBC it, please?
Comment #32
kim.pepperThis looks like it was already done in 8.0.x #1366020: Overhaul SearchQuery; make search redirects use GET query params for keywords
Commit: 4e8713299993549a0841095dfb4ed8aebb72f903
Comment #33
hass commented@kim: #2116391: Tag user_search_execute() query for realname and other modules is not in D8
Comment #34
damiankloip commentedHass. This is a patch for search extender. So I don't see what your problem is. The issue you created looks sensible. This issue is defitiely not to blame though. This is for things using search extender.
Comment #35
jhodgdonThis is actually a duplicate of #1435834: Cannot alter search queries, tag added too late, which was where this was fixed in 8.x and the backport has not happend yet.