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:

  1. Use factory services instead of direct calls to new Query() and new 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.
  2. 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

  1. Add QueryFactory and TermQueryFactory services, used for instantiating Lucene objects.
  2. Add two new event types, triggered after creating the Query object and TermQuery object.
  3. Alter the constructor on SearchParamBuilder to take the above factory services, plus the event dispatcher.
Command icon 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

muriqui created an issue. See original summary.

muriqui’s picture

Status: Active » Needs review
kim.pepper’s picture

This is looking really good. Just some phpcs fails. Also I'm not 100% sure whether we need BC for the SearchParamBuilder constructor args.

kim.pepper’s picture

Status: Needs review » Needs work
muriqui’s picture

Status: Needs work » Needs review

Added backward compatibility and fixed coding standards issues. Pipeline is green now.

kim.pepper’s picture

Status: Needs review » Needs work

Left some feedback.

muriqui’s picture

Status: Needs work » Needs review

Updated per your feedback.

  • kim.pepper committed b47c5d11 on 3.x authored by muriqui
    feat: #3559140 Improve DX for altering query string processing
    
    By:...
kim.pepper’s picture

Status: Needs review » Fixed

Committed to 3.x and cherry-picked to 2.x. Thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • kim.pepper committed d87faa0d on 2.x
    feat: #3559140 Improve DX for altering query string processing
    
    By:...

Status: Fixed » Closed (fixed)

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