Problem/Motivation
I get an fatal PHP error when trying to index an aggregated field as full text, using 8.x-1.0-alpha16 with Database as backend.
Indexing the same field as string, or indexing one of the aggregated as fields directly as full text, has no error.
Steps to reproduce:
Add a text field (such as Title) and index it as full text: No error.
Use the same text field as a field in an aggregated field, and index it as String: No error.
Set the type to full text: Fatal PHP error.
PHP Fatal error: Call to a member function getTokens() on a non-object in /var/www/html/ledenvereniging/web/modules/contrib/search_api/search_api_db/src/Plugin/search_api/backend/Database.php on line 1321
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#12 | 2764385-12--aggregated_fields_data_type_processing.patch | 4.44 KB | drunken monkey |
| |||
#12 | 2764385-12--aggregated_fields_data_type_processing--tests_only.patch | 3.82 KB | drunken monkey |
Comments
Comment #2
ekes CreditAttribution: ekes as a volunteer commentedI'm guessing the AggregatedFields plugin addFieldValues() method shouldn't be wrapping the value in an array and using the FieldInterface::setValues() method, but rather adding the string and using FieldInterface::addValue() to allow it to handle processing the value with the correct datatype plugin.
Comment #3
ekes CreditAttribution: ekes as a volunteer commentedAla
Comment #4
ekes CreditAttribution: ekes as a volunteer commentedPop to review, not sure what tests would be covering this one.
Comment #5
ekes CreditAttribution: ekes as a volunteer commentedComment #7
ekes CreditAttribution: ekes as a volunteer commentedJust that one then.
Comment #8
drunken monkeyThe default should be
NULL
, in which case you wouldn't add a value at the end.Or, instead of changing all this, you could leave it as-is and do a
foreach … ->addValue()
afterwards.For tests, see #2752963: rendered_item values overridden by processors – just add them to the existing
AggregatedFieldsTest
and check that all field values are actually passed through the data type plugins (probably by using a mockup data type plugin). (Or, just check that all fields that are of type "Fulltext" have onlyTextValueInterface
objects as values. You can even set all fields to "Fulltext" for that, it shouldn't really matter in any other way.)Comment #9
drunken monkeyThis is how I'd do it. Tests/reviews welcome!
Comment #11
borisson_It feels weird to hint agains the mockobject, if we add any kind of mock here, it should be plugin manager's one.
I did a search in core and it looks like there's a bunch of instances where there's being mocked on
* @var \PHPUnit_Framework_MockObject_MockObject|\Drupal\user\UserInterface
, so we can do something similar if you want to keep the mockOtherwise this looks great, so apart from that I feel this is RTBC. Setting to NW for that small change though.
Comment #12
drunken monkey(I guess you meant "any kind of type hint"?)
The hint for the mock object class is there since we just need the mock object methods. The manager class would be inferred by a properly configured IDE anyways. In this method, we don't need any of its methods, though, so I just type-hinted to the class whose methods are needed.
But if you find that confusing, it's no problem to add the second type hint (I did the same a few times in our code already, too).
Attached a re-roll with the second type hint.
Comment #13
borisson_Yes, thanks for being so kind to listen to my nitpickings :)
Comment #16
drunken monkeyI should be the one thanking you, for your thorough reviews! Usually you're right about such things, so no need to thank me for listening to them.
Anyways, committed. Thanks again for your work here, everyone!
Comment #17
ifrikThanks a lot!
Comment #18
audriusb CreditAttribution: audriusb commentedworks like a charm now