Skip to content

feat: add proximity query support - #41

Merged
philippemnoel merged 11 commits into
mainfrom
feat/proximity
May 17, 2026
Merged

feat: add proximity query support#41
philippemnoel merged 11 commits into
mainfrom
feat/proximity

Conversation

@nandor23

Copy link
Copy Markdown
Collaborator

This PR adds support for proximity queries. All queries use EF.Functions.Match() as the entry point, with proximity expressions composed via Pdb.Proximity(), Pdb.ProximityRegex(), and Pdb.ProximityArray() factories chained through .Within() and .WithinOrdered().

Basic proximity

context.Products.Where(p =>
    EF.Functions.Match(p.Description, Pdb.Proximity("sleek").Within(1, "shoes")));
SELECT id, name, description
FROM products
WHERE description @@@ (('sleek' ## 1) ## 'shoes');

Ordered proximity

context.Products.Where(p =>
    EF.Functions.Match(p.Description, Pdb.Proximity("sleek").WithinOrdered(1, "shoes")));
SELECT id, name, description
FROM products
WHERE description @@@ (('sleek' ##> 1) ##> 'shoes');

Proximity with regex

context.Products.Where(p =>
    EF.Functions.Match(p.Description, Pdb.ProximityRegex("sl.*").Within(1, "shoes")));
SELECT id, name, description
FROM products
WHERE description @@@ ((pdb.prox_regex('sl.*') ## 1) ## 'shoes');

With maxExpansions set to 100:

context.Products.Where(p =>
    EF.Functions.Match(p.Description, Pdb.ProximityRegex("sl.*", 100).Within(1, "shoes")));
SELECT id, name, description
FROM products
WHERE description @@@ ((pdb.prox_regex('sl.*', 100) ## 1) ## 'shoes');

Proximity with array

context.Products.Where(p =>
    EF.Functions.Match(p.Description, Pdb.ProximityArray("sleek", "white").Within(1, "shoes")));
SELECT id, name, description
FROM products
WHERE description @@@ ((pdb.prox_array('sleek', 'white') ## 1) ## 'shoes');

Arrays can mix tokens with regex or nested arrays.

context.Products.Where(p =>
    EF.Functions.Match(
        p.Description,
        Pdb.ProximityArray(Pdb.ProximityRegex("sl.*"), Pdb.ProximityArray("white"))
            .Within(1, "shoes")));
SELECT id, name, description
FROM products
WHERE description @@@ ((pdb.prox_array(pdb.prox_regex('sl.*'), pdb.prox_array('white')) ## 1) ## 'shoes');

Chained proximity

Multiple proximity clauses compose left to right.

context.Products.Where(p =>
    EF.Functions.Match(
        p.Description,
        Pdb.Proximity("sleek")
            .Within(1, "running")
            .Within(2, Pdb.ProximityArray("sneakers", Pdb.ProximityRegex("sho.*")))));
SELECT id, name, description
FROM products
WHERE description @@@ ((('sleek' ## 1) ## 'running') ## 2) ## pdb.prox_array('sneakers', pdb.prox_regex('sho.*'));

@nandor23 nandor23 closed this May 16, 2026
@nandor23 nandor23 reopened this May 16, 2026

@philippemnoel philippemnoel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I didn't look enough at the project yet to review this, but since it's still a WIP we can merge this and then pick up from that slate once ready. We're wrapping up the Drizzle ORM first, and this will be next.

If you want to see, we add all snippets to the official docs like here: https://github.com/paradedb/paradedb/tree/add-drizzle-snippets. We'll need to do this with the EFCore ORM

@philippemnoel
philippemnoel merged commit 254e459 into main May 17, 2026
10 of 19 checks passed
@philippemnoel
philippemnoel deleted the feat/proximity branch May 17, 2026 03:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants