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.


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.

| improve this answer | |
  • 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. – fallenturtle Jun 30 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. – Alfred Armstrong Jun 30 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. – fallenturtle Jun 30 at 17:00
  • @fallenturtle this isn't the usual behaviour, I can't say where the sort by nid is coming from. – Alfred Armstrong Jul 1 at 11:02

Your Answer

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

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