1

I am using Drupal 8 search views, I would like to order the search result so that the content that's author has field "X" filled out should be ordered first and all other content where the author has field "X" empty shows up after. How can I achieve this with views

I made a relationship between the content and the author. I can access field "x" in the fields part of views, but it does not show up in the "filter" or "order by" parts.

2 Answers 2

1

You are almost have done it.

I made a relationship between the content and the author. I can access field "x" in the fields part of views, but it does not show up in the "filter" or "order by" parts.

add that fix "X" in sort section and sort it as Descending. when you make it descending contents with null values appear after those that have value.

2
  • I think this is unlikely to have the expected result. If field x is in the first sort criteria, it'll sort items by the value in that field, the side effect being that results with field x empty will appear last. If field x isn't the first sort criteria, it'll only be considered after all previous sorts are considered, and only having an impact when the previous sorts all result in a tie.
    – sonfd
    Commented Jun 24, 2020 at 15:55
  • Thank you for your answer. As I mentioned, the field didnt show up in the "order by/sort" section. I found the solution. I had to add the field to the index in the search index settings at /admin/config/search/search-api/index/course_search/fields
    – ventura
    Commented Jun 24, 2020 at 16:34
0

The field needs to be added to the search index here:

/admin/config/search/search-api/index/YOUR_SEARCH_INDEX_NAME/fields

Then the field shows up in the sort and filter sections in views.

Your Answer

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

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