redis-vl-dotnet
TextQuery
TextQuery wraps a raw RediSearch query string and optional projections.
When to use it
Use TextQuery when the user already has a text predicate such as:
-
token matches like
heat -
OR expressions like
Alien|Arrival -
RediSearch prefix or grouped expressions authored directly as a query string
TextQuery requires a non-blank string and trims surrounding whitespace before execution.
Basic shape
var projectedTextResults = await index.SearchAsync(
new TextQuery("Alien|Arrival", ["title", "year"], limit: 2));
var typedTextResults = await index.SearchAsync<Movie>(
new TextQuery("Alien|Arrival", ["title", "year", "genre", "summary"], limit: 2));
The canonical runnable reference is /examples/JsonStorageExample.
Paging, projections, and mapping
TextQuery uses the same QueryPagination model as FilterQuery:
-
default paging is
offset: 0,limit: 10 -
returnFieldsare normalized and deduplicated -
typed mapping works through
SearchResults.Map<TDocument>()andSearchAsync<TDocument>(…)
If a required projected field is missing or cannot be converted into the target .NET property type, the library throws SearchResultMappingException. The mapping contract is covered in tests/RedisVL.Tests/Queries/SearchResultMappingTests.cs.
Batch helpers
Use SearchBatchesAsync when you want to stream pages:
await foreach (var batch in index.SearchBatchesAsync(
new TextQuery("Alien|Arrival", ["title"], pagination: new QueryPagination(limit: 1)),
batchSize: 1))
{
foreach (var document in batch.Documents)
{
Console.WriteLine(document.Values["title"]);
}
}
This exact pattern is used in /examples/JsonStorageExample.
Per-field weights
Pass fieldWeights to spread the query terms across multiple text fields and boost individual fields. When fieldWeights is supplied, the Text is treated as whitespace-separated terms (OR’d together) instead of a raw query string:
var weighted = new TextQuery(
"redis search",
fieldWeights: new Dictionary<string, double>
{
["title"] = 5.0,
["body"] = 1.0,
});
// weighted.QueryString =>
// (@title:(redis | search) => { $weight: 5 } | @body:(redis | search))
A field with weight 1.0 is emitted without a $weight modifier, and a single weighted field is not wrapped in parentheses. Weights must be greater than zero. When fieldWeights is omitted the QueryString is the raw Text, preserving the existing behavior.