In the SearchQuery extender, we add an alter tag like this:
$this->addTag('search_' . $this->type);

The problem is that this doesn't happen until the execute method is called, meaning that drupal_alter() has already happened (which gets done in preExecute()). The alter tag needs to be added as soon as we know the type of the query in order for it to be available to modules implementing hook_query_search_TYPE_alter(). Additionally, the preExecute method is where the first pass should be run in order to ensure that it happens before execute(), and has the power to stop the query from running.

For some background on this issue, see #997976: Add tag to node search query and #496516: Move query_alter() into a preExecute() method.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rbayliss’s picture

Here is a test that illustrates the problem. This should fail.

rbayliss’s picture

And here is a patch including the test, with a fix to SearchQuery to move tagging into searchExpression(), and moving the first pass and associated metadata into preExecute(). This should pass.

rbayliss’s picture

Status: Active » Needs review
kscheirer’s picture

#2: 1435834-search_query_alters-3.patch queued for re-testing.

kscheirer’s picture

Retesting against latest HEAD since it has been over a year.

Status: Needs review » Needs work

The last submitted patch, 1435834-search_query_alters-3.patch, failed testing.

jhodgdon’s picture

I think we should address the moving of the normalization elsewhere -- it is not a good idea to combine issues.
See #582938: Fix up documentation and member names in SearchQuery

Anyway, this patch will need a reroll, but we should probably get it done. It should be limited to changing the tag stuff. Thanks!

jhodgdon’s picture

I just marked #1146564: Search extender tags never 'hook'ed as a duplicate of this issue. It also has a patch.

jhodgdon’s picture

Issue summary: View changes
Status: Needs work » Postponed

I have possibly taken care of this issue on #1366020: Overhaul SearchQuery; make search redirects use GET query params for keywords, so postponing until that is complete.

jhodgdon’s picture

Status: Postponed » Active
Issue tags: +Needs tests, +Needs backport to D7

I believe we fixed this on #1366020: Overhaul SearchQuery; make search redirects use GET query params for keywords (the tag is now added in SearchQuery::searchExpression() instead of later), but we should probably make sure by writing a test. It also needs a backport to D7.

brockfanning’s picture

If I understand right the next steps needed are a D7 patch limited to the tagging part only? If so, here's a reroll of rbayliss' patch along those lines.

brockfanning’s picture

Status: Active » Needs review
jhodgdon’s picture

Version: 8.x-dev » 7.x-dev

Forgot to set version to 7.x.

Status: Needs review » Needs work

The last submitted patch, 11: 1435834-search_query_alters-11.patch, failed testing.

jhodgdon’s picture

Status: Needs work » Needs review
jhodgdon’s picture

The failed test was against 8.x because the version was wrong. Now testing on 7.x.

brockfanning’s picture

Oops, thanks for that.

jhodgdon’s picture

Status: Needs review » Needs work

I have reviewed this patch and the test...

The code patch looks fine in search.extender.inc.

However, the test is not useful, in my opinion. We have a Drupal 8 SearchQueryAlterTest and a search_query_alter module, and they actually are good tests. We should just port that test and module to Drupal 7.