[islandora_solr_views] Views sorting on multiple fields doesn't work

49 views
Skip to first unread message

Giancarlo Birello

unread,
Aug 9, 2017, 3:57:25 AM8/9/17
to islandora
When set a Views with more than one field in SORT CRITERIA the result is sorted only by first field.

From Solr log, in the query string:

... &sort=dc.date_dt+asc&sort=fgs_label_s+asc& ...

This format is not correct as stated here :

1) Multiple sort orderings can be separated by a comma, ie: sort=<field name>+<direction>[,<field name>+<direction>]...


So the right form must be:

... &sort=dc.date_dt+asc,fgs_label_s+asc& ...

I achieved that editing islandora_solr_views_query.inc :

      // Add sorting.
     
if (isset($this->orderby)) {
        module_load_include
('inc', 'islandora_solr', 'includes/utilities');
       
// Populate sorting parameters.
       
foreach ($this->orderby as $field => $order) {
-          $params['sort'][] = islandora_solr_lesser_escape($field) . ' ' . $order;
+          $sortFields[] = islandora_solr_lesser_escape($field) . ' ' . $order;
       
}
+       $params['sort'][] = implode(",",$sortFields);
     
}



     
     
       


Can someone check and confirm this? If confirmed I can open a PR.

Giancarlo




dp...@metro.org

unread,
Aug 9, 2017, 11:27:54 AM8/9/17
to islandora
Giancarlo,
I wonder if the issue is here? Can you debug the query?:. https://github.com/Islandora/islandora_solr_search/blob/c836f6a6f89d072125760664cf5ae8fbed0affaf/includes/query_processor.inc#L136-L163

Because adding each "sort" as an independent array element is the way it is documented and it is the way we are doing it with all the other ->solrParams, so if the query processor is not concatenating using "," correctly while executing the query, then we have an issue with the main query processor or who knows, with the underlying library.
 Can anyone else confirm this? do we have another scenario where multiple sorts are being set and properly understood?
 All the examples i have for multisort are using the Solr directly skipping this and i just realized my longest open pull (in history!) at https://github.com/Islandora/islandora_solr_views/pull/39/files#diff-3a0251062914f9f251182f299c54da22R154 using a single string... anyway, other mechanic i know..but i added a note there about single string also, but still passing multiple arrays.


Best

Diego

Jordan Dukart

unread,
Aug 10, 2017, 3:09:54 PM8/10/17
to islandora
Hey Giancarlo,

Just got a chance to look at this as Diego brought it up on committers. I agree with you that this is a bug within the sort code of Solr views. We should likely make a JIRA ticket such that this can be fixed with your code.

Jordan

Giancarlo Birello

unread,
Sep 6, 2017, 3:27:48 AM9/6/17
to isla...@googlegroups.com, Jordan Dukart

Sorry if the steps were not in the right order:

- I created Jira ticket https://jira.duraspace.org/browse/ISLANDORA-2054

- I forked into my github then made change then PR to islandora github.

I hope this can help for next release of Islandora.

Giancarlo

--
For more information about using this group, please read our Listserv Guidelines: http://islandora.ca/content/welcome-islandora-listserv
---
You received this message because you are subscribed to the Google Groups "islandora" group.
To unsubscribe from this group and stop receiving emails from it, send an email to islandora+...@googlegroups.com.
Visit this group at https://groups.google.com/group/islandora.
To view this discussion on the web visit https://groups.google.com/d/msgid/islandora/170f7e52-6bb2-48e9-82d3-cefa46819d8a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

dp...@metro.org

unread,
Sep 12, 2017, 10:54:56 PM9/12/17
to islandora
Hi Giancarlo, sorry for coming so late to this. This is great! thanks a lot. Will look at your pull request during the day tomorrow. That is a bug for sure, so even if code freeze (7.x-1.10 catches us, we can still review and merge afterwards)

Good night!

Diego Pino
Metro.org

Peter MacDonald

unread,
Sep 13, 2017, 8:52:44 AM9/13/17
to isla...@googlegroups.com
We have just now tested Giancarlo's patch for islandora_solr_views_query.inc to fix multi-level sorting of indexes in Solr Views. I tested it on our Islandora 7x-1.7 installation and it works as Giancarlo said.

We have tested it on two different Views and one of them has three levels of sorting and all three levels sorted properly whereas they never did before.

To see the three level sorting working on this site go to:


Grazie a lei, Giancarlo!

I hope this PR makes it into version 7.10.

Peter MacDonald

To unsubscribe from this group and stop receiving emails from it, send an email to islandora+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Peter MacDonald,
Library Information Systems Specialist
Hamilton College Library
Clinton, New York
315 859-4493
pmacdona-hamilton (Skype)

dp...@metro.org

unread,
Sep 13, 2017, 9:30:18 AM9/13/17
to islandora
Peter, it will, it will =)

D

Mark McFate

unread,
Sep 13, 2017, 11:48:23 AM9/13/17
to islandora
Just wanted to thank everyone for their work on this.  I looked at the issue a month ago (?) and was frankly puzzled why the sort WAS working for me, in most cases at least.  Got to looking at it today again and remembered that I override the sort order for some collections in an implementation of hook_query_alter.  I guess I can also confirm (sorry it took so long) that $params['sort'] as a CSV list works.  Thanks and take care.
Reply all
Reply to author
Forward
0 new messages