Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Currently, there are no options for sorting facet links by the weight of taxonomy terms in the facet settings page. I am using Search API that supports hierarchical indexing of taxonomy terms as mentioned by cpliakas here, but it doesn't seem to make them to follow the order of taxonomy term weight.
I have been searching for solutions for awhile but nothing helps. Is it a feature that needs to be implemented by Facet API?
Sorry for my bad English, I hope you understand what I mean. Thanks!
Comments
Comment #1
cpliakas CreditAttribution: cpliakas commentedThis is an interesting use case, and I thinks a useful one as well. I am not sure if it will get into the core Facet API module, but the API should be flexible enough to support this. Trying to resolve the stable release blockers first, however I do want to try this out to see if the current API would allow for this. Would love to get feedback from other people's attempts as well.
Thanks,
Chris
Comment #2
cpliakas CreditAttribution: cpliakas commentedSo looking at the current API this isn't possible without a lot of hacking. I think if we work on the issue posted at #1304820: Implement a hook that can alter facet data after it is returned from the server, then it would le pretty easy to add the taxonomy weight then filter by that value implementing hook_facetapi_sort_info() with a simple callback. Once I resolve the dependent issue I will post the taxonomy code here.
Comment #3
cpliakas CreditAttribution: cpliakas commentedIn addition, #1367964: Add requirements to sort info would also help this use case.
Comment #4
cpliakas CreditAttribution: cpliakas commentedFirst crack at this. With the patch applied at http://drupal.org/node/1304820#comment-5352346, the following code in a custom module named "mymodule" will allow you to sort facets by term weight. The requirements piece still has to be worked out, and I am also still deciding whether this should go in the core module or be implemented in contrib. I am leaning towards contrib.
Comment #5
foopang CreditAttribution: foopang commented@cpliakas, you are awesome! Thanks so much for your help! Appreciate your efforts on it:)
Comment #6
cpliakas CreditAttribution: cpliakas commentedComment #7
cpliakas CreditAttribution: cpliakas commentedThis seems like a nice little contributed module. The code below works with the patches applied at #1304820: Implement a hook that can alter facet data after it is returned from the server and #1367964: Add requirements to sort info. Adding to the "Contrib" tag since this should be added outside of Facet API.
Comment #8
foopang CreditAttribution: foopang commentedThe contrib module works just perfectly. Thanks cpliakas!
Comment #9
cpliakas CreditAttribution: cpliakas commentedThanks for testing. Marking as fixed. If someone decided to take this module on as their contrib, please post so multiple people don't create the same thing :-).
Comment #10
mrfelton CreditAttribution: mrfelton commentedCode added to a sandbox project at http://drupal.org/sandbox/mrfelton/1377366
@cpliakas - I'm not really clear why in your code you were loading the field with field_info_field() based on $facet['field api name']. I found that $facet['field api name'] is always simply FALSE, so this wasn't working at all. I adjusted the code so that it instead just looks at the value of $facet['field type'] and ensures that it's is set to 'taxonomy_term' which seems to be the case for taxonomy term reference fields. With that adjustment, the module works great for me. If some others can confirm that the code in the sandbox project works for them, I'll promote the project to full project status and cut a release.
Comment #11
cpliakas CreditAttribution: cpliakas commentedmrfelton,
Thanks for taking up this module! I appreciate you volunteering to maintain it.
In regards to the
field type
key, looking at the API documentation it isn't a key that is supported by Facet API and is probably custom to the search module you are using (Search API, right?). Thefield api name
approach is the way that Facet API expects it to done, so I would recommend posting a bug report to the search module asking to utilizefield api name
. I don't mind posting the issue if you prefer.Thanks again,
Chris
Comment #12
mrfelton CreditAttribution: mrfelton commented@cpliakas - yes, I'm using this in conjunction with Search API and its Solr integration. If you wouldn't mind posting the bug report over at Search API I'd appreciate that, since I'm sure that you would be able to give the most clear and concise report given your deeper understanding of the codebase.
- Tom
Comment #13
cpliakas CreditAttribution: cpliakas commentedThanks Tom. Issue posted at #1377734: The "field api name" key isn't being populated for facets containing field data. Since your setup is producing the error, I would be curious to see why this value is being not set. It looks like there is a small 8 line code snippet where this bug is being introduced, so it shouldn't take too much time to debug unless the issue is happening elsewhere. The link the the search_api_facetapi_facetapi_facet_info() function in the issue will point you directly to the code.
Comment #14
cpliakas CreditAttribution: cpliakas commentedAlso posted an issue #1379036: Resolve incompatibility with the Apache Solr Search Integration module with a patch that introduces a workaround to support both Apache Solr Search Integration and Search API with or without #1377734: The "field api name" key isn't being populated for facets containing field data resolved.
Comment #16
Summit CreditAttribution: Summit commentedHi,
Is this contrib module https://www.drupal.org/node/1361284#comment-5384568 still necessary to sort facets?
greetings, Martijn
Comment #17
thePanz CreditAttribution: thePanz at Liip for FREITAG lab. AG commented@Summit: The module you need is now called FacetAPI Taxonomy Sort (https://www.drupal.org/project/facetapi_taxonomy_sort)