A library for adding dynamic Lucene-style query capabilities to your .NET applications. Enable your users to write powerful search queries using familiar Lucene syntax, with support for Entity Framework and Elasticsearch.
This project is a modern replacement for Foundatio.Parsers.
- 🔍 Full Lucene Syntax - Terms, phrases, fields, ranges, boolean operators, wildcards, regex
- ⚡ Entity Framework Integration - Convert Lucene queries directly to LINQ expressions
- 🔎 Elasticsearch Support - Generate Elasticsearch Query DSL using the official .NET 9.x client
- 🧩 Visitor Pattern - Transform, validate, or analyze queries with composable visitors
- 🗺️ Field Aliasing - Map user-friendly field names to your actual data model
- ✅ Query Validation - Restrict allowed fields, operators, and patterns
- 🔄 Round-Trip Capable - Parse queries to AST and convert back to query strings
- 🛡️ Error Recovery - Resilient parser returns partial AST with detailed error information
using Foundatio.Lucene;
using Foundatio.Lucene.EntityFramework;
// Parse a Lucene query
var result = LuceneQuery.Parse("title:hello AND status:active");
// Or build LINQ expressions for Entity Framework
var parser = new EntityFrameworkQueryParser();
Expression<Func<Employee, bool>> filter = parser.BuildFilter<Employee>(
"name:john AND salary:[50000 TO *]"
);
var employees = await context.Employees.Where(filter).ToListAsync();Key topics:
- Getting Started - Installation and basic usage
- Query Syntax - Full syntax reference
- Entity Framework - EF Core integration
- Elasticsearch - Elasticsearch Query DSL generation
- Visitors - AST transformation patterns
- Validation - Query validation options
Want the latest CI build before it hits NuGet? Add the Feedz source (read-only public) and install the pre-release version:
dotnet nuget add source https://f.feedz.io/foundatio/foundatio/nuget -n foundatio-feedz
dotnet add package Foundatio.Lucene --prereleaseOr add to your NuGet.config:
<configuration>
<packageSources>
<add key="foundatio-feedz" value="https://f.feedz.io/foundatio/foundatio/nuget" />
</packageSources>
<packageSourceMapping>
<packageSource key="foundatio-feedz">
<package pattern="Foundatio.*" />
</packageSource>
</packageSourceMapping>
</configuration>CI builds are published with pre-release version tags (e.g. 1.0.0-preview.12345+sha.abcdef). Use them to try new features early—avoid in production unless you understand the changes.
Contributions are welcome! Please feel free to submit a Pull Request. See our documentation for development guidelines.
- Foundatio.Parsers - The predecessor to this library
- Foundatio - Pluggable foundation blocks for building distributed apps
Apache 2.0