Add configurable minimum query length for lookups#279
Open
gaurav wants to merge 2 commits into
Open
Conversation
Single-character lookups make Solr work hard while never returning a sensible result. Reject queries shorter than a configurable minimum (NAMERES_MINIMUM_QUERY_LENGTH, default 2) before they reach Solr. - Consolidate env-var config into a central `Config` dataclass; expose a public subset (currently just `minimum_query_length`) via `/status`. - `/lookup` returns HTTP 422 for too-short queries (documented in the OpenAPI schema); `/bulk-lookup` maps each too-short string to `[]` so one short string does not fail the whole batch. Note: empty-string `/lookup` now returns 422 instead of an empty list. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Note the minimum-length requirement and 422 on /lookup, the graceful []-per-key behavior on /bulk-lookup, and the new config block in /status. Co-Authored-By: Claude Opus 4.8 <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.
Summary
Log analysis showed that single-character lookups make Solr work very hard while never returning a sensible result. This adds a configurable minimum query length that rejects too-short queries before they hit Solr.
NAMERES_MINIMUM_QUERY_LENGTHenv var (default 2 — Translator expects useful results at length 2). Scattered env reads are consolidated into a centralConfigdataclass, whose public subset is surfaced under a newconfigblock in/status./lookup: returns HTTP 422 for queries shorter than the minimum (after whitespace is stripped). Documented in the OpenAPI schema with an explanation./bulk-lookup: a too-short string maps to[]for that key, so one short string doesn't fail the whole batch.Behavior change
Empty-string
/lookupnow returns 422 instead of an empty list (it counts as "too short"). Callers relying on the old empty-list response should note this.Testing
python -m pytest tests/→ 29 passed against a live Solr loaded withtests/data/test-synonyms.json.test_minimum_query_lengthcovers: single-char/lookup→ 422, 2-char query still returns a 200 list,/bulk-lookupdegrades a short string to[]while others resolve, and/statusreportsconfig.minimum_query_length.NAMERES_MINIMUM_QUERY_LENGTHenv override takes effect and that the 422 appears in the generated OpenAPI schema.🤖 Generated with Claude Code