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:
- 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.
- Provide a method for getting an unexecuted clone of a query.
- 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
Comment #2
drunken monkeyThinking about this a bit, I came up with a solution that also solves the
preExecute()problem: a newgetOriginalQuery()method which returns the query in its original – unpreprocessed and unexecuted – form.Feedback on whether this makes sense would be appreciated!
Comment #3
drunken monkeyComment #4
drunken monkeyComment #5
borisson_I don't understand the usecase for this, but if there is a good one - this looks like a very good implementation.
Comment #6
drunken monkeyThanks 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.
Comment #7
drunken monkeyHere's the patch, plus a few improvements.
And here is the change record.
Comment #9
drunken monkeyPhew, OK. Was really worried there for a second …
Comment #10
drunken monkeyComment #11
borisson_Look good to me. Great work!
Comment #13
drunken monkeyAlright, thanks a lot for reviewing!
Committed.