Query by tags, order by relevance (= most matches)

Hey guys, i’m new to contentful, so bare with me if this is a stupid question :slight_smile: I try to get a list of topics (content type) by searching for tags. This works fine, however i only need the most relevant match. Currently this is not the first one thats returned. I didnt find anything in the docs about how i can make sure the document that has the most matches will be returned as first. Any ideas how that could be achieved? Thanks!

Hi there,

What exactly do you mean by relevance? We do not have a relevance property associated with items, but we do give you the ability to order retrieved content through a variety of ways, as described in the following sections of our documentation:



Looking at the title I assume that relevance means most matches from collection.
So if I have a field “tags” that is a list of strings, I can query for it using tags[in]=“a,b,c”.
The thing that I can’t do is to order results by number of matched tags in that query.
Entry with just a single tag (e.g. “a”) may be returned before entry with tags “a,c”.

So is there a way to sort by the number of matched elements in the “in” query?

That would unfortunately not be possible and we don’t have an implementation to order it in such a way at the moment.