0

I have a view that by default is ordered by date. It has several exposed filters one of which is for filtering by text (we use it as a search field). I'd like the view sort to change to Relevance when a user submits a search but I also want to set it so it only does this once in case the user changes the sort order and then modified their search string. Is this possible? I'm using Better Exposed Filters, fwiw.

The view content source is "content datasource" from the drupal search api.

1 Answer 1

0

If you order your view by relevance first, then date, when there is no text entered all articles will be given the same relevance score, so this will achieve what you are after.

5
  • Thank you for the response, but this doesn't seem to be happening in my view. In fact, without a text string, I'm not sure what its sorting by... certainly not date. I forgot to mention this isn't a normal content view but its using "Content datasource" from the drupal search api. I suspect that's why I'm seeing different results (no pun intended) then what you described. Jun 30, 2020 at 16:01
  • I have used this technique successfully with search api previously. You can temporarily add the relevance as a field to the output, that might help with the diagnosis. Jun 30, 2020 at 16:10
  • I poked around and figured out that when set to relevance with no text string its sorting by NID. Our authored dates have been manipulated, so they aren't the same order as the NID. Jun 30, 2020 at 17:00
  • @fallenturtle this isn't the usual behaviour, I can't say where the sort by nid is coming from. Jul 1, 2020 at 11:02
  • I'm revisiting this and have at least realized I was mistaken in thinking it was ordering by NID and in fact its ordering by created date ascending. Seems part of the issue is that there are no secondary sorts when all criteria are exposed. A partial solution seems to be to set relative as the first exposed sort criteria and then at the bottom of the sort criteria lists add the desired initial sort criteria unexposed, in my case date descending. Still I wish I could just have the text search field when submitted switch to sort by relevance unless another sort criteria has been chosen. Oct 7, 2020 at 0:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.