SearchEngine.Sharp 0.5.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package SearchEngine.Sharp --version 0.5.0
                    
NuGet\Install-Package SearchEngine.Sharp -Version 0.5.0
                    
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="SearchEngine.Sharp" Version="0.5.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SearchEngine.Sharp" Version="0.5.0" />
                    
Directory.Packages.props
<PackageReference Include="SearchEngine.Sharp" />
                    
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 SearchEngine.Sharp --version 0.5.0
                    
#r "nuget: SearchEngine.Sharp, 0.5.0"
                    
#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 SearchEngine.Sharp@0.5.0
                    
#: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=SearchEngine.Sharp&version=0.5.0
                    
Install as a Cake Addin
#tool nuget:?package=SearchEngine.Sharp&version=0.5.0
                    
Install as a Cake Tool

SearchEngine.Sharp

In-memory inverted index for .NET. Supports exact token match, substring (within-word) search, boolean expressions (AND / OR / NOT), and natural sort ordering of results.

Target: .NET 10 (C# 14). NuGet: SearchEngine.Sharp (publish on tag v*).

Requirements

Build

dotnet build SearchEngine.Sharp.sln -c Release

Tests

dotnet test SearchEngine.Sharp.sln -c Release

Benchmarks

Console app on synthetic data. Reports query throughput (queries/s) and P50/P95 latency.

dotnet run -c Release --project benchmarks/SearchEngine.Sharp.Benchmarks

Optional parallel infix experiment (not part of the library API):

dotnet run -c Release --project benchmarks/SearchEngine.Sharp.Benchmarks -- --parallel

Flags: --warmup N, --iterations N, --seed N.

Usage

Without DI

using SearchEngine;
using SearchEngine.Snapshots;

var provider = new IndexSnapshotProvider();
var updater = new IndexUpdater(provider);

updater.RebuildFrom(new Dictionary<int, string>
{
    [1] = "GA-100 digital watch",
    [2] = "GA-200 analog watch",
});

var engine = new SearchEngineSharp(provider);

// Exact token match
var exact = engine.Find("digital", WordMatchMethod.Exact);

// Substring match (within indexed words)
var within = engine.Find("ana", WordMatchMethod.Within);

// Boolean expression
var filtered = engine.Find("digital AND watch", WordMatchMethod.Exact, enableOperators: true);

// Natural sort by model name (requires IndexedEntry with separate SortText)
var sorted = engine.Find("watch", WordMatchMethod.Exact, enableOperators: false,
    sortMode: SearchSortMode.NaturalSortAscending);

With DI

using Microsoft.Extensions.DependencyInjection;
using SearchEngine;
using SearchEngine.DependencyInjection;

var services = new ServiceCollection();
services.AddSearchEngine();
var sp = services.BuildServiceProvider();

var updater = sp.GetRequiredService<IIndexUpdater>();
var engine = sp.GetRequiredService<ISearchEngine>();

updater.AddEntry(1, "example text");
var ids = engine.Find("example", WordMatchMethod.Exact);

AddSearchEngine overloads accept an initial snapshot, a keyed index, or a custom snapshot factory. See ServiceCollectionExtensions.

IndexedEntry

When search text and display/sort text differ:

updater.RebuildFrom(new Dictionary<int, IndexedEntry>
{
    [10] = new("GA-100 G-Shock digital", "GA-100"),
});

SearchText is tokenized and matched. SortText drives SearchSortMode.NaturalSortAscending.

API summary

Type Role
ISearchEngine Query execution (Find, CountMatches)
IIndexUpdater Index mutations (rebuild, add, remove)
IIndexSnapshotProvider Current immutable snapshot
SearchEngineSharp Default ISearchEngine implementation
IndexSnapshotBuilder Build snapshot without DI
WordMatchMethod.Exact Whole-token match
WordMatchMethod.Within Substring match inside indexed tokens
SearchSortMode.SnapshotOrder Result order follows internal document ordinals
SearchSortMode.NaturalSortAscending Sort by natural key derived from SortText

Index updates

Each mutation rebuilds the full index from the in-memory entry dictionary. Batch methods (AddOrUpdateEntries, RemoveEntries) perform one rebuild per call. Async rebuild methods consume input outside the update lock.

Queries read the current snapshot via Volatile.Read; updates publish a new snapshot with Interlocked.Exchange. Snapshots are immutable.

Platform notes

Runs on any .NET 10-supported OS and CPU architecture.

FastBitSet set operations use runtime CPU detection:

  • x64 with AVX2: 256-bit SIMD path
  • ARM64 with AdvSimd: 128-bit SIMD path
  • otherwise: scalar fallback

Infix search in the library is single-threaded. A parallel variant exists only under benchmarks/ for measurement.

Publishing (maintainers)

NuGet.org uses Trusted Publishing (OIDC), not long-lived API keys.

  1. nuget.org → Account → Trusted Publishing → add policy:
    • Provider: GitHub Actions
    • Owner: buchmiet
    • Repository: SearchEngine.Sharp
    • Workflow: publish-nuget.yml
    • Environment: production (must match the workflow job environment:)
  2. GitHub → repo Settings → Environments → ensure production exists (created automatically on first run).
  3. GitHub → Secrets → Actions → NUGET_USER = nuget.org profile username (policy creator; see your profile URL, not display name).
  4. Push a version tag, e.g. git tag v0.5.0 && git push origin v0.5.0.

The workflow builds, tests, packs, exchanges an OIDC token for a short-lived push key, then publishes.

Project layout

src/SearchEngine.Sharp/          Library
tests/SearchEngine.Sharp.Tests/  xUnit tests
benchmarks/SearchEngine.Sharp.Benchmarks/  Throughput console app

License

MIT. Copyright (c) 2026 Lukasz Buchmiet.

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

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
0.5.5 119 7/3/2026
0.5.4 95 7/3/2026
0.5.3 103 7/2/2026
0.5.2 100 7/2/2026
0.5.1 98 7/2/2026
0.5.0 102 7/1/2026