We are working on 2 projects that have the following scenario:

Organizations are working in 1 or more districts. Show a list with the name of an NGO and the district where the NGO is active. 1 District per line.

Using normal nodes + a taxonomy term field, Views will return multiple lines for 1 NGO, for each District that they are active in.

When configuring the same, using the search_api (and thus entities), this is not possible, as it is not implemented. It generates the message from the subject in the relationship configuration screen. (from entity_views_handler_relationship.inc )

Can we use this issue to find an approach for implementing this functionality?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

fago’s picture

Status: Active » Closed (won't fix)

No, that's not easily possible as values are not retrieved per SQL but via doing entity-loads. Thus, we have only one row per entity and nothing we can do about that.

batje’s picture

i never thought it would be easy, or finished tomorrow.

what would be possible (uneasy) strategies to make this possible, eventually?

batje’s picture

Status: Closed (won't fix) » Postponed

let set some expectations, without ruling it out completely

batje’s picture

Is there anyone who would like to take this on as a paid job?

jsacksick’s picture

Status: Postponed » Needs review
FileSize
7.86 KB

This patch should fix the issue, it has been done by Damien Tournoud.

batje’s picture

I really like Damien Tournoud. It seems his patch is working for me. I tested this using search_api & search_api_solr.

I hope others can test the patch too.

jsacksick’s picture

There was a small bug, here is the new patch.

Letharion’s picture

I was tearing my hair out over search api indexes not showing up in list of view bases. #7 fixed it.

jsacksick’s picture

This is weird because this isn't related. Anyway if you apply this patch... you should apply this one also
#1452018: Update search api views integration according to Entity views update

And I also submit a new version because there were a remaining bug in the Entity views handler helper patch.

mkostir’s picture

Hi guys,
I applied the patch from #9 as well as #1452018.
However no luck.
Once I create relationship to the reffered field, I get the following error:

An AJAX HTTP error occurred.
HTTP Result Code: 500
Debugging information follows.
Path: /austat01/admin/structure/views/view/indexedteachers03/preview/page/ajax
StatusText: Service unavailable (with message)
ResponseText: EntityMetadataWrapperException: There can be only numerical keyed items in a list. in EntityListWrapper->get() (line 953 of /var/www/austat01/sites/all/modules/entity/includes/entity.wrapper.inc).

Could anyone give me any suggestions please?

jsacksick’s picture

Can you give more details please ? Which kind of view ... which field etc ?

mkostir’s picture

So the scene is following.
I have content node called Location (geofield, addresfield, geocoder fields).
Than I have bunch of users each with entityreference to the location. (Each user can reside in one or more locations).
Than I run SolrServer and index the users, which gives me a reference for the location fields via the entityreference.

I make views, with base table based on that UserIndex. All works well - gives me list of all users and allows me to use faceted search (suburb / postcode), however the views list all users only once - with the first instance of the location (if given user has more locations assigned). I would like to have the output of the views each row one user and one location, so the users with more locations will be repeated.

That would normally be done (without solr) via relationship (joining the users and locations together via the entityreference field).

Now I assumed the patches here would allow for that while using the Solr.
The Views fields are really just "user name" and then "location name". I tried many combinations of the fields, but all give the same error.

Hope that is enough info. If more needed, I will gladly provide.
Thanks so much for making efort. It is greatly appreciated.

jsacksick’s picture

jsacksick’s picture

jsacksick’s picture

drunken monkey’s picture

I'm pretty sure (can't test, see below) the patch in the current form messes up paging, a problem that I think is inherently insoluble, unless we completely rebase the system (essentially querying for a complete list of results and then using a normal database view to display them – the first approach back from 2008). This is also what kept fago and me from doing this right when we first implemented this Views integration.

Other, less elementary complaints:
get_result_entities() isn't defined by us, but by Views itself. We can't therefore just change its signature, which is (if I recall correctly) also the reason why we left the relationship-resolution in the query plugin.
Leaving the signature as-is and just letting the relationship default to NULL should be fine, though.

Also, when testing this I got the same error as #10. I had a node index and added a relationship to a field with multiple taxonomy terms.

noahadler’s picture

Could you elaborate more on what causes the paging to mess up, and why it's insoluble? IIRC, Solr returns its own numbers for paging, but I'm less familiar with views.

yechuah’s picture

15 works for me. adding relationship on search api view

maxplus’s picture

Hi,
thanks for the good work but i tried patch #15 on the current dev of Entity API and when I reload my view I get the error "EntityMetadataWrapperException: Unknown data property field_team_lid_field_team_lid. in EntityStructureWrapper->getPropertyInfo() (regel 339 van /Library/Server/Web/Data/Sites/.../sites/all/modules/entity/includes/entity.wrapper.inc).

I think I wont use a multi relationship until the issue is solved.

alanom’s picture

This is a pretty big deal so it would be valuable if we could share our experiences with this to see exactly what works, what breaks and what needs work.

For me, trying out patch #15 with a Search API Solr "More like this" view and a Relation module Views relationship linking an Indexed Node to the other node referenced in a Relation entity, after also applying the Search API patch here ( #1452018: Update search api views integration according to Entity views update ) I see:

  • Before applying the patch, fields using the relationships just return data from the original indexed node (the first in the relationship - it doesn't go anywhere, regardless of directionality of the relation)
  • After applying the patch, the relationships work - data from the correct related entity is returned. However, it creates duplicate rows, and it confuses the paging as expected. On AJAX paging, paging works but a seemingly random number of records are shown per page. On non-AJAX paging, it seems to simply not work at all, not even showing the paging options and showing a drastically shortened set of results.

Looks like it still needs a lot of work.

giorgio79’s picture

In simple views, after one adds a relationship we can select the relationship that a field should use. I notice this feature is entirely missing in Search API Views. Could this be a possible route of attack?

rcodina’s picture

Issue summary: View changes
Status: Needs review » Needs work

Patch on #15 works for me on a map view which uses search api solr (the paging issue doesn't matter), but from the previous comments I guess that this may need some additional work.

rcodina’s picture

In my case, this patch solves the issue for my map view. However, I'm afraid it jeopardizes the rest of my views. For now I will keep the patch running because I haven't found any workaraound yet and because the rest of my views have non-AJAX paging.

rcodina’s picture

Well, finally I had to install Views Distinct module because I found out duplicates in some views.

petednz’s picture

I needed to show multiple tags on a view displaying nodes that had been indexed. I ran in to this issue that "This is a multi-valued relationship, which is currently not supported. Only the first related entity will be shown".

I decided to give https://www.drupal.org/project/views_field_view a go since it has gotten me out of corners before. Glad to report it worked in my situation and I now have multiple tags showing on my indexed search results.

For anyone wanting the recipe (though it seems out of place in such a technical post):
- create a new View based on Content for types involved and set just the relevant 'term' field as the display (you don't need to create any views displays).
- set Contextual filter to nid with 'provided default value = raw value from url' (outcome should be if you enter the nid you should see relevant tags in preview). Save
- install/enable https://www.drupal.org/project/views_field_view
- over in the view that is rendering the search results (searchapi)
- made sure you have Indexed Content: Node ID field already in your Fields, and set to not display
- add a new field of type Global: View
- in the 'view settings' of this field, find the view you made above, set the right display or use Master if you didn't make any (because you didn't need to),
- in Contextual Filter, check your Replacement Patterns where you should have [%nid] == Indexed Content: Node ID (rendered), and enter [%nid]
- save and I hope you get to smile like i just did.

xenophyle’s picture

@petednz That was exactly what I needed. Thanks!

petednz’s picture

Excellent

drupaljunior’s picture

Really thank you for this hint @petednz, it is working for me also.
Now I have an additional question: from the external view (search api view) is it possible to filter out the Nodes for which the inner view has no results? I make an example.

Actual View:
- Node A
- - term 1
- - term 2
- Node B
- Node C
- - term 3

Desired View:
- Node A
- - term 1
- - term 2
- Node C
- - term 3

(Node B is not shown because the inner view returns empty output for B)

Many thanks in advance for any hint.

drunken monkey’s picture

Now I have an additional question: from the external view (search api view) is it possible to filter out the Nodes for which the inner view has no results? I make an example.

I guess you can index the relationship and then use an "is not empty" filter on it in Views?

maxplus’s picture

Hi,

@petednz:
thanks for your inventive solution.
I have also used it on a node product grid view to show the lowest price from all the referenced product variations.

However, I'm not sure what the performance impact is in my use case.
Because now for showing a price for a single product on my grid I'm always rendering the embedded price view over and over again for every product display node on the grid

petednz’s picture

maxplus what are you doing in way of caching the views - both the views_field_view and the 'parent' view

blueblot’s picture

@petednz thx for the smile.
Was looking for this solution for a while.
Works perfect.