Bielu.BetterSearch.Core 1.0.0-beta.20261122193512

Prefix Reserved
This is a prerelease version of Bielu.BetterSearch.Core.
dotnet add package Bielu.BetterSearch.Core --version 1.0.0-beta.20261122193512
                    
NuGet\Install-Package Bielu.BetterSearch.Core -Version 1.0.0-beta.20261122193512
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Bielu.BetterSearch.Core" Version="1.0.0-beta.20261122193512" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Bielu.BetterSearch.Core" Version="1.0.0-beta.20261122193512" />
                    
Directory.Packages.props
<PackageReference Include="Bielu.BetterSearch.Core" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Bielu.BetterSearch.Core --version 1.0.0-beta.20261122193512
                    
#r "nuget: Bielu.BetterSearch.Core, 1.0.0-beta.20261122193512"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Bielu.BetterSearch.Core@1.0.0-beta.20261122193512
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Bielu.BetterSearch.Core&version=1.0.0-beta.20261122193512&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Bielu.BetterSearch.Core&version=1.0.0-beta.20261122193512&prerelease
                    
Install as a Cake Tool

Bielu.BetterSearch

CI NuGet NuGet Downloads License: MIT

<p align="center"> <img src="https://raw.githubusercontent.com/bielu/bielu.bettersearch/main/assets/icon.png" alt="Bielu.BetterSearch logo" width="128"> </p>

A provider-agnostic search abstraction for .NET: describe a query once, then run it against whichever search engine you configure. Elasticsearch, OpenSearch, Meilisearch, Typesense, PostgreSQL full-text search and an in-memory provider ship today, and a new engine is a new provider package, with no change to the core.

📖 Full documentation: https://search.bielu.pl/

Status: beta, not production ready. The public API will change before 1.0. The roadmap is the plan for a stable release, and the feature matrix records what each provider really supports.

Quick start

1. Install

dotnet add package Bielu.BetterSearch.Core --prerelease

# Then one provider:
dotnet add package Bielu.BetterSearch.ElasticSearch --prerelease   # Elasticsearch
dotnet add package Bielu.BetterSearch.OpenSearch --prerelease      # OpenSearch
dotnet add package Bielu.BetterSearch.Meilisearch --prerelease     # Meilisearch
dotnet add package Bielu.BetterSearch.Typesense --prerelease       # Typesense
dotnet add package Bielu.BetterSearch.PostgreSql --prerelease      # PostgreSQL full-text search
dotnet add package Bielu.BetterSearch.Lifti --prerelease           # in-memory

2. Register a provider

Elasticsearch, configured from Bielu:BetterSearch:ElasticSearch:

using Bielu.BetterSearch.DependencyInjection;
using Bielu.BetterSearch.ElasticSearch.DependencyInjection;

builder.Services.AddBetterSearch(builder.Configuration, search => search.AddElasticSearch());

OpenSearch, configured from Bielu:BetterSearch:OpenSearch:

using Bielu.BetterSearch.DependencyInjection;
using Bielu.BetterSearch.OpenSearch.DependencyInjection;

builder.Services.AddBetterSearch(builder.Configuration, search => search.AddOpenSearch());
{
  "Bielu": {
    "BetterSearch": {
      "OpenSearch": {
        "SharedIndexSettings": {
          "ConnectionString": "http://localhost:9200",
          "AuthenticationType": "Password",
          "AuthenticationDetails": { "Username": "admin", "Password": "..." }
        }
      }
    }
  }
}

AuthenticationType is None, Password (basic, Username and Password) or ApiKey (an OpenSearch 3.x API key in ApiKey). An entry under Indexes overrides the connection string or the authentication for that one index and takes the rest from the shared settings (set "AuthenticationType": "None" there to turn the shared authentication off for that index), and MaxResultWindow (10,000 by default) should match the indexes' index.max_result_window. AdditionalNodes lists the cluster's other nodes, on OpenSearch and Elasticsearch, and PoolType (Static, Sticky or Sniffing) chooses how requests are spread over them; a request that can't reach a node goes to the next one. See the OpenSearch and Elasticsearch pages.

In every provider, keys under Indexes match index names whatever their case, so Indexes:People applies to the index people.

Elasticsearch and OpenSearch also take explicit field mappings under SharedIndexSettings:Mappings or an Indexes entry's Mappings, applied when the index is created: a Keyword field matches and sorts on its whole value under its plain name, a Text field sorts on its keyword sub-field automatically, and a GeoPoint field makes geo distance queries work. Fields not listed keep dynamic mapping, and invalid mappings fail at startup. See field mappings.

On Elasticsearch and OpenSearch a successful write becomes searchable at the next index refresh, about a second later. Set "WriteVisibility": "WaitUntilSearchable" under SharedIndexSettings or an Indexes entry to have index and remove calls return only once a search can see the write; Meilisearch, Typesense, PostgreSQL and Lifti already wait. See when writes are searchable.

Meilisearch, configured from Bielu:BetterSearch:Meilisearch:

using Bielu.BetterSearch.DependencyInjection;
using Bielu.BetterSearch.Meilisearch.DependencyInjection;

builder.Services.AddBetterSearch(builder.Configuration, search => search.AddMeilisearch());
{
  "Bielu": {
    "BetterSearch": {
      "Meilisearch": {
        "SharedIndexSettings": {
          "ConnectionString": "http://localhost:7700",
          "ApiKey": "..."
        }
      }
    }
  }
}

ApiKey is the master key or an API key; leave it empty when the server has none. An entry under Indexes without a ConnectionString uses the shared server and key. Meilisearch filters rather than ranks, so fuzzy queries return a failed Result, and raw Lucene queries are translated into filters where they can be: a term needs a field, and a Lucene fuzzy term matches the exact word with a TranslationWarning. Spatial queries work on one field, named by "GeoField" under Meilisearch, holding a "lat,lon" string or a dictionary with lat and lon. Phrase prefix queries store word runs for every text field; list the fields that need them in "PhraseFields" to keep long texts small, and re-index after adding a field to it (see the feature matrix).

Typesense, configured from Bielu:BetterSearch:Typesense:

using Bielu.BetterSearch.DependencyInjection;
using Bielu.BetterSearch.Typesense.DependencyInjection;

builder.Services.AddBetterSearch(builder.Configuration, search => search.AddTypesense());
{
  "Bielu": {
    "BetterSearch": {
      "Typesense": {
        "SharedIndexSettings": {
          "ConnectionString": "http://localhost:8108",
          "ApiKey": "..."
        }
      }
    }
  }
}

AdditionalNodes lists a cluster's other nodes, tried in order when one can't be reached. Typesense also runs queries as filters, so hits aren't ranked; fuzzy, raw Lucene and string range queries, facets and highlighting return a failed Result, and so does a MustNot range, prefix or spatial query, as Typesense filters can only negate an equality. See the Typesense page.

PostgreSQL full-text search, configured from Bielu:BetterSearch:PostgreSql:

using Bielu.BetterSearch.DependencyInjection;
using Bielu.BetterSearch.PostgreSql.DependencyInjection;

builder.Services.AddBetterSearch(builder.Configuration, search => search.AddPostgreSql());
{
  "Bielu": {
    "BetterSearch": {
      "PostgreSql": {
        "SharedIndexSettings": {
          "ConnectionString": "Host=localhost;Database=app;Username=app;Password=..."
        }
      }
    }
  }
}

Leave the connection string empty to use the NpgsqlDataSource registered in the container. Each index is a table with the fields as jsonb and a generated tsvector under a GIN index. Queries run as SQL conditions, so hits aren't ranked; raw Lucene queries, facets and highlighting return a failed Result, and fuzzy queries need the fuzzystrmatch extension. See the PostgreSQL page.

Or in memory:

using Bielu.BetterSearch.DependencyInjection;

builder.Services.AddBetterSearch(search => search.AddLiftiSearch());
await indexing.IndexDocumentAsync(new SearchDocument
{
    Id = "1",
    Index = "people",
    Fields = new Dictionary<string, IList<object>> { ["Name"] = ["Jane Doe"] },
});

var query = new SearchQuery { Index = "people", Page = 1, PageSize = 20 };
query.Add(Occurrence.Must, new PrefixSubQuery { Field = "Name", Value = "ja" });

var result = await search.SearchAsync(query, cancellationToken);
if (result.IsSuccess)
{
    foreach (var hit in result.Value.Items) { /* hit.Document.Id, hit.Score, ... */ }
}

To search one culture, index it in the plain Culture field and filter on it with the fluent API:

Fields[CultureField.Name] = [CultureField.Value("en-US")];

var query = FluentApiSearchQueryCreator.Create()
    .WithSearchQuery(search => search.WithIndex("pages"))
    .CreateSearchQuery(search => search
        .CreateTermQuery(term => term.WithField("Title").WithValue("welcome"))
        .FilterByCulture("en-US"));

The Getting Started guide covers this in more detail.

Features

  • ✅ One query model for every provider: term, terms, prefix, prefix phrase, fuzzy, date, numeric and string ranges, geo distance, raw Lucene, and nested boolean logic with Lucene semantics
  • ✅ Fluent query builder in Bielu.BetterSearch.FluentApi
  • ✅ Paging, sorting, post filters, highlighting and scores on the Elasticsearch and OpenSearch providers; paging, sorting and post filters on Meilisearch, Typesense and PostgreSQL
  • ✅ Field mappings on Elasticsearch and OpenSearch: Text, Keyword, Date, numeric, Boolean and GeoPoint fields, with an optional analyzer or format, validated at startup
  • ✅ Zero-downtime rebuilds on Elasticsearch and OpenSearch through IIndexLifecycleServiceAsync: fill a new index while searches read the old one, then swap an alias and delete the old index in one atomic step; on Typesense through a collection alias, in separate steps, one rebuild of an index at a time, with a short gap on an index's first rebuild
  • ✅ Index name prefix (IndexPrefix) on Elasticsearch, OpenSearch, Meilisearch and Typesense, so applications or environments can share one cluster
  • ✅ Errors as results: searching and indexing return FluentResults Results. Lifti, Typesense and PostgreSQL fail a query that asks for facets, and Meilisearch one that asks for any facet other than a top-level term facet; Meilisearch, Typesense, PostgreSQL and Lifti also fail a query that asks for highlighting. Lifti ignores paging, sorting and post filters, so check the feature matrix for what your provider applies
  • ✅ Opt-in search result cache: the built-in memory cache for one instance, FusionCache with a backplane for several, or your own ISearchResultCache, as decorators over the search and indexing services; every write through the indexing service evicts the index's cached searches. See caching
  • ✅ Observability: OpenTelemetry spans and metrics and LoggerMessage logs from the Core services, so every provider has them, wired with AddBetterSearchInstrumentation(), and a health check that pings the engine (AddBetterSearchHealthCheck()); see the feature matrix
  • ✅ Shared provider tests: provider-agnostic behavior tests in BaseTests run against every provider
  • ✅ .NET Aspire AppHost that starts Elasticsearch, OpenSearch, Meilisearch and Typesense for local development and the integration tests, with meilisearch-ui for browsing Meilisearch indexes and trying queries

Elasticsearch and OpenSearch run term, multi-term and filter facets, nested inside each other; Meilisearch runs top-level term facets, and Lifti none. Only Elasticsearch and OpenSearch highlight. See the feature matrix for the full picture.

Packages

Package Description
Bielu.BetterSearch.Abstractions Query model (SearchQuery and its sub-queries), SearchDocument and the request models, and service interfaces
Bielu.BetterSearch.Core AddBetterSearch and the indexing and search services
Bielu.BetterSearch.FluentApi Fluent query builder
Bielu.BetterSearch.Caching.FusionCache Search result cache over FusionCache
Bielu.BetterSearch.OpenTelemetry AddBetterSearchInstrumentation() for OpenTelemetry tracing and metrics
Bielu.BetterSearch.HealthChecks AddBetterSearchHealthCheck(), which pings the configured engine
Bielu.BetterSearch.OpenSearch.Aws AddOpenSearchAwsSigV4(), which signs OpenSearch requests with AWS SigV4 for Amazon OpenSearch Service and Serverless

Providers

Package Engine Status
Bielu.BetterSearch.ElasticSearch Elasticsearch Available
Bielu.BetterSearch.OpenSearch OpenSearch Available
Bielu.BetterSearch.Meilisearch Meilisearch Available; filters only, see the feature matrix
Bielu.BetterSearch.Lifti In memory, on LIFTI Available; to be replaced by Lucene.NET
Bielu.BetterSearch.Lucene Lucene.NET, in memory or on disk Planned (roadmap)

Documentation

The changelog lists what changed in each release.

Building from source

The repository needs the .NET 10 SDK. The solution is src/Bielu.BetterSearch.slnx. The Elasticsearch, OpenSearch and Meilisearch tests start their engine through the Aspire AppHost, so they need Docker.

dotnet build src/Bielu.BetterSearch.slnx
dotnet test --solution src/Bielu.BetterSearch.slnx

To run the engines yourself, start src/examples/Bielu.BetterSearch.Examples.AppHost (aspire run from src/, or dotnet run the project). For Meilisearch the Aspire dashboard links to Meilisearch's own search preview and to meilisearch-ui; the master key is the meilisearch-masterKey parameter shown in the dashboard.

See CONTRIBUTING.md before opening a pull request. Every pull request needs a changeset.

License

Copyright (c) 2024 Arkadiusz Biel. Licensed under the MIT License.

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (10)

Showing the top 5 NuGet packages that depend on Bielu.BetterSearch.Core:

Package Downloads
Bielu.BetterSearch.ElasticSearch

Package Description

Bielu.BetterSearch.Lifti

Package Description

Bielu.BetterSearch.OpenSearch

Package Description

Bielu.BetterSearch.Meilisearch

Package Description

Bielu.BetterSearch.Caching.FusionCache

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0-beta.20261122193512 47 11/22/2026
1.0.0-beta.20261122185900 56 11/22/2026
1.0.0-beta.20261115140832 116 11/15/2026
1.0.0-beta.20261115131256 108 11/15/2026
1.0.0-beta.20261115130723 112 11/15/2026
1.0.0-beta.20261115125817 99 11/15/2026
1.0.0-beta.20261115125225 100 11/15/2026
1.0.0-beta.20261114231717 105 11/14/2026
1.0.0-beta.20261114225816 92 11/14/2026
1.0.0-beta.20261114221153 99 11/14/2026
1.0.0-beta.20261114212816 95 11/14/2026
1.0.0-beta.20261114211723 96 11/14/2026
1.0.0-beta.20261114210618 88 11/14/2026
1.0.0-beta.20261114210103 81 11/14/2026
1.0.0-beta.20261114205610 90 11/14/2026
1.0.0-beta.20261114195414 88 11/14/2026
1.0.0-beta.20261114194127 85 11/14/2026
1.0.0-beta.20261114192126 78 11/14/2026
1.0.0-beta.20261114190827 81 11/14/2026
1.0.0-beta.20261114185948 80 11/14/2026
Loading failed