Repository navigation
Harden Foundatio.Lucene for 1.0: SQL/ES parity, scoped config swapping, API lock - #65
Merged
Merged
Conversation
- Add LuceneParser.MaxDepth (default 100) bounding group recursion to prevent a StackOverflow DoS from deeply nested input. Over-depth records a MaxDepthExceeded ParseError and the group is discarded iteratively. - Parse boost (^) and fuzzy/slop (~N) with InvariantCulture so values such as 2.5 do not change meaning on comma-decimal locales. - Fix a lexer trailing-backslash overrun in quoted-string and regex scanning that advanced past the end of the buffer (could throw inside Slice). - Add a Code (QueryErrorCode) field to ParseError and classify depth, bracket, range and unexpected-character errors. - Remove the dead ParseNumberTerm method.
- Delete the orphaned, untested TenantOptionsCache / EntityOptionsCache / TenantEntityOptionsCache and VisitorPool (~700 lines, zero references). Per-request options (ElasticsearchQueryOptions / EntityFrameworkQueryOptions, both immutable records) are the blessed scope-swap path; apps own caching. - ElasticsearchQueryParser now carries the per-scope field map and includes on the visitor context and reuses singleton FieldResolver/Include visitors instead of allocating a new visitor per query when a scope supplies its own config. Removes per-query visitor allocation on the swap path. - Add ConfigSwapBenchmarks (ES + EF) measuring per-query allocations when each query swaps a different scope against a shared parser.
- EntityFrameworkQueryParser now runs the shared pre-build visitor pipeline (field-alias resolution, @include expansion, date-math evaluation) before building the LINQ expression, so per-scope FieldMap, includes, and date math behave identically to the Elasticsearch integration (previously silently ignored in SQL). Adds a configurable TimeProvider to the EF configuration. - Capability model: the EF builder throws QueryBuildException (UnsupportedQueryType) for fuzzy (term~N) and proximity/slop ("..."~N) queries instead of silently degrading them to substring matches. - Add Foundatio.Lucene.Parity.Tests: starts SQL Server + Elasticsearch containers, seeds identical data, and asserts the same Lucene query returns the same result set on both engines across the supported construct set.
- Remove the dead Elasticsearch geo surface (IsGeoPointField, GeoLocationResolver, UseGeoFields/UseGeoLocationResolver/WithGeoPointFields, context geo members and the geo lines in CreateContext). The builder never emitted geo queries and the async resolver could not be awaited in the synchronous pipeline; geo is deferred to a post-1.0 design that keeps the visitor pipeline synchronous. - Unify the duplicate default-operator enum: Elasticsearch now uses Foundatio.Lucene.Ast.BooleanOperator everywhere and the separate QueryOperator enum is deleted. - Make LuceneParseResult.Document/Errors init-only. - Fix EntityFieldInfo equality/hash to key on FullName instead of the leaf Name (nested fields sharing a leaf name no longer collide) and remove the unused public IsMoney property.
- QueryResultTests: success/failure model, GetValueOrThrow, GetValueOrDefault, Map, Try, Deconstruct, and implicit-bool behavior. - ElasticsearchErrorAndConcurrencyTests: TryBuildQuery returns a Failure (not a throw) on malformed input, and a stress test mutating registered per-index options (SetOptions/RemoveOptions) while building queries on a shared parser. - EF: TryBuildFilter returns a Failure on malformed input.
- Add root LICENSE (Apache-2.0) matching the package license expression. - Add CHANGELOG documenting the 1.0 hardening (added/changed/removed/fixed, breaking changes, and the PublicApiAnalyzers follow-up). - Fix pervasive documentation drift: examples now use the real synchronous API (no ParseAsync/BuildQueryAsync/RunAsync/AcceptAsync/VisitAsync), the real AST shape (no BooleanQueryNode.Left/Right, GroupNode.Child, FieldQueryNode.Value, or IncludeNode), BooleanOperator instead of QueryOperator, and reflect the geo removal and the EF field-map/include/date-math pipeline. Correct AGENTS.md (recursive-descent parser; synchronous QueryVisitor.Visit pattern).
Follow-up to the Elasticsearch enum unification and EF pipeline wiring.
Adding the cross-engine parity project introduced a second Elasticsearch container; running the full solution test suite then launched 2x ES + 2x SQL concurrently and exhausted Docker memory. Bound the ES JVM heap (-Xms512m -Xmx512m) in both ES fixtures (the test data sets are tiny) so the full `dotnet test` run is reliable.
State the API is synchronous positively instead of enumerating *Async methods that do not exist.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
Prepares the library for a stable 1.0, centered on the primary use case: high-performance per-scope configuration swapping (each scope/tenant has its own custom fields, aliases, and options) that works equally well with SQL (EF Core) and Elasticsearch. Delivered as six milestones, one commit each (plus two small cleanups).
What changed
M1 — core/lexer hardening (
61feaae)LuceneParser.MaxDepth(default 100) bounds group recursion → fixes an uncatchableStackOverflowExceptionDoS on deeply nested input.^) and fuzzy/slop (~N) parsing.ParseError.Code(QueryErrorCode) classification; removed deadParseNumberTerm.M2 — symmetric scope-swap mechanism (
13444ca)TenantOptionsCache/EntityOptionsCache/TenantEntityOptionsCache/VisitorPool(~700 LOC). Per-request options (immutable records) are the blessed swap path; apps own caching.ConfigSwapBenchmarks(EF + ES).M3 — SQL/ES parity (
2fb0cf0)@includeexpansion, date math) — these were exposed on the options API but silently ignored in SQL. Added a configurableTimeProviderto the EF config.QueryBuildException(UnsupportedQueryType) for fuzzy/proximity queries instead of silently degrading them to substring matches.Foundatio.Lucene.Parity.Testsseeds identical data into SQL Server + Elasticsearch (Testcontainers) and asserts the same Lucene query returns the same result set on both engines.M4 — public API lock (
a96ba78)QueryOperator→Ast.BooleanOperator.LuceneParseResult.Document/Errorsareinit-only;EntityFieldInfoequality keys onFullName(was the leafName); removed unusedIsMoney.M5 — test coverage (
e2b572c) —QueryResultmodel, ES/EFTryBuild*failure paths, registered-options mutation under concurrent builds.M6 — release essentials (
60b98fc) — rootLICENSE(Apache-2.0),CHANGELOG.md, and a full docs-drift fix: the docs site assumed a non-existent async visitor API and AST shape; examples now use the real synchronous API and reflect the geo removal + EF pipeline support. CorrectedAGENTS.md(recursive-descent parser; syncQueryVisitor.Visit).Breaking changes
TenantOptionsCache/VisitorPoolfamily, the Elasticsearch geo config surface, theQueryOperatorenum, andEntityFieldInfo.IsMoney.LuceneParseResultmembers are init-only.Warrants a
v1.0.0tag (not a patch).Testing
dotnet buildclean;dotnet format --verify-no-changesclean.dotnet testrun — core, EF (incl. SQL Server FTS integration), Elasticsearch (incl. real ES 9.0), and the cross-engine parity gate, all concurrent. (ES test-container heap is capped so the suites run side by side.)Follow-ups (documented in CHANGELOG, not blockers)
Microsoft.CodeAnalysis.PublicApiAnalyzerswith committed baselines (surface is already cleaned; this adds the build-time guardrail — best generated via the IDE one-click fix).