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

drunken monkey created an issue. See original summary.

drunken monkey’s picture

Issue tags: +release target
drunken monkey’s picture

Component: Framework » Views integration
Status: Active » Needs review
Issue tags: -release target
StatusFileSize
new1.64 KB

Almost trivial patch attached.
Why didn't we do this before the release? But doesn't really matter anyways.

borisson_’s picture

Issue tags: +Needs tests

This new feature needs tests. But it looks really simple, so great work!

Status: Needs review » Needs work

The last submitted patch, 3: 2624876-3--retrieved_properties_query_option.patch, failed testing.

drunken monkey’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new4.03 KB
new4.96 KB

Hm, 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 _object property we use.
Anyways, thanks for reviewing!

borisson_’s picture

Status: Needs review » Reviewed & tested by the community

Adding new tests is always a good thing! They look great.

  • drunken monkey committed 4f16d28 on 8.x-1.x
    Issue #2624876 by drunken monkey, borisson_: Added a query option for "...
drunken monkey’s picture

Status: Reviewed & tested by the community » Fixed

Good to hear, thanks for testing!
Committed.

drunken monkey’s picture

Status: Fixed » Needs review
StatusFileSize
new1.05 KB

Oh, 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).

drunken monkey’s picture

I now even remembered to add our first ever change record for this!

drunken monkey’s picture

Status: Needs review » Fixed

Shouldn't break anything and has been lying around for long enough: committed.

  • drunken monkey committed 20f1d0b on 8.x-1.x
    Follow-up to #2624876 by drunken monkey: Fixed "retrieved properties"...

Status: Fixed » Closed (fixed)

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

murz’s picture

Does this work only for Views, or also must work for custom programmatic queries too? For me it isn't working :(

    $query = Index::load('my_index')->query();
    $query->setOption('search_api_retrieved_properties', ['id', 'title', 'geolocation']);
    $result = $query->execute();
    $resultItem = reset($result->getResultItems());
    dump($resultItem->getFields(FALSE));

- this code dumps empty array of fields.

david.fcondezo’s picture

I've tried it on a custom programmatic query too and no luck.
Did anyone find a solution for this?

ied9185’s picture

According 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']);