Skip to content

[5.x]: Limit in search query doesn't work as expected #16183

@jakobhaerter

Description

@jakobhaerter

What happened?

Description

When working with site('*') and unique() in a search query, the output contains more or less entries compared to the limit I set – with more than enough entries to limit.

  • I get 10 entries without site('*') and unique().
  • I get 6 entries without site('*') and with unique().
  • I get 12 entries with site('*') and without unique().
{% set searchTerm = q ?? null %}
{% set searchQuery = craft.entries()
    .section([
        'home',
        'locations',
        'news',
        'pages',
        'persons',
    ])
    .orderBy('score, title ASC')
    .limit(10)
    .search(searchTerm)
    .site('*')
    .unique()
%}

Steps to reproduce

  1. Create a couple of entries
  2. Create a search query similar to the example above, using a reasonable limit value
  3. Output the length of the search results with and without site('*') and unique()

Expected behavior

The limit parameter should always limit the query to the exact limit value.

Actual behavior

The query output is not being limited based on the limit value.

Craft CMS version

5.5.2

PHP version

8.3

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions