Adding pattern-based search to your .NET app
Drop the IndxSearchLib NuGet package into a C# project and run your first search in a few minutes.
Indx embeds directly into your .NET process. There is no separate search server to run, and nothing to configure before you start: pattern recognition and BM25 scoring handle typos and messy input without tokenizers, stemmers, or analyzers. This guide takes you from an empty project to your first filtered search.
Install
dotnet add package IndxSearchLib
Initialize and configure fields
Indx works on a JSON array of objects. Init parses the structure and discovers the fields with their types. Nothing is searchable by default. You assign each field a role yourself.
using Indx.Api;
var engine = new SearchEngine();
using var stream = File.OpenRead("products.json");
engine.Init(stream);
var name = engine.GetField("name")!;
var category = engine.GetField("category")!;
name.Searchable = true;
name.Weight = 2.0f; // float, default 1.25, relative to other searchable fields
category.Filterable = true;
category.Facetable = true;
A field can hold several roles at once. Here category is both filterable and facetable, so it can narrow results and show value counts in a sidebar.
Load and index
Stream the same JSON in again to load the documents, then build the index:
stream.Position = 0;
engine.Load(stream);
engine.Index();
The engine is now in the Ready state. From here you can also insert, update, and delete individual documents without rebuilding.
Search
var result = engine.Search(new Query("wireles", 20)); // typo is tolerated
foreach (var entry in result.Entries)
Console.WriteLine($"key={entry.DocumentKey} score={entry.Score}");
// Pull the full JSON for the matches:
var keys = result.Entries.Select(e => e.DocumentKey).ToArray();
var docs = engine.GetJsonDataOfKeys(keys);
Search returns keys and scores, not full documents. Fetch the JSON separately and keep the result list light.
A query like "wireles" still finds "Wireless Headphones". Pattern matching, no tuning required.
Filter results
Filters run server-side against the whole dataset. Never filter the returned array yourself: it only holds the top results, so you would miss matches.
var audio = engine.CreateValueFilter("category", "audio", out _);
var result = engine.Search(new Query("wireless", 20) { Filter = audio });
Range filters work the same way, and filters combine with &, |, and !:
var affordable = engine.CreateRangeFilter("price", 0, 50, out _);
var combined = audio & affordable;
Next steps
- Getting started is the full walkthrough, including sorting and facets
- C# API reference
- Frontend in another stack? Self-host IndxCloudApi, a ready-to-deploy ASP.NET Core server, and call its REST API from anywhere
More articles
A skill, agent-readable docs, and a built-in MCP server. Describe what you want searchable, and your agent does the rest.
A faster search engine and a redesigned cloud platform, now in beta. See what is changing and how to try the preview.