Skip to main content
Bumped by Community user
Bumped by Community user
removed tags from the title
Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284

Search api: Is there a way to default sort by date when no search keywords have been used, but default sort by relevance for all searches?

Source Link
aharown07
  • 414
  • 2
  • 11

Search api: Is there a way to default sort by date when no search keywords have been used, but default sort by relevance for all searches?

At present, my project has default search pages for sections of the site. They are per-content type. When the user goes the "search page" for the content type, they see a views-generated search result page unfiltered by any keywords. In other words, it displays all the items for that content type. The view:

has expose form in a block enabled settings on the exposed form has 'input required' disabled

What I want to happen...

I'd like users to

  • see the unfiltered search result page sorted by newest first. At present, this page, if set to relevance, shows old content first.
  • automatically switch to relevance sorting when they enter keywords and execute a search. At present, I've set the first sort to date, to solve the 'old content first' problem, so users have to manually change the sort to relevance when doing a search.

Some options... I could separate the list pages from the search result pages. My question is, is there a way to make an unfiltered "search result" views page show the newest content first, while having the default sort actually set to relevance, so nobody has to manually change it? How does that sort really work when there aren't any keywords to supply "relevance"?

My config basics...

  • Drupal 9.3.7
  • search_api
  • facets
  • search_api_solr