Hi guys,

I want to add a facet search "City" that uses an aggregated field. But I am confused about how to do it given my structure.

You can see my structure in the image below. All rectangles are simple node types. All arrows are entity references fields.

UML Diagram

I want to aggregate the city both by the entity reference from two fields:

  1. The first field is: "Activity->Done in city" (here there is a direct referencing).
  2. The second field is: "Activity->Done in institution->Located in city" (there are two references here, the city is indirectly referenced by Activity, this time through Institution).

How can I do it? Which fields I have to add to the indexing and later to aggregate?

Any help is appreciated!

Thanks.
---

NOTE 1

The diagram in the image abouve can be generated using the tool yUML.me entering this script:
[Activity]->Done in institution[Institution]
[Activity]->Done in city[City]
[Institution]->Located in[City]

NOTE 2
There is no redundancy in the structure. Sometimes the user who enters data into an Activity node does not know in which institution the activity took place, but she does know in which city it took place.

CommentFileSizeAuthor
b75c5be8.png9.42 KBamir simantov

Comments

Amir Simantov created an issue. See original summary.

drunken monkey’s picture

Status: Active » Fixed

It’s pretty clear which properties you need to add: “Done in city” (property path: field_done_in_city) and “Done in institution » Content » Located in” (property path: field_done_in_institution:entity:field_located_in) – names and machine names may differ, of course.
Only two problems:

  1. The UI doesn’t let you pick nested fields as part of an aggregated field. However, it works perfectly fine when just manually adding the property path to the search index’s exported config (either in a file, or via the „Single export”/“Single import” config UI).
  2. The aggregated values (referenced nodes’ IDs) will just be treated as plain integers, any information that these are actually node references is unfortunately lost. So, the facet in your case would just display the plain IDs, not the node titles. You’d need some custom code to fix that.
amir simantov’s picture

Issue summary: View changes
amir simantov’s picture

Thanks Thomas.

Closing. As I am going to face custom code here anyway, I am ending up doing something else.
Commenting here for the sake of documenting and helping others.

My alternative approach is to copy the value on node saving. Then, simply filter by one value (Activity->City).

1.
ON: Activity saved
OPERATION: Copy nid
FROM: Activity->Institution->City
TO: Activity->City

2.
ON: Institution saved
OPERATION: Update nid
FROM: Institution->City
TO: Activity->City
WHERE: There are activity nodes referencing the institution.

ASSUMPTION: Institution->City is a required field.
NOTE: activity editing form prevents the user to fill in both institution and city.

amir simantov’s picture

Status: Fixed » Closed (fixed)