Zymergi.Search.Sqlite
11.4.0-alpha
dotnet add package Zymergi.Search.Sqlite --version 11.4.0-alpha
NuGet\Install-Package Zymergi.Search.Sqlite -Version 11.4.0-alpha
<PackageReference Include="Zymergi.Search.Sqlite" Version="11.4.0-alpha" />
<PackageVersion Include="Zymergi.Search.Sqlite" Version="11.4.0-alpha" />
<PackageReference Include="Zymergi.Search.Sqlite" />
paket add Zymergi.Search.Sqlite --version 11.4.0-alpha
#r "nuget: Zymergi.Search.Sqlite, 11.4.0-alpha"
#:package Zymergi.Search.Sqlite@11.4.0-alpha
#addin nuget:?package=Zymergi.Search.Sqlite&version=11.4.0-alpha&prerelease
#tool nuget:?package=Zymergi.Search.Sqlite&version=11.4.0-alpha&prerelease
Zymergi.Search.Sqlite
Embedded SQLite adapter for the engine-neutral search contracts in Zymergi.Core (ISearchProvider<T>, ISearchIndexer<T>, IIndexManager). No search server: one database file is the whole engine. Good for small sites, local development, and tests.
Targets .NET 10. Depends on Zymergi.Core, Zymergi.Data, Microsoft.Data.Sqlite, and SQLitePCLRaw.bundle_e_sqlite3. Supports every SearchCapabilities feature: recency, range, stats, and date-histogram facets, highlighting, and exact totals.
Install
dotnet add package Zymergi.Search.Sqlite
Register in Program.cs
{ "SqliteSearch": { "ConnectionString": "Data Source=App_Data/search.db" } }
using Zymergi.Search;
using Zymergi.Search.Sqlite;
builder.Services
.AddSqliteSearch(builder.Configuration) // reads SqliteSearch:ConnectionString
.AddSqliteSearchIndex<ProductDoc>("products", d => d.Id); // singleton provider + indexer
var app = builder.Build();
// Create the index once, at startup or in a deploy step.
var indexes = app.Services.GetRequiredService<IIndexManager>();
if (!await indexes.ExistsAsync("products"))
{
await indexes.CreateAsync("products", ProductDoc.Definition);
}
The document is a plain record you own. Field names in the IndexDefinition must match the JSON property names (System.Text.Json, so Title stays Title):
public sealed record ProductDoc(string Id, string Title, string Brand, double Price, DateTimeOffset Released)
{
public static readonly IndexDefinition Definition = new(
[
new FieldDefinition("Id", FieldType.Keyword, Filterable: true),
new FieldDefinition("Title", FieldType.Text, Searchable: true),
new FieldDefinition("Brand", FieldType.Keyword, Filterable: true, Facetable: true),
new FieldDefinition("Price", FieldType.Number, Filterable: true, Sortable: true),
new FieldDefinition("Released", FieldType.Date, Filterable: true, Sortable: true),
]);
}
Use it
app.MapGet("/search", async (string? q, string? brand, int page, ISearchProvider<ProductDoc> search, CancellationToken ct) =>
{
var result = await search.SearchAsync(new SearchRequest
{
Query = q,
Filter = brand is null ? null : new TermFilter("Brand", brand),
Facets = [new TermsFacetRequest("Brand")],
Sort = q is null ? [new SortClause("Released", SortDirection.Descending)] : [],
Offset = Math.Max(page, 0) * 20,
Limit = 20,
}, ct);
return Results.Ok(new { result.TotalCount, Hits = result.Hits.Select(h => h.Document), result.Facets });
});
Indexing from a service:
public sealed class ProductIndexer(ISearchIndexer<ProductDoc> indexer)
{
public Task UpsertAsync(IEnumerable<ProductDoc> docs, CancellationToken ct) => indexer.IndexAsync(docs, ct);
public Task RemoveAsync(IEnumerable<string> ids, CancellationToken ct) => indexer.DeleteAsync(ids, ct);
}
Best practices
- Depend on
ISearchProvider<T>andISearchIndexer<T>, never on the adapter types. You can swap inZymergi.Search.ElasticorZymergi.Search.Meiliby changing only the registration. - Pass the request's
CancellationToken. - Index in batches (
IndexAsynctakes many documents and writes them in one transaction). Index from a background job or a queue, not inside the user's request when you can avoid it. - Each call opens its own
SqliteConnection(pooled by Microsoft.Data.Sqlite). SQLite allows one writer at a time: keep write batches moderate, and run one indexer process per file. - Keep the database file on local disk, not a network share.
- Rate-limit public search endpoints (
AddRateLimiter) and cache popular queries with output caching orHybridCache. - Check
search.Capabilitiesbefore you offer a feature that another engine may not support.
Testing
- Use a temp file per test fixture:
Data Source={Path.GetTempPath()}/search-{Guid.NewGuid():n}.db. CallSqliteConnection.ClearAllPools()before you delete the file. - Do not use plain
Data Source=:memory:. Each operation opens a new connection, and each new in-memory connection is a new, empty database. A named shared-cache memory database (Data Source=name;Mode=Memory;Cache=Shared) works only while some other connection to it stays open. - You can build
SqliteIndexManager,SqliteSearchIndexer<T>, andSqliteSearchProvider<T>directly from a connection string in tests.
Gotchas
- Index and field names must be letters, digits, or underscores, and must not start with a digit. They become table and column names.
- A full-text companion table (FTS5) is created only when the definition has a
Searchablefield. Recencyis honored here but ignored by Meili. An explicitSortalways wins over recency.
Version notes
11.4.0-alpha: no API change in this package. The README sample no longer uses Zymergi.Articles, which is not packed, and no longer suggests :memory:.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Microsoft.Data.Sqlite (>= 10.0.12)
- Microsoft.Extensions.Configuration (>= 10.0.12)
- Microsoft.Extensions.DependencyInjection (>= 10.0.12)
- SQLitePCLRaw.bundle_e_sqlite3 (>= 3.0.5)
- Zymergi.Core (>= 11.4.0-alpha)
- Zymergi.Data (>= 11.4.0-alpha)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 11.4.0-alpha | 52 | 11/16/2026 |
| 11.3.0-alpha | 64 | 11/12/2026 |
| 11.2.0-alpha | 61 | 11/2/2026 |
| 11.1.1-alpha | 72 | 10/4/2026 |
| 11.1.0-alpha | 103 | 10/1/2026 |
| 11.0.6-alpha | 88 | 7/10/2026 |
| 11.0.5-alpha | 79 | 7/9/2026 |
| 11.0.4-alpha | 78 | 7/6/2026 |
| 11.0.3-alpha | 82 | 7/6/2026 |