Lifti (in memory)
Bielu.BetterSearch.Lifti keeps an in-memory index built on LIFTI. It needs no server or configuration, which suits tests and small data sets. It is due to be replaced by a Lucene.NET provider (see the roadmap).
Warning
What won't work
- Silently ignored: paging (
Page,PageSize), sorting and post filters. The query still succeeds and returns every hit, so don't rely on them. ASortOrderwith anullentry or an entry with noFieldNamestill returns a failedResult, as on the other providers. - Facets return a failed
Result: the index keeps the words of each field, not the values to count. - Highlighting returns a failed
Result: the index keeps only the words of each document, not its text, so there is no text to mark the matched terms in. - Range and spatial queries:
DateRangeSubQuery,NumericRangeSubQuery,LongRangeSubQuery,StringRangeSubQueryandSpatialSearchSubQueryreturn a failedResult. A range with neither bound fails with the message every provider gives for it, naming the missing bounds, rather than saying ranges are not supported, and so does aNumericRangeSubQuerywith aNaNor infinite bound. LuceneQueryis not supported.- Fields are ignored: term, terms, fuzzy, prefix and phrase prefix queries match the value in any field.
- A value with no words, such as
null,""or-, returns a failedResultfrom a term, fuzzy, prefix or phrase prefix query, as it could never match. A terms query fails when one of its values has no words; a terms query whose list isnullor empty succeeds with no hits. - Hits only carry the document id, the query's
IndexandScore; no stored fields, andTypeis"". Writing a hit back throughIndexDocumentAsyncreplaces the indexed document with an empty one. - Persistence: the index is lost on restart, and creating an index that exists replaces it, losing its documents.
- Missing index: searching an index that does not exist creates it and returns no hits, where the other
providers return a failed
Result. - Removing from a missing index succeeds:
RemoveDocumentAsyncon an index that does not exist returns success, where the other providers return a failedResult. See Removing documents. - Cancelling a running search: the token is only checked before the search starts; once running, it runs to the end.
- Culture filter (
FilterByCulture): the field is ignored, so a document holding the culture value in another field matches too.
Install
dotnet add package Bielu.BetterSearch.Core --prerelease
dotnet add package Bielu.BetterSearch.Lifti --prerelease
Register
using Bielu.BetterSearch.DependencyInjection;
builder.Services.AddBetterSearch(search => search.AddLiftiSearch());
There is nothing to configure.
A write is searchable as soon as the call returns, as the index is in memory.
How queries behave
Must,ShouldandMustNotfollow Lucene semantics, as on the other providers: alongsideMust,Shouldchanges nothing, and a nested bool with onlyMustNotclauses excludes from its parent's matches.- A query that would match every document except some exclusions, such as one with only
MustNotclauses, returns a failedResult, as Lifti has no query for every document. Filteris treated asMust, so it still scores.- Total hit count is exact.
- Values are split into words as the index splits them. Field values are turned into text the same way on
every machine and split into words at punctuation and spaces, with case and accents folded, so
3.5is indexed as the words3and5. A term, terms, fuzzy, prefix or phrase prefix value goes through the same tokenizer, and its words must be next to each other, in order:3.5matches3.5but not5.3or35, aDateTimematches that date, as both are written as ISO 8601 text in UTC (2026-11-08T00:00:00Z),żółwmatchesŻółw, andjane das a phrase prefix matchesJane Doe. Fuzzy matches each word on its own, and prefix and phrase prefix match the last word as a prefix. Fuzzy allows 2 edits for every word whenMaxEditsis unset, notAUTOas on Elasticsearch, and uses an explicitMaxEditsas given, with no limit of 2. A prefix value that ends with punctuation or a space, such as3., has a complete last word, so that word matches whole and must be followed by another word:3.matches3.5, not35or3. As Lifti has no wildcard that excludes one word, that following word can be the next value of a multi-valued field, so3.also matches a field holding3andx. One word of a value, such as the year2026of a date, still matches the whole value, as a word does in any text field. - Multi-valued fields: the words of one value are never next to the words of another, so
3.5does not match a field holding3and5.
Indexing several documents
IndexMultipleDocumentsAsync adds each index's documents with one AddRangeAsync, which Lifti applies as one
change, and returns how many documents it indexed. When Lifti rejects one document (one without an id, say),
the Result fails naming every id of that index, with all of them in the error's ids metadata, and none of
them is stored.
Removing documents
DeleteDocumentRequest.Index names the index to remove the document from.
- A document that is not there:
RemoveDocumentAsyncsucceeds, as the document is already gone. - An index that does not exist:
RemoveDocumentAsyncsucceeds and does not create the index. Lifti keeps indexes in memory, so after a restart every index is missing until something writes to it; a missing index holds no documents, so the document is already gone. Reporting a failure there would make callers log errors or retry deletes that are already done. A misspelled index name therefore goes unnoticed, unlike on the other providers. - Several documents:
RemoveDocumentsAsync(index, ids)removes the ids one by one and returns how many were removed. A missing index succeeds with 0 and is not created, and cancellation, the index lookup, the client factory and the lock below work as withRemoveDocumentAsync. - Cancellation: a cancelled token throws
OperationCanceledException, as on Elasticsearch. Any other exception is caught and returned as a failedResultthat keeps the exception as its cause. A failed lookup fromILiftiIndexManager.GetIndexAsyncis returned with the manager's own errors, as supplied. - Which index: the index manager (
ILiftiIndexManager.GetIndexAsync) says whether the index exists; the document is then removed from the index the registeredIClientFactoryAsync<IFullTextIndex<string>>returns, the same one indexing writes to. A customILiftiIndexManagermust implementGetIndexAsyncand returnnull, without creating the index, when it does not exist. - Removing while the index is deleted:
RemoveDocumentAsync,RemoveDocumentsAsync,DeleteIndexAsyncandRemoveAllDocumentsAsyncon the provider take a lock per index name, shared by every provider on the sameILiftiIndexManager. A delete therefore can't land between the lookup and the factory call, which would make the factory create the deleted index again. The lock does not cover calls made on the index manager directly.
Index prefix and rebuilds
Lifti has no IndexPrefix, as its indexes live in the process and nothing else shares them. It has no index rebuilds
either: the provider does not implement IIndexLifecycleProviderAsync, so every IIndexLifecycleServiceAsync call
returns a failed Result.
Getting, counting and updating documents
Lifti keeps only the words of each document, not its fields, so GetDocumentAsync and UpdateDocumentAsync
return a failed Result saying so; index the whole document again to change it. CountAsync runs the query as
a search does and counts every match, which is exact; on a missing index it creates the index and counts 0, as
a search there does.
Errors
When a custom ILiftiIndexManager or IClientFactoryAsync<IFullTextIndex<string>> throws, every indexing method
returns a failed Result with the exception as its cause. An OperationCanceledException from either of them
propagates. A failed Result from ILiftiIndexManager.CreateIndexAsync is returned by CreateIndexAsync with
all of its errors.
Health check
PingAsync always succeeds, as the indexes live in the application's own memory and there is no engine to reach,
so AddBetterSearchHealthCheck() reports Lifti as healthy whenever the application runs. It throws
OperationCanceledException when the token is already cancelled.
The feature matrix has the full detail.