I'm not entirely sure if this issue belongs under Field Collection, Commerce, or Search API but I'll start here and hopefully it can be moved as appropriate. I apologize if my description of the issue gets confusing--I'm still trying to work it out in my head.

My goal is to create an index for a product display using Search API.

  • The display has fields, field collections, and a product reference.
  • The referenced product contains nested field collections (field collections within field collections).

Indexing the fields from the field collections seems to work OK, except that it doesn't always show the right fields. When I add a referenced field collection to the Fields tab when editing my index (via Search API), it shows fields from other field collections as if they were a part of that field collection. In some cases, it only shows the wrong fields and the correct ones aren't even mixed in.

An example of this is the 'Specifications' field collection which I have assigned to the product entity. This collection in turn has a 'Temperature range' field collection which specifies a 'Minimum temperature' field and a 'Maximum temperature' field. On the Fields tab of the index configuration, when I reference the 'Referenced product » Specifications » Temperature range' element, it adds fields from other field collections, but does not add 'Minimum temperature' or 'Maximum temperature' as options to index.

I don't seem to have this issue with other entities that I reference when creating the index--only fields actually associated with that entity type are shown. Is there some reason that Search API wouldn't be able to determine the proper fields associated with a nested field collection?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mikemadison’s picture

I've seen some issues similar to this as well. A normal view allows you to fairly easily create a relationship back to the collection, and then add fields individually, or whatever.

When using SearchAPI, it seems very difficult to actually interact with the contents of the collection in a meaningful way through Views itself. I've had to do some funky stuff using the custom php field.

+1

bmcclure’s picture

I still have this issue with my Products index. It seems that any nested Field collections, when added as a relationship in the index config, repeat all parent field collection items (including a recursive reference to itself and its parents)

After a couple of levels deep, I stop seeing any of the fields I should be seeing and only see all of the parent collections' fields.

It seems currently the only way I can access those fields is by storing a Computed Field higher up in the relationship hierarchy storing the value, but that sort of defeats the purpose of using field collections in the first place.

I'm not sure if this issue belongs here or with Field Collection.

Renee S’s picture

Project: Field collection » Search API
Version: 7.x-1.0-beta4 » 7.x-1.x-dev
Component: Code » Miscellaneous

I'm seeing this, and I think it belongs in the Search API as it does have field collection support.

Renee S’s picture

Further to, it seems to index only the first occurrence if I have the same field on multiple collections. It just doesn't seem to iterate through the collections properly.

drunken monkey’s picture

Does it really only index the first one, or is only the first one displayed in Views? Views display is entirely separate from indexing, and in fact even implemented in a different module, the Entity API. That for multi-valued relationships only the first element is retrieved was a deliberate restriction there, as implementation of other ways proved almost impossible. You can try to use the Views Field View module to circumvent this problem.

Regarding the related fields on the index's "Fields" tab always showing all fields added to any bundle on the entity type, and not restricting them to the proper bundle of the relationship: this problem is known, and also pretty much deliberate. Since the bundle information wasn't deemed reliable, we opted to rather show all fields than omit ones that would actually be present. I admit it's more confusing, but at least everything is there that way and no functionality lost ("only" UX). If we could find a reliable way to determine the bundles I'd be not opposed to fixing this, I think that numerous people have that problem, or rather annoyance.

However, regarding some fields not being there, that definitely shouldn't be the case. Maybe these fields don't integrate with the Entity API? Are they available for indexing when put directly on, e.g., nodes?

Renee S’s picture

These are just normal textareas I'm seeing this on. The second instance of the field isn't filled with anything in the solr index, though it is there (ie: bundle1:field_text, bundle2:field_text - indexing only fills whichever was added first in the Search API fields selection page.)

I'll test it added to a node and let you know, but all my node fields, even if multiple, seem to have content.

gilsbert’s picture

Hi Drunken.

All elements are indexed with the following scenario: content type with a multivalued field of type "collection field". The view only display the first element informed on the field but facets are OK (just like you commented at #5).

The only bad thing I could find is that my taxonomy field inside the field collection is not listed at "index hirarchy" option on data alteration. May it be altered or is it intentional?

Regards,
Gilsberty

drunken monkey’s picture

All elements are indexed with the following scenario: content type with a multivalued field of type "collection field". The view only display the first element informed on the field but facets are OK (just like you commented at #5).

OK, yes, this sounds like the known problem mentioned in #5.

The only bad thing I could find is that my taxonomy field inside the field collection is not listed at "index hirarchy" option on data alteration. May it be altered or is it intentional?

This is also a known problem, which sadly cannot really be fixed now. Fields of related entities are generally not available there.

ron_s’s picture

I can confirm that I'm seeing very strange behavior with Search API for field collections. Just attempting to add a field to the index shows incorrect results.

For example, I have a field collection called "field_chairs" and a second field collection called "field_tables". When I add chairs as a field to index, there is no issue. However, when I try to add tables, the fields are displayed as "Chairs » Table Quantity" and "Chairs » Table Type".

I then create facets from these fields, and the Chairs block renders results, but the Tables block does not.

NWOM’s picture

Category: Bug report » Feature request
Status: Active » Closed (duplicate)
Related issues: +#2489142: Add entity type-specific versions of the "Host entity" property

This appears to be a duplicate of #2489142: Add entity type-specific versions of the "Host entity" property for the field collection module which currently has a patch in the works.

NWOM’s picture

Status: Closed (duplicate) » Active
Related issues: -#2489142: Add entity type-specific versions of the "Host entity" property

Never mind, it appears the issue had to do with indexing Field Collections themselves, rather than nested field collections. This is indeed not a duplicate.

drunken monkey’s picture

For example, I have a field collection called "field_chairs" and a second field collection called "field_tables". When I add chairs as a field to index, there is no issue. However, when I try to add tables, the fields are displayed as "Chairs » Table Quantity" and "Chairs » Table Type".

Could you provide more detailed steps for how you're doing this? Or maybe screenshots?

ron_s’s picture

It's done simply by selecting a field collection entity from the "Add related fields" select dropdown at the bottom of the Fields tab. We regularly see options displayed in the Search API settings which are nonsensical.

For example, the following screenshots show a Field Collection called "Space Hours", and the only two fields on space hours are "weekday" and "hours." However when in Search API settings, it displays options such as "Space Hours > Table Type" and "Space Hours > Table Quantity", which are part of an entirely different Field Collection called "Tables". There is no connection between these two .

However, we actually have to select "Space Hours > Table Type" and "Space Hours > Table Quantity" for indexing, otherwise "table type" and "table quantity" are never searchable.

drunken monkey’s picture

The first part is expected behavior. The same happens, e.g., when adding the fields of a node reference – no matter what the content type, the fields from all content types will be included. This is somewhere between hard and impossible to fix, due to technical restrictions.

The second one doesn't sound like it can be true. Can't you just index those fields for a different field collection (where they can actually be present)?
Indexing just these, you might get the option to add, e.g., a Views filter for them, but it won't ever find anything.

ron_s’s picture

no matter what the content type, the fields from all content types will be included. This is somewhere between hard and impossible to fix, due to technical restrictions.

Ok, understood. Maybe worth editing the "Add related fields" message? Instead of:

"There are entities related to entities of this type. You can add their fields to the list above so they can be indexed too."

Can say:

"There are entities related to entities of this type. You can add their fields to the list above so they can be indexed too. Ensure the selected fields are associated with the entity, otherwise the field will not be indexed."
Can't you just index those fields for a different field collection (where they can actually be present)?

At the time I posted the message, "Tables > Table Quantity" and "Tables > Table Type" were not even options in the field list. The only choices related to Tables fields were "Space Hours > Table Quantity" and "Space Hours > Table Type".

Something must have changed between then and now, because I'm now seeing "Tables > Table Quantity" and "Tables > Table Type" as options. If I configure them as the other fields are configured, the values are indexed and rendered correctly.

drunken monkey’s picture

Category: Feature request » Support request
Status: Active » Fixed

OK, good to hear you could fix it!
I don't think that description text is the right place to point out this potentially puzzling behavior. But feel free to add it to the FAQ or the index settings documentation.

Status: Fixed » Closed (fixed)

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

ron_s’s picture