Problem/Motivation
If a developer wants to change the query string/term processing behavior for their site—for example, to make use of Query::OP_REQUIRE or change the handling of certain terms—they currently need to either patch the module or override the SearchParamBuilder service and re-implement the buildSearchString method to inject their own logic. Either approach is difficult to maintain, requiring you to re-roll the patch or update your overridden implementation to maintain parity when a new module version is released. It would be more convenient if the service offered opportunities for other modules to alter its logic.
Proposed resolution
Change SearchParamBuilder::buildSearchString to do the following:
- Use factory services instead of direct calls to
new Query()andnew TermQuery(), allowing site maintainers to override these factories to instead return their own classes that extend the Lucene objects. These extensions could, for example, know how to react to options set by a custom @SearchApiParseMode plugin. - Dispatch events when setting options on the Query and TermQuery objects, allowing custom event subscribers to alter the values set on these objects.
API changes
- Add QueryFactory and TermQueryFactory services, used for instantiating Lucene objects.
- Add two new event types, triggered after creating the Query object and TermQuery object.
- Alter the constructor on SearchParamBuilder to take the above factory services, plus the event dispatcher.
Issue fork search_api_opensearch-3559140
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
muriqui commentedComment #4
kim.pepperThis is looking really good. Just some phpcs fails. Also I'm not 100% sure whether we need BC for the SearchParamBuilder constructor args.
Comment #5
kim.pepperComment #6
muriqui commentedAdded backward compatibility and fixed coding standards issues. Pipeline is green now.
Comment #7
kim.pepperLeft some feedback.
Comment #8
muriqui commentedUpdated per your feedback.
Comment #10
kim.pepperCommitted to 3.x and cherry-picked to 2.x. Thanks!