Closed joshuabaker closed 3 years ago
Can you give me a code example of what you mean?
Essentially, what I’m talking about is searching.
Below is an example scenario where we’re looking for people that have worked at a specific company and we want to order by matches with some skills.
{% set element = entry %}{# The homepage, perhaps (i.e. redundant for this query) #}
{% set context = craft.categories({
relatedTo: skillIds,
}) %}
{% set criteria = craft.entries({
section: 'people',
relatedTo: companyIds,
limit: 3,
}) %}
{% set results = craft.similar.find({
element: element,
context: context,
criteria: criteria,
}) %}
The above works, however, when we’re on a page where there’s no element object we have to add a query to get a random element.
So the element
is required because that's what it uses to create the Element Query. I suppose it could fall back to a default generic ElementQuery
or EntryQuery
or such, but I'm wondering if having to be explicit/consistent about it makes sense regardless?
Is the criteria
element type not sufficient for this though?
I think it's probably best to keep the API consistent in the end.
I have a scenario where providing a the
element
is redundant. I just want to get the best matches for the providedcontext
.The only requirement for this, at present, is to determine the element type and remove the element from the result set. The former can be achieved looking at the
criteria
and the latter isn’t always required.Leaving here for myself, in case I find time to put together a PR. Let me know your thoughts.