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.
Hi,
I would like to sort a search API views by flag count, e.g. most flagged items first. Is this possible? I cannot see how to do this and have no option in my views or a flag_count in the fields on search api, just a flag_follow_user.
Any suggestions?
Thanks,
Paul.
Comments
Comment #1
joachim CreditAttribution: joachim commentedI'm not familiar with how search API views work. There is at least one issue about this IIRC, with a patch that needs testing.
Comment #2
techypaul CreditAttribution: techypaul commentedI found a few issues that revolve around flag/search api functionality. I think this one is the one I need:
https://drupal.org/comment/6417498#comment-6417498
I will try this code out tomorrow and let you know what happens. I am wary of using this in production though and wondered if you had any thoughts on whether something like it might get committed in 7? The issue itself has been bumped to 8 now, but I think by the end of the issue it is more about the flag/unflag behaviour on search api results, than simply the count.
Thanks,
Paul.
Comment #3
joachim CreditAttribution: joachim commentedI thought it was this #1362298: Independent views query backend flag links but I might be wrong.
It says lower down in the issue you linked to that the code snippet at https://drupal.org/comment/6417498#comment-6417498 was committed to Flag in #1315850: Add support for Entity API properties.
Comment #4
techypaul CreditAttribution: techypaul commentedArgh! I can't work out what is going on here.
I have 3.2 so therefore this patch should be committed as suggested, yet in my search api fields list, I get only:
Users who flagged the entity with flag follow
When I select this, I get a facet that shows the actual users who have flagged those nodes, e.g. I can drill down by user to see what they have flagged. The original patch suggests, as I want it to do, that it provides the count as an indexible field:
However, in a later patch by yourself (wip), this is missing. I cannot find this in the code of 3.2 either. I have a feeling that this got left behind?
The independent views issue is all about flagging/unflagging in views whereas I just want to sort my results by total count and/or allow a facet for the same thing.
Thanks,
Paul.
Comment #5
joachim CreditAttribution: joachim commentedThe snippet you mention was only in one of the patches on #1315850: Add support for Entity API properties, at comment #15. It looks like things took a bit of a fork at that point, and it never made it into the patch I ended up making.
Looking at the code, there's no property for flag counts.
So if that's what you need, the best thing would be to file a new issue and work on a patch, taking that patch on #1315850: Add support for Entity API properties as a starting point.
Comment #6
techypaul CreditAttribution: techypaul commentedThanks joachim, I will try to :)
Paul.
Comment #7
digitgopher CreditAttribution: digitgopher commented[Deleted]