Recursive AI

Skip indexing a column in SQLite FTS5

OneLite is a free, open-source SQLite-compatible database for .NET from Recursive AI. MIT or Apache-2.0, no native dependencies.

Use fts5(body, label UNINDEXED) to search the body and return the label without indexing its words.

Terminal
dotnet add package RecursiveAI.OneLite

Requires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.

C#
using RecursiveAI.OneLite;
 
await using var db =
    await Database.OpenAsync(":memory:");
await db.ExecuteAsync($"""
    CREATE VIRTUAL TABLE notes
    USING fts5(body, label UNINDEXED)
    """);
await db.ExecuteAsync($"""
    INSERT INTO notes VALUES
    ('Fix the bicycle', 'workshop')
    """);
Console.WriteLine(
    await db.ScalarAsync<string>($"""
    SELECT label FROM notes
    WHERE notes MATCH {"bicycle"}
    """));

The snippet prints workshop. The download also searches for workshop itself.

Unzip the example, then dotnet run.

Text
bicycle matches: 1
Stored label: workshop
workshop matches: 0

The full program

The download searches both bicycle and workshop. The first term matches the body and returns the stored label. The second term appears only in label, so MATCH returns no rows, not an error.

C#
using RecursiveAI.OneLite;
 
await using var db =
    await Database.OpenAsync(":memory:");
await db.ExecuteAsync($"""
    CREATE VIRTUAL TABLE notes
    USING fts5(body, label UNINDEXED)
    """);
await db.ExecuteAsync($"""
    INSERT INTO notes VALUES
    ('Fix the bicycle', 'workshop')
    """);
 
foreach (var term in new[] { "bicycle", "workshop" })
{
    var labels = await db.QueryAsync<string>($"""
        SELECT label FROM notes WHERE notes MATCH {term}
        """);
    Console.WriteLine($"{term} matches: {labels.Count}");
    foreach (var label in labels)
        Console.WriteLine($"Stored label: {label}");
}
Text
bicycle matches: 1
Stored label: workshop
workshop matches: 0

Variations

To look up the label itself, use SQL equality instead of MATCH. Replace the query inside the loop with this one.

C#
var labels = await db.QueryAsync<string>($"""
    SELECT label FROM notes WHERE label = {term}
    """);
Text
bicycle matches: 0
workshop matches: 1
Stored label: workshop

The short answer

Add UNINDEXED to the column declaration in CREATE VIRTUAL TABLE … USING fts5(...). In fts5(body, label UNINDEXED), body supplies searchable words while label supplies a value you can select. FTS5 won’t return a row just because a search term appears in the label.

Use UNINDEXED when a field should never contribute to full-text matches. A display label, source URL, or external ID can still travel with the search result without affecting which rows appear. Put the keyword on each column you want to exclude; it is a column option, not a switch on the entire FTS5 table. OneLite’s FTS5 documentation lists UNINDEXED and column filters separately because they solve different problems.

If a field should be searchable on some screens but not others, leave it indexed and restrict each query that needs a narrower search. For example, body MATCH ? searches only the body. That restriction changes the current query, not what FTS5 stores in the index.

Can you filter on an unindexed FTS5 column?

Yes. UNINDEXED affects the full-text index, not whether ordinary SQL can read the stored value. In the example, label = 'workshop' still finds the row. That expression compares the whole value instead of looking for a word within a longer label. An equality filter can be combined with MATCH: use one to filter on the stored label and the other to search the body. If metadata lookup is a main access path, consider an ordinary table with a regular SQL index for that metadata.

What is stored in an FTS5 table?

By default, FTS5 keeps both the original values and a separate index of searchable tokens. UNINDEXED skips the index entries, not the stored value. This recipe uses the default content storage. An external-content FTS5 table reads values from a separate table instead, and the application must keep the index in sync with that table.

All onelite recipes