I am trying to sort by a timestamp field from the solr collection, but nothing happens. After digging around, I found a solution to fix the issue. Patch to follow.

Comments

bdlangton’s picture

StatusFileSize
new774 bytes
bdlangton’s picture

Status: Active » Needs review
bdlangton’s picture

StatusFileSize
new1.03 KB

One more change was needed. Updated patch.

bdlangton’s picture

StatusFileSize
new1.09 KB

Sorry, #3 didn't have the full changes.

miroslavbanov’s picture

Status: Needs review » Postponed (maintainer needs more info)

It is working for me with these modules:

 Search Toolkit    Apache Solr framework (apachesolr)                Module  7.x-1.7            
 Search Toolkit    Apache Solr Views integration (apachesolr_views)  Module  7.x-1.0-beta3+8-dev
 Views             Views (views)                                     Module  7.x-3.8
erik frèrejean’s picture

I'm seeing the same issue with the following configuration:

apachesolr: 7.x-1.7
apachesolr_views: 7.x-1.x-dev
views: 7.x-3.10

The parameters on the view URI are: ?order=sm_vid_Informatiesoorten&sort=desc

Applying the patch from #4, resolves this issue for me.

miroslavbanov’s picture

@Erik Frèrejean
I tried to reproduce your case and all I get is "HTTP 400; can not sort on multivalued field" with or without the patch in #4 (as I see you are sorting on multivalued term reference: "sm_vid_Informatiesoorten"). I am still trying to understand in what situation this patch will help. Perhaps if you export the view from the administration and upload it here, I can use it as a test case.

erik frèrejean’s picture

@MiroslavBanov, I'll send you the view export through a pm. Rather not have those things floating around ;).

torgospizza’s picture

Sorting on a multivalue field doesn't work: "sm_vid_Informatiesoorten" - the "sm" means "string multiple" and allows for more than one value to be attached to that field.

Your best advice is to recreate that as "ss" - or string single field.

erik frèrejean’s picture

Well the funny thing is that the sorting somehow does work. It appears to be sorting on the first element in the multivalue (don't ask me exactly how/why that works as I haven't build this view initially)

miroslavbanov’s picture

What I can say is that if the patch #4 is applied, it will break multiple sort criteria.

I exchanged some info with Erik Frèrejean, and could not understand why patch #4 helps his situation situation. Anyway, the actual Solr query can be traced/dumped, and then if it is different with and without the patch, the difference can be back-traced to what is causing it.

For this issue, I need more details than "Sorting doesn't work". One problem that might be affecting some people (but probably not Erik Frèrejean) is that something could call SolrBaseQuery::parseSortString and this can reset the Solr filters. This can be overridden in apachesolr_views_solr_base_query, so that the parseSortString() method does not do anything (it doesn't support multiple sort criteria, so we don't want it anyway).

estebanvalerio.h’s picture

StatusFileSize
new504 bytes

None of the above patches worked for me but a mix of them did. Not sure if it is because I'm applying other patches to the module or if there is another reason.
I'm attaching the one that works for me

miroslavbanov’s picture

estebanvalerio.h,
Could tell which exactly version of Apachesolr Views you are using, and what patches?

j1mb0b’s picture

Since the above patch in comment #4 didn't work, I have re-uploaded the patch. I have tested this against multiple sort criteria and it seems to work accordingly.

Here is the output of the sorts:

As expected my results get filtered by sticky and then publish date etc...

I'm using version 7.x-1.1-beta1.

j1mb0b’s picture

After some debugging I have discovered the issue for me, using apachesolr_views in conjunction with weight module breaks all sorts defined in views.

I have created a separate issue for this: https://www.drupal.org/node/2628236

miroslavbanov’s picture

Status: Postponed (maintainer needs more info) » Needs review

@kingmackenzie

What is the $params['sort'] parameter of the Solr query, after the sortstring with multiple sorts is parsed? For me, I never could get multiple sort parameters to work, unless I directly set the sort parameter with query->replaceParam('sort', $this->orderby). And also I didn't want to deal with setting "available" sorts.

miroslavbanov’s picture

With #2628236-4: Apach Solr views sorting not working with setAvailableSort() applied, I think #14 will not change sort order at all. Can't be sure though - people here seem to be experiencing issue that I am not able to reproduce.

j1mb0b’s picture

@MiroslavBanov

Since the related issue I created is merge parsing shouldn't be an issue?

Agreed #14, at least for my case, is no longer required based on issue #2628236.

miroslavbanov’s picture

Status: Needs review » Fixed

I call this one fixed but feel free to reopen if it isn't. Thanks to everyone who contributed to the thread.

Status: Fixed » Closed (fixed)

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