Query giving priority to a certain content type

I’m querying for some contents using Content Lib in a paginated way, but in my case I need to show the contents of a certain type as the first ones. Is there any way to do this with Enonic?

For example:

  • If I get all contents of type x,y and z under ‘/content/site/*’, I want the x’s to appear as the first ones.

Best way currently is probably to do two searches. One for the special content, and then a regular one where you omit that content?

There is a feature request for scoring functions that might aid on this in the future?

1 Like

There is a sort of hacky way to do this using content queries, where you can boost the score of some contents.

If you add (type LIKE '*:mycontenttype' OR type LIKE '*') to your query expresseion, content with content type mycontenttype will have a higher score. so if you sort by score, they will appear first.

I don’t know exactly how this works, but this query will always be true, but “more” true for the for content with correct content type.

With this technique you can even boost certain content to the top, i.e. (_id IN ('random-id1', 'random-id2') OR type LIKE '*')


Thanks. I’ll try that.