I tried using the index hierarchy setting for taxonomy terms with all parents and on two websites I received following PHP error when indexing:
"Fatal error: Maximum function nesting level of '500' reached, aborting!" which is caused by SearchApiAlterAddHierarchy->extractHierarchy( ).

On another website it did work (at least not this error), so I'm not yet sure why this bug occurs. Likely it depends on the vocabulary.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

fangel’s picture

I'm having the same issue - and I believe it's to do with if (search_api_is_list_type($wrapper->type())) {, that then tries to loop through each item - this doesn't appear to work, so it calls itself with the a wrapper that is still a list, and hence it repeats.

It might only trigger if the taxonomy-field allows multiple values.

mh86’s picture

I'm using the parents_all property on the term fields in the meanwhile (add the term reference field as relation first), works fine.

fangel’s picture

Hmm, I was wrong - it wasn't because of the type. It was because parents_all on taxonomy-terms includes itself as one of the parents (or so it seems). I tweaked the code to only call itself recursively if the term hadn't already been seen. This seems to solve the problem for me.

fangel’s picture

Yup, $wrapper->parents_all on a taxonomy-term does indeed return itself as one of its parents..

Here's my test-code:

  $term = taxonomy_term_load(8916);
  $wrapper = entity_metadata_wrapper('taxonomy_term', $term);
  var_export($wrapper->parents_all->value());

Output

array(
  (object) array(
      'tid' => '8916',
      'vid' => '27',
      // SNIP
    ),
  (object) array(
      'tid' => '8915',
      'vid' => '27',
      // SNIP
    ),
  (object) array(
      'tid' => '8911',
      'vid' => '27',
      // SNIP
    ),
)

As seen, term-id 8916, has the parent 8915, which has the parent 8911 - but when getting the parents of 8916, it returns 3 because it includes itself.

So I believe I'm right in only recursing when the value we're looking at haven't already been added to $values. Otherwise we end up looking at the term itself again, which leads us straight back to where we just were.

--

I haven't tested it, but because the recursion only seems to be limited by the property not being set or having an empty value, wouldn't simply looking at the parent-property also include all parents? Because it calls itself on the parent, which calls itself on it's parent etc until we no longer have a parent (ie the root term).

fangel’s picture

Status: Active » Needs review

Marking as needs-review so we can get people to test this out.

jsacksick’s picture

Status: Needs review » Reviewed & tested by the community

I tested the patch and it worked for me.

bago’s picture

Worked for me too!

BTW after fixing this I found that the db backend doesn't correclty index parents if your field is a "single value term" field: http://drupal.org/node/1494502

jsacksick’s picture

This is fixing the other issue or creating it ?

bago’s picture

@jsacksick: it doesn't fix or create it. I just reported it as "related" as in my case the indexing failed and I found this issue. I applied this patch and the indexing still failed, but then I discovered that I had 2 concurrent bugs and this patch fixes one of them (but I still couldn't index because of the other issue: now I found a workaround for the other issue and, with the help of the patch at #3, I can finally index my term hierarchies).

jsacksick’s picture

Status: Reviewed & tested by the community » Fixed

Commited in the dev branch. Thanks.

fangel’s picture

Awesome, thank you. (PS, you accidentally set the wrong author on the commit)

jsacksick’s picture

Sorry man... I did it quickly this morning...

jaypark’s picture

fangel, how are you getting any response other than

EntityMetadataWrapperException: Unknown data property field_group. in EntityStructureWrapper->getPropertyInfo() (line 339 of entity.wrapper.inc).

i get that response from

$w=entity_metadata_wrapper('taxonomy_term', taxonomy_term_load(22));
drupal_set_message(print_r($w->field_group->value()));

field_group is a term reference field (yes, for a term).

...i can't get any value inside data at all - gives a similar exception about unknown data property. when just printing out the wrapper contents, data is defined as "stdClass Object" type, not a property.

is $wrapper->field->value() not supported for anything other than nodes?

fangel’s picture

Jaypark, Hmm - I never tried fields on taxonomy-terms, but I have used entity-wrappers to get the contents of fields on users, so I believe they should work. What does print_r($w->value()) give you?

Also, this is a closed issue on a only-semi-related issue, so this really isn't the correct place to ask questions - just fyi.

Status: Fixed » Closed (fixed)

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