Unless I'm mistaken, there is currently no way to re-execute an executed search query (other than manually passing it to the search server, I guess). We should therefore add a way to do that. I see several options:

  1. Provide something like a reexecute() method (or maybe just a $force flag to execute()?), or a method to reset the query to its unexecuted state. With this approach, the results of the original query would have to be removed from the query object and therefore get lost.
  2. Provide a method for getting an unexecuted clone of a query.
  3. Just make the built-in clone default to producing an unexecuted query. I can't really think of a use case for cloning a query along with its result set – so this might be OK? It would change current behavior, though, so probably not a good idea to do at this stage.

In all those cases, we should probably take care not to run hooks and processors on the query twice so, when re-executing a query, preExecute() should probably not do anything. (I think. Not sure, though. Maybe leave that to callers via setProcessingLevel()?)

Comments

drunken monkey created an issue. See original summary.

drunken monkey’s picture

Status: Active » Needs review
Issue tags: +Needs tests

Thinking about this a bit, I came up with a solution that also solves the preExecute() problem: a new getOriginalQuery() method which returns the query in its original – unpreprocessed and unexecuted – form.

Feedback on whether this makes sense would be appreciated!

drunken monkey’s picture

StatusFileSize
new2.05 KB
drunken monkey’s picture

Issue tags: +Needs change record
borisson_’s picture

I don't understand the usecase for this, but if there is a good one - this looks like a very good implementation.

drunken monkey’s picture

Status: Needs review » Needs work

Thanks for your feedback!
The use case is saved searches: #2955617: The serialized query is already executed. Without this, we have a hard time executing the query again later to check for new results.

OK, then setting to NW for the tests.

drunken monkey’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests, -Needs change record
StatusFileSize
new2.78 KB
new4.21 KB

Here's the patch, plus a few improvements.
And here is the change record.

Status: Needs review » Needs work

The last submitted patch, 7: 2955887-7--get_original_query.patch, failed testing. View results

drunken monkey’s picture

Phew, OK. Was really worried there for a second …

drunken monkey’s picture

Status: Needs work » Needs review
borisson_’s picture

Status: Needs review » Reviewed & tested by the community

Look good to me. Great work!

  • drunken monkey committed 8859b8d on 8.x-1.x
    Issue #2955887 by drunken monkey, borisson_: Added a way to re-execute a...
drunken monkey’s picture

Status: Reviewed & tested by the community » Fixed

Alright, thanks a lot for reviewing!
Committed.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.