Problem/Motivation
Typesense supports filter-based scoring in `sort_by` via `_eval()`, optionally combined with `_text_match(buckets: N)` to coarsen the relevance score so the eval score can reorder within a relevance tier. This is the standard way to prefer or demote certain kinds of documents without hard-filtering them.
The GraphQL layer currently can't express this. `sortBy` accepts only the `TypesenseSortBy` enum, and `mapSortByEnumToFieldName()` resolves those to schema fields flagged `sort: true` — so an `_eval` expression can't be built. The only workaround is `hook_typesense_graphql_query_alter()` plus `setSortBy()`, which hides the ranking intent from the query document and is awkward to scope when several queries share one collection.
Proposed resolution
Add a `boostBy` input to `searchTypesense`, e.g.
boostBy: [{ field: CONTENT_SEARCH_ITEM_TYPE, values: ["service", "page"], weight: 4 }]
plus an argument to control `_text_match` bucketing. When present, the built `sort_by` becomes `_text_match(buckets: N):desc,_eval([...]):desc`.
Should compose with an explicit `sortBy` and must not affect the disjunctive facet sub-queries (which don't receive `sort_by` today).
Issue fork typesense_graphql-3616025
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #4
ayalon commentedI have rebased and reviewed these nice features. Thanks for making the sorting more powerful.
Comment #6
ayalon commented