Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Order by number of relations in common #35

Closed
johnj24 opened this issue May 26, 2021 · 2 comments
Closed

Order by number of relations in common #35

johnj24 opened this issue May 26, 2021 · 2 comments
Labels
question Further information is requested

Comments

@johnj24
Copy link

johnj24 commented May 26, 2021

Question

Is it expected behavior to have elements with the most relations in common be returned first? I've basically copied the tags and categories example from the documentation and I'm getting a seemingly random order.

Additional context

Here's a code example and what it returns:

{# Similar Recipes #}
{% set ids = entry.relatedStory.ids() | merge(entry.tags.ids()) %}
{% set limitCriteria = craft.entries.limit(8) %}
{% set similarRecipes = craft.similar.find({ element: entry, context: ids, criteria: limitCriteria }) %}

{% for similar in similarRecipes %}
  <div>{{ similar.title }} ({{ similar.count }} ids in common)</div>
{% endfor %}

{# Returns #}
Recipe Title 1 - (2 ids in common)
Recipe Title 2 - (2 ids in common)
Recipe Title 3 - (2 ids in common)
Recipe Title 4 - (2 ids in common)
Recipe Title 5 - (4 ids in common)
Recipe Title 6 - (4 ids in common)
Recipe Title 7 - (4 ids in common)
Recipe Title 8 - (2 ids in common)

Thanks!

@johnj24 johnj24 added the question Further information is requested label May 26, 2021
@khalwat
Copy link
Contributor

khalwat commented May 26, 2021

It should be explicitly ordering them by the number found, as per:

https://github.com/nystudio107/craft-similar/blob/v1/src/services/Similar.php#L192

...not sure if there was a regression or not though.

@khalwat
Copy link
Contributor

khalwat commented Jun 3, 2021

Addressed in 8d694f8

@khalwat khalwat closed this as completed Jun 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants