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?
Comments
Comment #1
fagoNo, 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.
Comment #2
batje CreditAttribution: batje commentedi never thought it would be easy, or finished tomorrow.
what would be possible (uneasy) strategies to make this possible, eventually?
Comment #3
batje CreditAttribution: batje commentedlet set some expectations, without ruling it out completely
Comment #4
batje CreditAttribution: batje commentedIs there anyone who would like to take this on as a paid job?
Comment #5
jsacksick CreditAttribution: jsacksick commentedThis patch should fix the issue, it has been done by Damien Tournoud.
Comment #6
batje CreditAttribution: batje commentedI 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.
Comment #7
jsacksick CreditAttribution: jsacksick commentedThere was a small bug, here is the new patch.
Comment #8
Letharion CreditAttribution: Letharion commentedI was tearing my hair out over search api indexes not showing up in list of view bases. #7 fixed it.
Comment #9
jsacksick CreditAttribution: jsacksick commentedThis 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.
Comment #10
mkostir CreditAttribution: mkostir commentedHi 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:
Could anyone give me any suggestions please?
Comment #11
jsacksick CreditAttribution: jsacksick commentedCan you give more details please ? Which kind of view ... which field etc ?
Comment #12
mkostir CreditAttribution: mkostir commentedSo 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.
Comment #13
jsacksick CreditAttribution: jsacksick commentedComment #14
jsacksick CreditAttribution: jsacksick commentedComment #15
jsacksick CreditAttribution: jsacksick commentedComment #16
drunken monkeyI'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.
Comment #17
noahadler CreditAttribution: noahadler commentedCould 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.
Comment #18
yechuah CreditAttribution: yechuah commented15 works for me. adding relationship on search api view
Comment #19
maxplus CreditAttribution: maxplus commentedHi,
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.
Comment #20
alanom CreditAttribution: alanom commentedThis 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:
Looks like it still needs a lot of work.
Comment #21
giorgio79 CreditAttribution: giorgio79 commentedIn 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?
Comment #22
rcodina CreditAttribution: rcodina commentedPatch 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.
Comment #23
rcodina CreditAttribution: rcodina commentedIn 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.
Comment #24
rcodina CreditAttribution: rcodina commentedWell, finally I had to install Views Distinct module because I found out duplicates in some views.
Comment #25
petednz CreditAttribution: petednz commentedI 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.
Comment #26
xenophyle CreditAttribution: xenophyle commented@petednz That was exactly what I needed. Thanks!
Comment #27
petednz CreditAttribution: petednz commentedExcellent
Comment #28
drupaljunior CreditAttribution: drupaljunior commentedReally 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.
Comment #29
drunken monkeyI guess you can index the relationship and then use an "is not empty" filter on it in Views?
Comment #30
maxplus CreditAttribution: maxplus commentedHi,
@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
Comment #31
petednz CreditAttribution: petednz commentedmaxplus what are you doing in way of caching the views - both the views_field_view and the 'parent' view
Comment #32
blueblot CreditAttribution: blueblot commented@petednz thx for the smile.
Was looking for this solution for a while.
Works perfect.