We've implemented a sorter for a project that sorts term-based facet-results by their term-weight. Thought it might be of general use.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

danquah created an issue. See original summary.

danquah’s picture

Status: Active » Needs review
FileSize
3.11 KB
borisson_’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

This is looking great! I actually had a question about this functionality very recently. Thanks!

I don't think I'll commit this without any tests though.

+++ b/src/Plugin/facets/processor/TermWeightWidgetOrderProcessor.php
@@ -0,0 +1,90 @@
+class TermWeightWidgetOrderProcessor extends SortProcessorPluginBase implements SortProcessorInterface, ContainerFactoryPluginInterface {

I think implements SortProcessorInterface is superfluous as the SortProcessorPluginBase already implements the same interface.

danquah’s picture

Status: Needs work » Needs review
FileSize
8.23 KB

Makes sense :) I've removed the "implements SortProcessorInterface" and test-cases for a couple of term-weights. Is the test thorough enought?

Status: Needs review » Needs work

The last submitted patch, 4: sort_facets_by_weight-2833340-4.patch, failed testing.

  • borisson_ committed e1a1ad0 on 8.x-1.x authored by danquah
    Issue #2833340 by danquah: Sort term-based facets by term weight
    
borisson_’s picture

Status: Needs work » Fixed
Issue tags: -Needs tests

Test looks fine, committed! Thanks and sorry for letting this sit for so long.

nicola85’s picture

Status: Fixed » Active
borisson_’s picture

@nicola85: Looks like I made a mistake while committing that patch, I'll try to see if the patch in #4 still applies.

  • borisson_ committed 4b8eff1 on 8.x-1.x authored by danquah
    Issue #2833340 by danquah: Sort term-based facets by term weight
    
borisson_’s picture

Status: Active » Fixed

Committed this again.

Status: Fixed » Closed (fixed)

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

bmcclure’s picture

This functionality isn't working for me. Is it incompatible with using the hierarchy?

I'd like to display facets hierarchically, following the same sorting as the terms themselves, but the term weight sorting option doesn't seem to have any effect in my case.

borisson_’s picture

@bmcclure: #2864336: Facet sorting for hierarchical vocabularies, so yeah, that currently doesn't work yet.

surbz’s picture

Adding the sort order key in the yml file.

borisson_’s picture

@surbz could you open a new issue for that? That way we can track and give proper attribution. Thanks!

surbz’s picture

https://www.drupal.org/files/issues/sort_facets_by_weight-2833340-15.patch had a trailing white space , uploading the fixed one.

@borisson_ okay i will do that.
Thanks

surbz’s picture

This patch the sort order key in the yml file for 8.x-1.0-alpha6

surbz’s picture

FileSize
685 bytes

https://www.drupal.org/files/issues/sort_facets_by_weight-2833340-18.patch had a trailing white space , uploading the fixed one.