0

I've got a Apache Solr Views display where I'm using "Group By" to group the results by a particular taxonomy term. I'm then sorting the results so the taxonomy terms appear in ascending (alphabetical) order.

It works fine with one exception: If the row doesn't have anything assigned for the particular vocabulary I'm grouping by, those items appear first, they are sorted "Before A" in my alphabetical sort. So, if sorting the terms alphabetically, the 'no term' results are first in the View (because apparently NULL is alphabetically before 'A').

What I want is the terms sorted alphabetically with the 'no term' items LAST.

I mention it's a Solr View because I thought about using the weight of the terms instead of alphabetically (for more control), however relationships don't work in Solr views at all, so that's not an option because I can't get the term weight data.

I think I need to alter the View result programmatically to change the sort order of the 'no term' items and move them to the end of any results, but I can't figure out an effective place to hook in and do it.

Therefore my question is: To manually move some items from a 'group by' view to the end of the list, Which views hook should I use? In that hook, how do I pull out any 'no term' items and put them as the LAST visible results in the view?

  • You might want to do this as two views. Just filter by count > 1 for the top view and count < 1 for bottom view. – CG Monroe Nov 1 '18 at 19:18
  • I thought about doing this, but it won't really work because we're using sidebar facets to limit results etc. I don't think those (or other more advanced features) will work with multiple views (or even a view and attachment). – Feature Nov 1 '18 at 19:20
  • Makes sense.. I wonder if you could create a has content 1/0 field and then sort by this then by term name. I seem to remember in D7 there was a module that let you use some SQL expressions as fields.. can't remember the name off hand. E.g. a boolean expression for title <> NULL or similar. – CG Monroe Nov 1 '18 at 19:39
  • This might work for you: drupal.org/project/views_sort_expression – CG Monroe Nov 1 '18 at 19:41
  • I can't really add custom fields just to track this...there's tens of thousands of nodes that would have to be edited/updated :) It sure seems like there should be a way to hook in and change the sort order of the groups, somehow! – Feature Nov 1 '18 at 19:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.