Skip to content

Add configurable minimum query length for lookups#279

Open
gaurav wants to merge 2 commits into
mainfrom
set-min-size
Open

Add configurable minimum query length for lookups#279
gaurav wants to merge 2 commits into
mainfrom
set-min-size

Conversation

@gaurav

@gaurav gaurav commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator

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.

  • Config: new NAMERES_MINIMUM_QUERY_LENGTH env var (default 2 — Translator expects useful results at length 2). Scattered env reads are consolidated into a central Config dataclass, whose public subset is surfaced under a new config block 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 /lookup now 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 with tests/data/test-synonyms.json.
  • New test_minimum_query_length covers: single-char /lookup → 422, 2-char query still returns a 200 list, /bulk-lookup degrades a short string to [] while others resolve, and /status reports config.minimum_query_length.
  • Verified the NAMERES_MINIMUM_QUERY_LENGTH env override takes effect and that the 422 appears in the generated OpenAPI schema.

🤖 Generated with Claude Code

gaurav and others added 2 commits July 17, 2026 19:32
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

1 participant