1

I have nodes that can have many tags. I'm able to display nodes that share some of the tags.

        $query = \Drupal::entityQuery('node');

        if ($nodeId != null) {
            $query->condition('nid', $nodeId, '<>');
        }
        $query->condition('field_tags', $tagsIds, 'IN');
        $query->condition('status', 1);

That works. But now I'd like to sort them by relevance. In other words, the ones that have the most tags in common should come first.

Any idea how I can achieve that? Thanks!

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.