Define a way for the search query to specify which fields should be returned by the service class, if it supports this functionality (like Solr does). This would enable service classes to avoid retrieving all fields when only a few are actually needed.
This doesn't really need any support from the framework, it can just be a search query option which is set in the Views integration and which some backends recognize – there doesn't even need to be a feature.
(However, by supporting it explicitly on the query class, we can maybe use this to unify field data extraction among the different search UIs. Or is Utility::extractFields() good enough for that?)
Comments
Comment #2
drunken monkeyComment #3
drunken monkeyAlmost trivial patch attached.
Why didn't we do this before the release? But doesn't really matter anyways.
Comment #4
borisson_This new feature needs tests. But it looks really simple, so great work!
Comment #6
drunken monkeyHm, since it's just a small, optional feature of the Views integration, I wouldn't have thought tests were necessary. However, they're easy enough to add, so sure, why not?
Also, we should mention the special
_objectproperty we use.Anyways, thanks for reviewing!
Comment #7
borisson_Adding new tests is always a good thing! They look great.
Comment #9
drunken monkeyGood to hear, thanks for testing!
Committed.
Comment #10
drunken monkeyOh, a bit too late, but if we do it like this instead we avoid messing the Views preview up with this option (which can take up quite a bit of space).
Comment #11
drunken monkeyI now even remembered to add our first ever change record for this!
Comment #12
drunken monkeyShouldn't break anything and has been lying around for long enough: committed.
Comment #15
murzDoes this work only for Views, or also must work for custom programmatic queries too? For me it isn't working :(
- this code dumps empty array of fields.
Comment #16
david.fcondezo commentedI've tried it on a custom programmatic query too and no luck.
Did anyone find a solution for this?
Comment #17
ied9185 commentedAccording to this, the option name should be: 'search_api_retrieved_field_values'
In my case, it worked with:
$query->setOption('search_api_retrieved_field_values', ['id', 'field_XXX', 'field_YYY']);