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).

Command icon 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

dulnan created an issue. See original summary.

ayalon made their first commit to this issue’s fork.

ayalon’s picture

Status: Active » Fixed

I have rebased and reviewed these nice features. Thanks for making the sorting more powerful.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

ayalon’s picture

Status: Fixed » Closed (fixed)