Add whereNotNull to count query sort-field EXISTS

The list CTE's INNER JOIN on search already excludes entities whose
sort-field value is NULL (truncated long values stored as NULL by
buildEntitySearch). Add the same whereNotNull to the count query's
EXISTS so totalItems matches the reachable set. Matters for fields
like metadata.description where ~128K entities have NULL values.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2026-05-20 16:59:39 +02:00
parent 02a6410992
commit 2c4b4912c2
@@ -505,7 +505,8 @@ export class DefaultEntitiesCatalog implements EntitiesCatalog {
this.database('search')
.select(this.database.raw(1))
.whereRaw('search.entity_id = final_entities.entity_id')
.where('search.key', sortField.field),
.where('search.key', sortField.field)
.whereNotNull('search.value'),
);
}