![]() |
VOOZH | about |
dotnet add package Foundatio.Parsers.LuceneQueries --version 8.0.0
NuGet\Install-Package Foundatio.Parsers.LuceneQueries -Version 8.0.0
<PackageReference Include="Foundatio.Parsers.LuceneQueries" Version="8.0.0" />
<PackageVersion Include="Foundatio.Parsers.LuceneQueries" Version="8.0.0" />Directory.Packages.props
<PackageReference Include="Foundatio.Parsers.LuceneQueries" />Project file
paket add Foundatio.Parsers.LuceneQueries --version 8.0.0
#r "nuget: Foundatio.Parsers.LuceneQueries, 8.0.0"
#:package Foundatio.Parsers.LuceneQueries@8.0.0
#addin nuget:?package=Foundatio.Parsers.LuceneQueries&version=8.0.0Install as a Cake Addin
#tool nuget:?package=Foundatio.Parsers.LuceneQueries&version=8.0.0Install as a Cake Tool
👁 Build status
👁 NuGet Version
👁 feedz.io
👁 Discord
An extensible Lucene-style query parser with support for Elasticsearch and SQL/Entity Framework Core. Build dynamic search APIs, custom dashboards, and powerful query interfaces.
# Core Lucene parser
dotnet add package Foundatio.Parsers.LuceneQueries
# Elasticsearch integration
dotnet add package Foundatio.Parsers.ElasticQueries
# SQL/EF Core integration
dotnet add package Foundatio.Parsers.SqlQueries
using Foundatio.Parsers.LuceneQueries;
using Foundatio.Parsers.LuceneQueries.Visitors;
var parser = new LuceneQueryParser();
var result = parser.Parse("field:[1 TO 2]");
// Debug the AST structure
Console.WriteLine(DebugQueryVisitor.Run(result));
Output from DebugQueryVisitor:
Group:
Left - Term:
TermMax: 2
TermMin: 1
MinInclusive: True
MaxInclusive: True
Field:
Name: field
Regenerate the original query:
string query = GenerateQueryVisitor.Run(result);
// Output: "field:[1 TO 2]"
using Foundatio.Parsers.ElasticQueries;
var parser = new ElasticQueryParser(c => c
.UseMappings(client, "my-index")
.UseFieldMap(new Dictionary<string, string> {
{ "user", "data.user.identity" }
}));
// Build NEST QueryContainer
var query = await parser.BuildQueryAsync("user:john AND status:active");
// Build aggregations
var aggs = await parser.BuildAggregationsAsync("terms:(status min:created max:created)");
// Build sort
var sort = await parser.BuildSortAsync("-created +name");
using Foundatio.Parsers.SqlQueries;
var parser = new SqlQueryParser(c => c
.SetDefaultFields(new[] { "Name", "Description" }));
var context = parser.GetContext(db.Products.EntityType);
string dynamicLinq = await parser.ToDynamicLinqAsync("status:active AND price:>100", context);
var results = await db.Products
.Where(parser.ParsingConfig, dynamicLinq)
.ToListAsync();
field:value, field:"quoted phrase"field:[1 TO 10], field:>100, field:>=2024-01-01AND, OR, NOT, +, -field:val*, field:va?ue_exists_:field, _missing_:fieldcreated:[now-7d TO now]location:75044~75mimin, max, avg, sum, stats, cardinality, percentilesterms, date, histogram, geogrid, missingterms:(category min:price max:price)Full Aggregation Syntax Reference
Map user-friendly names to actual field paths:
var parser = new ElasticQueryParser(c => c
.UseFieldMap(new Dictionary<string, string> {
{ "user", "data.user.identity" },
{ "created", "metadata.createdAt" }
}));
Define reusable query macros:
var parser = new ElasticQueryParser(c => c
.UseIncludes(new Dictionary<string, string> {
{ "active", "status:active AND deleted:false" },
{ "recent", "created:[now-7d TO now]" }
}));
// Expands @include:active inline
var query = await parser.BuildQueryAsync("@include:active AND category:electronics");
Validate and restrict queries:
var parser = new ElasticQueryParser(c => c
.SetValidationOptions(new QueryValidationOptions {
AllowedFields = { "status", "name", "created" },
AllowLeadingWildcards = false,
AllowedMaxNodeDepth = 10
}));
var result = await parser.ValidateQueryAsync(userQuery);
if (!result.IsValid)
return BadRequest(result.Message);
Extend with custom query transformations:
public class CustomVisitor : ChainableQueryVisitor
{
public override async Task VisitAsync(TermNode node, IQueryVisitorContext context)
{
// Custom transformation logic
await base.VisitAsync(node, context);
}
}
var parser = new ElasticQueryParser(c => c
.AddVisitor(new CustomVisitor(), priority: 100));
Foundatio.Parsers.slnx in Visual Studio or VS Codedotnet builddotnet test| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
Showing the top 2 NuGet packages that depend on Foundatio.Parsers.LuceneQueries:
| Package | Downloads |
|---|---|
|
Foundatio.Parsers.ElasticQueries
A lucene style query parser that is extensible and allows additional syntax features. |
|
|
Foundatio.Parsers.SqlQueries
A lucene style query parser that is extensible and allows additional syntax features. |
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 8.0.0 | 1,646 | 5/12/2026 |
| 7.18.3 | 1,682 | 5/12/2026 |
| 7.18.2 | 648 | 5/9/2026 |
| 7.18.1 | 4,153 | 4/28/2026 |
| 7.18.0 | 542 | 4/25/2026 |
| 7.18.0-beta6 | 245 | 4/15/2026 |
| 7.18.0-beta5 | 120 | 4/15/2026 |
| 7.18.0-beta4 | 2,132 | 2/27/2026 |
| 7.18.0-beta3 | 2,394 | 2/14/2026 |
| 7.18.0-beta2 | 165 | 2/14/2026 |
| 7.18.0-beta1 | 589 | 1/12/2026 |
| 7.17.20 | 16,225 | 12/19/2025 |
| 7.17.19 | 2,435 | 11/25/2025 |
| 7.17.18 | 20,430 | 8/20/2025 |
| 7.17.17 | 25,953 | 5/15/2025 |
| 7.17.16 | 6,540 | 5/12/2025 |
| 7.17.15 | 903 | 5/9/2025 |
| 7.17.14 | 15,448 | 1/31/2025 |
| 7.17.13 | 7,250 | 1/13/2025 |
| 7.17.12 | 4,386 | 11/26/2024 |