Skip to content

Commit 795fe57

Browse files
committed
feat: add inline boolean builder overload for JsonSearch
Adds JsonSearch(keyField, Action<ParadeDbBooleanQuery>) so boolean queries can be built directly in the call without a separate variable.
1 parent 6fe5c03 commit 795fe57

3 files changed

Lines changed: 30 additions & 0 deletions

File tree

Equibles.ParadeDB.EntityFrameworkCore.Tests/QueryTranslationTests.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,16 @@ public void JsonSearch_extension_generates_same_as_ef_functions() {
294294
Assert.Contains("@@@", sqlDirect);
295295
}
296296

297+
[Fact]
298+
public void JsonSearch_inline_boolean_generates_correct_sql() {
299+
var sql = Sql(_db.Chunks.JsonSearch(c => c.Id, b => b
300+
.Must(
301+
ParadeDbJsonQuery.Parse("revenue growth"),
302+
ParadeDbJsonQuery.Term("DocumentType", 10))));
303+
Assert.Contains("@@@", sql);
304+
Assert.Contains("::pdb.query", sql);
305+
}
306+
297307
// ── Combining with LINQ ───────────────────────────────────────────
298308

299309
[Fact]

Equibles.ParadeDB.EntityFrameworkCore/ParadeDbSearchExtensions.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ public static class ParadeDbSearchExtensions {
1414
private static readonly MethodInfo ScoreMethod = typeof(ParadeDbFunctions)
1515
.GetMethod(nameof(ParadeDbFunctions.Score), [typeof(DbFunctions), typeof(object)])!;
1616

17+
/// <summary>
18+
/// Adds a WHERE clause with a ParadeDB boolean JSON query built inline.
19+
/// Translates to: <c>keyField @@@ 'json'::pdb.query</c>.
20+
/// </summary>
21+
public static IQueryable<T> JsonSearch<T>(this IQueryable<T> source,
22+
Expression<Func<T, object>> keyField, Action<ParadeDbBooleanQuery> configure) where T : class {
23+
return source.JsonSearch(keyField, ParadeDbJsonQuery.Boolean(configure));
24+
}
25+
1726
/// <summary>
1827
/// Adds a WHERE clause with a ParadeDB JSON query.
1928
/// Translates to: <c>keyField @@@ 'json'::pdb.query</c>.

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,17 @@ var results = await dbContext.Chunks
366366
.OrderByScoreDescending(c => c.Id)
367367
.Take(5)
368368
.ToListAsync();
369+
370+
// Option 3: Inline boolean builder
371+
var results = await dbContext.Chunks
372+
.JsonSearch(c => c.Id, b => b
373+
.Must(
374+
ParadeDbJsonQuery.Parse("revenue growth"),
375+
ParadeDbJsonQuery.Term("DocumentId", documentId),
376+
ParadeDbJsonQuery.Term("DocumentType", 10)))
377+
.OrderByScoreDescending(c => c.Id)
378+
.Take(5)
379+
.ToListAsync();
369380
```
370381

371382
```sql

0 commit comments

Comments
 (0)