Problem/Motivation
When you create an Aggregate field Data alteration Filter on an Index, you can choose an Aggregation type. One of the Aggregation types is Fulltext which processes the data as follows...
return isset($a) ? $a . "\n\n" . $b : $b;
... this code is in the function \SearchApiAlterAddAggregation::reduce().
An administrator may want to use a separator other than two newline characters.
Proposed resolution
Turn the separator into a configuration option, expose the configuration option to the administrator.
Remaining tasks
- Determine if it is possible to access configuration options in \SearchApiAlterAddAggregation::reduce().
- Write a patch that adds the configuration option to \SearchApiAlterAddAggregation::configurationForm() and company, and uses the configuration option in \SearchApiAlterAddAggregation::reduce().
- Review and feedback
- RTBC and feedback
- Commit
User interface changes
New configuration option when adding an aggregate field.
API changes
New configuration option in \SearchApiAlterAddAggregation.
Fulltext aggregate field could separate items with something other than two newlines.
Data model changes
None.
| Comment | File | Size | Author |
|---|---|---|---|
| #14 | 2855447-14.patch | 8.1 KB | alexdoma |
| #12 | 2855447-11--concat_aggregation_separator.patch | 7.98 KB | drunken monkey |
Issue fork search_api-2855447
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 #2
mparker17Note that #1357070: Allow multiple value string aggregated fields is similar (it adds a List reductionType). This solution is different because it still produces a Fulltext reductionType, it just lets the admin choose the string between the first and second value.
Comment #3
mparker17Here's a simple patch. Feedback welcome.
Comment #4
drunken monkeyThanks a lot for this suggestion! Seems like a simple and nice-to-have feature.
The patch also looks quite good, thanks!
A few suggested improvements:
Comment #6
drunken monkeyCommitted.
Thanks again for your work!
Comment #7
drunken monkeyComment #10
edurenye commentedI mage a merge request, I'm not sure how to deal well with the configuration, but I think this relates more to a more general issue, maybe we should add the aggregate_field types as plugins by themselves or move all that into a sub-module like is proposed here: https://www.drupal.org/project/search_api/issues/3220868
Comment #11
drunken monkeyThanks a lot for that, already looks quite good!
Unfortunately, testing for our MRs still doesn’t seem to work, so switching to patches. The attached one includes a few minor updates to your code style, a description for the form field (non-trivial, after all), escaping for the form field values and tests.
Please test/review!
Also, stumbled upon #3280916: Field configurations do not correctly include defaults while testing – apparently, we do need those
?? "\n\n"snippets for now, so leaving those in.Comment #12
drunken monkeyComment #13
alexdoma commentedre-roll for drupal 9.5.9
Comment #14
alexdoma commentedfix previous patch - set correct paths, re-roll for drupal 9.5.9
Comment #16
drunken monkeyLooks good, thanks for re-rolling!
I assume this means the patch was also working for you, so I think we can proceed. I just fixed the method signature of
testAggregation()and removed the emptytestPropertyConfigurationForm()method and then merged.Thanks again!