1

I use a View to show search results (core Search module). In the view I have grouped the grid on the field "Content type". This works fine, each content type is shown under it's own title.

But under "Sort" in the View I can only sort the content types by ASC or DESC. But I would like to use a custom sort order like "node type = product", followed by "node type = accessories" and so on.

How to do that? I have tried using hook_views_query_alter() and hook_search_api_query_alter() and a few other tings, with no luck.

0

If you're looking to arbitrarily order nodes, that is the use case of Weight module. The module lets you add a field to any node type with a customizable weight range. Once added to your node types, you can configure any View to use this field to sort your nodes.

| improve this answer | |
  • Thanks for your answer. But no luck in this case. I installed the Weight module and gave my node types different weights. Then I added this wheight field to the search index and re-indexed it. I then added it as a Sort criteria in my view, with ascending order. But Views keep showing my search result in some other order. Strange... I keep looking, – TBJ Jun 6 '16 at 17:06
  • Ah, views sorting is driven by search ranking. Have you looked at hook_ranking() to add your own custom weight to the index? – Shawn Conn Jun 6 '16 at 17:17
  • No matter what I do, the sorting does not do what I want :-(. I have tried the hook_ranking() too, by adding a boost to my content types in the search settings. Thanks a lot anyway for taking time to answer. – TBJ Jun 6 '16 at 20:59

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.