Skip to content

[5.x]: CraftCMS GraphQL Search with orderBy "score" and "limit" Causes Incorrect Results #18394

@arctouch-robsondejesus

Description

@arctouch-robsondejesus

What happened?

Hi CraftCMS team!
I'm running into a puzzling issue with GraphQL search queries, and I would love some guidance.

The issue is when I combine orderBy: "score DESC" with site: "" (multi-site search), limit, and offset, pagination returns inconsistent/incorrect results.
However, removing the limit or the "score DESC" parameters makes it work correctly.

Working Scenarios:
✅ orderBy: "score DESC" + site: "" + no limit → Returns all 55 results correctly
✅ site: "" + limit + offset + no orderBy → Returns correct 6 results per page|

Broken Scenario:
❌ orderBy: "score DESC" + site: "" + limit: 6 + offset: 0 → Returns only a total of 3 results (expected 6 per page)

Is this a known issue with multi-site search + score ordering + pagination?
Is there a workaround that allows me to keep relevance sorting (orderBy: "score DESC") while using pagination?
Should I file a bug report, or am I missing something in how this combination should work?
Any insights or suggestions would be greatly appreciated!

My Query:

query searchResults($searchTerm: String!, $offset: Int!, $limit: Int!) {
  results: entries(
    site: "*"
    section: ["or", "aboutUs", "careers", "careersPages", "work", "creativeContent", "contact", "consumerBrand", "corporatePublicAffairs", 
      "insights", "thoughtLeaders", "localPages", "newsroom", "pages", "privacyNotice", "regionHome", "responsibleDisclosurePolicy", "sectors", 
      "products", "advisory", "innovationIntelligence", "authors"]
    search: $searchTerm
    orderBy: "score DESC"
    limit: $limit
    offset: $offset
  ) {...}
}

Count Query that returns 55 results:

query searchCount($searchTerm: String!) {
  count: entryCount(
    site: "*"
    section: ["or", "aboutUs", "careers", "careersPages", "work", "creativeContent", "contact", "consumerBrand", "corporatePublicAffairs", 
      "insights", "thoughtLeaders", "localPages", "newsroom", "pages", "privacyNotice", "regionHome", "responsibleDisclosurePolicy", "sectors", 
      "products", "advisory", "innovationIntelligence", "authors"]
    search: $searchTerm
    orderBy: "score DESC"
  )
}

Multi-site setup with site: "*"
Search term: "sports" (wildcard search)
Expected: 6 results per page from total 55
Actual: 3 results on page 1

Craft CMS version

5.8.21

PHP version

8.2

Operating system and version

Linux Ubuntu 24.04 LTS

Database type and version

MySQL 8.0

Image driver and version

No response

Installed plugins and versions

"craftcms/aws-s3": "2.2.3",
"craftcms/ckeditor": "^4.11.0",
"craftcms/cms": "5.8.21",
"nystudio107/craft-seomatic": "5.1.19",
"putyourlightson/craft-amazon-ses": "3.1.0",
"spicyweb/craft-embedded-assets": "5.4.3",
"topshelfcraft/wordsmith": "5.0.0",
"vlucas/phpdotenv": "^5.6.1"

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions