Starts-With Query



StartsWith

The results will contain only Product documents having a 'Name' field that starts with any case variation of 'ch'.

/** @var array<Product> $products */
$products = $session
    ->query(Product::class)
    // Call 'StartsWith' on the field
    // Pass the prefix to search by
    ->whereStartsWith("Name", "Ch")
    ->toList();
/** @var array<Product> $products */
$products = $session->advanced()
    ->documentQuery(Product::class)
    // Call 'WhereStartsWith'
    // Pass the document field and the prefix to search by
    ->whereStartsWith("Name", "Ch")
    ->toList();
from "Products"
where startsWith(Name, "Ch")

StartsWith (case-sensitive)

The results will contain only Product documents having a 'Name' field that starts with 'Ch'.

/** @var array<Product> $products */
$products = $session->advanced()
    ->query(Product::class)
    // Pass 'exact: true' to search for an EXACT prefix match
    ->whereStartsWith("Name", "Ch", true)
    ->toList();
/** @var array<Product> $products */
$products = $session->advanced()
    ->documentQuery(Product::class)
    // Call 'WhereStartsWith'
    // Pass 'exact: true' to search for an EXACT prefix match
    ->whereStartsWith("Name", "Ch", true)
    ->toList();
from "Products"
where exact(startsWith(Name, "Ch"))

Negate StartsWith

The results will contain only Product documents having a 'Name' field that does NOT start with 'ch' or any other case variations of it.

/** @var array<Product> $products */
$products = $session
    ->query(Product::class)
    # Negate next statement
    ->not()
    // Call 'StartsWith' on the field
    // Pass the prefix to search by
    ->whereStartsWith("Name", "Ch")
    ->toList();
/** @var array<Product> $products */
$products = $session->advanced()
    ->documentQuery(Product::class)
    // Call 'Not' to negate the next predicate
    ->not()
    // Call 'WhereStartsWith'
    // Pass the document field and the prefix to search by
    ->whereStartsWith("Name", "Ch")
    ->toList();
from "Products"
where (true and not startsWith(Name, "Ch"))