Currently the Facet API Taxonomy Sort module makes use of the $facet['field type'] key which is custom to Search API. Therefore this module does not work with Apache Solr Search Integration. However, there is a bug at #1377734: The "field api name" key isn't being populated for facets containing field data which prevents this module from working with Search API if we rely solely on the universal field api name key. A proposed solution would be to leverage the field api name as illustrated at http://drupal.org/node/1361284#comment-5377112 but fall back to the facet's field type key so this module can work with both projects without having to wait for the Search API issue from being resolved.

Comments

cpliakas’s picture

Status: Active » Needs review
StatusFileSize
new2.03 KB

The attached patch implements the proposed solution. The facetapi_taxonomy_sort_is_term_reference_field() function now takes the full facet definition as a parameter so we can determine which key to use.

cpliakas’s picture

StatusFileSize
new2.03 KB

Same patch but with the condition in facetapi_taxonomy_sort_is_term_reference_field() reversed to prevent accidental "assignment in operator" errors from happening in the future.

mrfelton’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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

jyg’s picture

Version: » 7.x-1.0-beta1

Perhaps I did something wrong, but this module does not appear to sort by term weight at all. It did not work as installed. I looked at the code of the actual sort and saw that $a['#taxonomy_weight'] and $b['#taxonomy_weight'] were always empty. Perhaps I am doing something elsewhere to manipulate the term data structures, but I'm surely not directly clearing out an array member with that name!

At any rate, I was getting the regular term information (such as the 'tid' with ['#indexed_value']), so I modified the sort callback as follows. I am not including this as a patch because I do not think people should be applying it, at least not until someone can tell me my hack is justified. I realize there might be a better way to load/cache the terms...

function facetapi_taxonomy_sort_sort_taxonopmy(array $a, array $b) { 
  $ta = taxonomy_term_load($a['#indexed_value']);
  $tb = taxonomy_term_load($b['#indexed_value']);
  $a_count = $ta->weight;
  $b_count = $tb->weight;

  if ($a_count == $b_count) {
    return 0;
  }
  return ($a_count < $b_count) ? -1 : 1;
}

[edit]
Might I be using a too-old version of Apachesolr, and that might be what's causing the weight values to not appear in the data structures supplied to the sort callback? I'm currently using Apache Solr Search 7.x-1.0-beta8. So if I'm wrong in my assumptions above, my code might provide a more complete, backwardly compatible solution.
[/edit]

jyg’s picture

Status: Closed (fixed) » Active
cpliakas’s picture

Status: Active » Fixed

Hi jyg.

I would suggest trying this with the latest versions of Apache Solr Search Integration, Ctools, and Facet API. If the problem persists then please open up a separate issue to we can start debugging. The Apache Solr Search Integration beta8 release is very old, so I would consider that to be an unsupported configuration.

Thanks,
Chris

Status: Fixed » Closed (fixed)

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