I'm using search api with a solr index. When creating a View on the index, I see the Indexed Node: specimen_id field, but no way to use the relationship it is based on. I have an Image node, and specimen_id refers to another node type name Specimen. In the View, I wish to pull the specimen information based on the indexed value of the specimen_id. I try to add a Relationship but Entity Reference does not appear.

As well, I look in the Add Related Fields of the search api index and there is nothing like Parent => child concerning my node types.

Is it not possible to do this?

CommentFileSizeAuthor
#11 single-example.jpg250.63 KBrbruhn
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

linus79’s picture

I've the same problem!

farse’s picture

Yes, it seems to be like this for indexed nodes, although not sure why!

pyxio’s picture

greetings,

did you ever solve this by chance? i am having the same problem... no possibility to get the reference in a views relationship with search api indexed nodes :o(

rbruhn’s picture

@talengix - Well, to give an example: I wanted the scientific name for the specimen the image represented. First, I created a relationship using the "Indexed Node: specimen id" field and named it. Second, I added a field and selected Node in the drop down, which gave me some options for the the available fields. I selected the Scientific Name field. The when applying it, I told it to use the specimen id relationship I created.

Hope that helps. It's been a while since I posted the original but I went through the process with a test view tonight.

pyxio’s picture

hi rbruhn,

Thanks for detailing the process you went through. were you able to select a relationship from the field settings? normally, i get a select list of relationships available. The select list isn't available for indexed nodes as far as I can see. I think what I am trying to accomplish so simple. I just need to limit the indexed nodes displayed to those referencing another node. I've never had a problem doing this before I suppose it is a search api compatibility issue with entity reference. Even in the relationships options.. the typical Entity Reference: options are not available. Do you see them as being available in your search view?

cheers
kevin

rbruhn’s picture

@talengix - The information I selected in Relationships was the Indexed Node specimen id field. I didn't use, nor see, anything about Entity Reference as the specimen_id field is the reference any way.

If you are clicking "add" in the Relationships section, and do not see "Indexed Node" in the Filter drop down, then I"m not really sure what may be wrong. It shows in mine. I'm using Entity Reference 7.x-1.0 and Views: 7.x-3.7

pyxio’s picture

@rbruhn

Thanks again. I definitely see indexed node and field i want to filter by in the relationships drop down menu... i have tried use that field as a filter and a contextual filter to no avail. So, it sounds like my problem and not a compatibility issue if you were able to get your specimen_id field items to be displayed contextually to the node ID. I guess I will need to keep trying ;o) nice to at least know that it does work. Thanks. kevin

rbruhn’s picture

@talengix

Well, maybe I should explain a little bit how my browse/search page works. I have a searchable Browse section that uses the Index and Facet filters. People can browse by image, specimen, location, etc. When browsing by image, the url would like like this: http://drupal.loc/browse?f[0]=type:bir_image
The query string on the end being what is needed by facet api to filter results.... if I remember correctly... its been a long time!!

If someone types a value into the search box, then the url will look like this (keyword = 'acupalpa'): http://drupal.loc/browse/acupalpa
That is where I use the Contextual Filter (Full Text) in my view.

If I use keyword "Image 576266", which is the Title of one of the images, the contextual filter kicks in and gives me that one image, and also includes the Scientific Name I created from the Relationship.

====

I just need to limit the indexed nodes displayed to those referencing another node.

Is the "another node" and indexed node too?
From what you are describing, it sounds like you should be passing the referenced field value (the "another node" id all your other nodes referece) in the URL, using a context filter on that (Which, in reality is going to be Content: Nid), creating a relationship using the field that is the Inexed Node: entity reference field, then select from Fields the Node values you want to display using that relationship. Of course, these are just a bunch of words and may not actually work... lol

pyxio’s picture

@rbruhn

Thanks for the reply. I kinda understand what you are saying... however, i am not necessarily doing much with url other than giving it the node title which as i understand is enough for views to obtain a NID from. Perhaps, if I explain what I am trying to accomplish it will be clearer.

I have two content types... contest and contestant. there is an entity reference field on the contestant content type called field_contest and this connects with a contest node. So now, we have from the contestant node a reference to an available contest node via the entity reference field named field_contest. This field is indexed with search api.

What i need to accomplish is that when a user is viewing a specific contest they see a list of all of the contestants who have chosen to enter that contest. It sounds simple, I know. Very basic. And I can easily achieve this using a standard content view... but the search api view is giving me problems. I have all contestants for all contests showing up in the list and can't for the life of me get any type of filtering to work so that ONLY contestants who have chosen the contest being viewed are displayed.

This sounds a bit different (and less complicated) than your scenario. Given what you know now, how would you go about solving it? Again, thanks so much for the help!

rbruhn’s picture

Well, since you are wanting to list contestants for a particular contest, can't you simply use that on a Contest single view page? You would not need to use the Indexed Node for that, as Indexed Node information is only important when doing searches, right?

I would let people search via fulltext or something on a search page, show a list of contests, and then they can click the contest if they want more information. The single contest view page can then be handled like any normal node page. You will have the Entity Reference in the Relationship drop down. No need to deal with Indexed Node in that case.

Your example fits aptly with my single specimen pages, where a specimen may have multiple images associated with it.

My browse/search can show a list of specimens with some basic information. If they want a more detailed view, they click the link to a single node view page. Contextual Filter -> Content: nid. I pull all the information I want for that specimen. Still within that Single Specimen View, I click add to make another view. I happen to use this view in a QuickTab, but I'm not going to go into all the detail there... lol. But you can create another view like that...like a block or something... using the Contextual Filter->Content: Title, then use the Entity Reference in the Relationship to connect to your contestants. I can't remember which entity reference to use, as in mine I see two possible ones:

1) Entity Reference: Referenced Entity - A bridge to the Content entity that is referenced via specimen_id
2) Entity Reference: Referencing entity - A bridge to the Content entity that is referencing Content via specimen_id

But one of those in your case will return what you want. I believe it is the second one.
Then, when selecting fields, you use the usual Content drop down, and use the relationship you created for every field.

Then it is simply a matter of placing that block view on the single node page. As I said, I use Quicktabs on mine, and panel variants for each of my single node pages.

Does this confuse you more? lol

rbruhn’s picture

FileSize
250.63 KB

Here is an example of one of my single specimen pages that shows the tabs. Each tab is it's own view, using the NID for the specimen, the relationship specimen id, pulling fields for the images that are associated with that specimen id.

pyxio’s picture

@rbruhn

"Well, since you are wanting to list contestants for a particular contest, can't you simply use that on a Contest single view page? You would not need to use the Indexed Node for that, as Indexed Node information is only important when doing searches, right?"

Actually, i want to use search api because i need to be able to filter content with search facets. The first reason is that i think facet functionality is much nicer than views exposed filters. The second is consistency, since I am using the search api indexed nodes throughout the rest of the site. if i switch over to exposed filters for one single content type only it will be awkward imo.

"1) Entity Reference: Referenced Entity - A bridge to the Content entity that is referenced via specimen_id
2) Entity Reference: Referencing entity - A bridge to the Content entity that is referencing Content via specimen_id"

This would be great if these options were available in relationships for indexed nodes... but they are not. which has been my problem since the very beginning and was the impetus of my original post ;o) I sure appreciate you sticking with me and offering tips. If you have anymore I am happy to listen! Cheers kevin

rbruhn’s picture

I messed around with a View based on specimen title or nid, trying to get the associated images. It's not possible. Since my images are the nodes with the specimen_id, that is why I'm able to pull the specimen name when browsing images. When browsing specimens, I cannot pull in image information. Only way I can get it done is the single node page I spoke about.

I don't think this can be handled in Entity Reference module. From what I see in code, it looks like Search API would need to handle any kind of fix, if possible.

pyxio’s picture

Yeah, we have three major modules involved here... views, search api, and entity relationships... very difficult to know who to bring the issue up with. an important one that will be solved eventually by these great contributors. thanks again for the help!

Exploratus’s picture

I would like to be able to use Search API to find nodes / entities by a field from a related entity (entity reference). I tried to follow the thread, but I'm not quite sure. Can one for example find a "album" content type by the value of "singer" (another entity) that reference that album.

B -> references -> a

So I would like to find an "A" content type based on a field value from "B". So the actual reference is on the "B" content, and "A" is being referenced.

guillaumev’s picture

Issue summary: View changes

I'm also not able to use a views relationship to get the fields of a referenced entity in a search api view... Has there been any progress on this ?

pyxio’s picture

guillaumev,

be sure you are using the latest version of entity. it solved all of my problems. cheers

amir_razavi’s picture

@rbruhn
@drupalstrap
I have exactly the same problem! Have you found any solution yet?!

vandung93’s picture

Hi there,
I have 2 content-type, they are "School" and "Course"
Content type school has a field is Entity Reference course.
so what i want to search all Course of the school (nid from url),
I've made a view, with url search/couses/% (nid), but how i can filter course by content id School from url with facet
Because there is no option Entity Reference: Referencing entity in RELATIONSHIPS
Please help me everyone, Sorry for my bad english.

mlima’s picture

@drupalstrap

How did you solve the problem? I'm trying to do the same but no luck.

pyxio’s picture

@m.lima

Solved by using the latest version of Entity module... at least for me. Cheers

chrislabeard’s picture

@drupalstrap

So when you upgraded to the latest version of Entity (dev?). You are now able to add entity reference relationships into your search api view using the node index?

I can't seem to get that same result.

mkinnan’s picture

@chrislabeard

It works, but there isn't a relationship label specifically called "Entity Reference". On the relationships tab of my solr index view, I added the non-indexed option called "Node: the name of your entity referenced field". Then I add non-indexed fields and add the relationship.

I couldn't get this to work at all if you used indexed relationships.

jdesrig’s picture

Unless I'm missing something about this question, I think the solution is pretty simple. When on the search api index field page (such as http://example.com/admin/config/search/search_api/index/[index name]/fields, go to the bottom of the page, find your entity reference field in th dropdown and click add fields. This exposes the fields of the referenced entity so that you can no use them in your view. I was able to do this successfully.
And remember to re-index after you add these fields.

Exploratus’s picture

This issue here is some people are trying to get the referencing entity, not the referenced entity. How do we get the referencing entity?

Chipie’s picture

@mkinnan

How did you set up your solr index? When adding a relationship I only can select "Indexed Node: [field name]" there is no "Node: the name of your entity referenced field".

joshua.howell’s picture

Has there been any progress with this?

Alex72RM’s picture

Thank you so much to jdesrig for #24: I actually solved the issue indexing referenced content too.

Therefore the facet API works in a strange way for referenced content... date are rendered as unix timestamp and integer numbers aren't usable with sliders :(

lukasss’s picture

Issue summary: View changes

Note: This is a multi-valued relationship, which is currently not supported. Only the first related entity will be shown.