nystudio107 / craft-similar

Similar for Craft lets you find elements, Entries, Categories, Commerce Products, etc, that are similar, based on... other related elements.
https://nystudio107.com/
MIT License
26 stars 5 forks source link

context being ignored? #31

Closed i-just closed 3 years ago

i-just commented 3 years ago

I'm grabbing some related entries like this:

{% set tagsFieldHandle = 'centreArticlesTags' %}
{% set related = craft.similar.find({ element: entry, context: entry[tagsFieldHandle], criteria: craft.entries.limit(3) }) %}

Up until version 1.0.6, Similar was only returning entries that actually used 'centreArticlesTags' field. Since version 1.1.0, the plugin is returning entries from various other sections that don't use that tags field at all.

I can limit it to just the section(s) I want via criteria, but it seems to me that this change in behaviour might not be intentional? I mean I'm not sure what it now actually uses to figure out if another entry is related since it's looking through entries that don't have the tags group I specified in context? Was this change in behaviour intentional?

khalwat commented 3 years ago

Very well could be an unintentional side-effect. Will have a look

khalwat commented 3 years ago

Potentially related to: https://github.com/nystudio107/craft-similar/issues/29#issuecomment-796844250

aurexs commented 3 years ago

I'm having the same problem.

When the entry has tags that do not have another related entry, it returns entries from other sections. Even if it is limited by section via criteria, it returns multiple inputs (from the same section) with count = NULL.

In context I must pass the IDs of the tags because if I useentry.tags it returns entries that do not have related tags either (with count = NULL).

I'm using version 1.1.1

{% set tagIds = [] %}
{% for tag in entry.servicioTags %}
  {% set tagIds = tagIds|merge([tag.id]) %}
{% endfor %}

{% set serviciosCriteria = craft.entries
                  .section('servicios')
                  .with([
                    'imagen',
                    'categoriaPerfil',
                    'servicioTags'
                  ]).limit(4) %}

{% set serviciosRel = craft.similar.find({ element: entry, context: tagIds, criteria: serviciosCriteria }) %}
khalwat commented 3 years ago

Addressed in: https://github.com/nystudio107/craft-similar/commit/47aa0bdee22c4effe572189b554af642c7ff67b5

You can try it now by setting your semver in your composer.json to look like this:

    "nystudio107/craft-similar": "dev-develop as 1.1.2”,

Then do a composer update

khalwat commented 3 years ago

@i-just @aurexs you able to try this?

i-just commented 3 years ago

@khalwat it seems to be back to how it used to work; context is limiting finding related/similar entries to the ones that have the context field in them; thanks for fixing!