Compile SurrealDB full-text search, vector KNN, and geometry expressions in Surqlize with the SearchField, VectorField, and GeometryField helpers.
Surqlize provides field helpers that compile SurrealDB's full-text search, vector, and geometry expressions. Mark the relevant properties with the matching attribute, then use the field helper in a where() or projection.
SearchField compiles search predicates and helpers. matches() builds the @@ operator, score() returns the relevance score, and highlight() marks matched terms.
useSurqlize\Query\Fields\SearchField;
$body=newSearchField('body');
SearchableArticle::select(['title',$body->score()->as('score')]) ->where(fn()=>$body->matches('surreal orm')) ->orderBy('score','DESC') ->compile(); // SELECT title, search::score(1) AS score FROM searchable_article // WHERE body @@ 'surreal orm' ORDER BY score DESC
score() and highlight() take an optional match reference (default 1) that ties the helper to the matching predicate.
Vector search
VectorField compiles a K-nearest-neighbour query. nearest() builds the KNN predicate, and knnDistance() projects the computed distance.