Allow multiple intermediate fields in number field search (LMFDB#6827) - #35
Allow multiple intermediate fields in number field search (LMFDB#6827)#35roed-math wants to merge 3 commits into
Conversation
The "Intermediate field" search box now accepts a comma-separated list of
subfields (polynomials, field labels, or nicknames, freely mixed). The search
returns number fields containing every listed subfield, i.e. the AND of the
containment conditions (equivalently, fields containing their compositum).
This makes it easy to search for e.g. Q(sqrt2, sqrt3, sqrt5) without first
computing a defining polynomial for the compositum.
parse_subfield splits the input on commas and parses each piece with the
existing input_to_subfield helper, emitting {"$contains": [...]} on the
text[] subfields column. This compiles to a single "subfields @> ARRAY[...]"
Postgres containment test (no per-row recomputation) -- the same operator the
single-subfield search already used, so single-field behavior is unchanged.
Whitespace is stripped by the search parser, so "x^2-2, x^2-3" works too. A
malformed entry raises the existing clean SearchParsingError. Help text and a
test were added.
Verified with the flask test client: single label/polynomial (unchanged),
multiple polynomials and multiple labels both returning the compositum, three
quadratics correctly excluding the degree-4 field, and malformed input giving
a flashed error rather than a 500.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…directly Review follow-up to the comma-separated "Intermediate field" search. parse_subfield dropped list entries that parsed to None, so "x^2-2," and ",x^2-2" were silently treated as "x^2-2", "x^2-2,,x^2-3" as two entries, and "," dropped the subfields constraint altogether, turning the request into an unfiltered number field search. Every entry is now required to be nonempty, both before parsing and after input_to_subfield has removed unsupported characters; an empty one raises the usual SearchParsingError and is flashed. The new tests call the parser directly and compare the query dictionary, so they pin the semantics (one $contains holding every entry, in input order, rather than the first entry alone or an OR) without a database search, and check that each bad input raises and leaves the query untouched. The integration test now bounds degree and discriminant, which makes it decisive instead of timeout-tolerant and cuts it from about 626s on CI to about 5s: among quartic fields of discriminant at most 3000 the search for x^2-2 returns both 4.4.2304.1 and 4.0.256.1, while the search for x^2-2,x^2-3 returns only 4.4.2304.1. Verified: the three tests pass, and each fails if parse_subfield is mutated to keep only the first entry, to emit an $or, or to drop empty entries as before. pyflakes and the repository pylint check are clean on all changed files. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
Both requested changes are in 17c6320. 1. Empty list entries are now rejected. 2. The tests are now decisive and fast.
The bounds matter for runtime, since the sort plus Verification
The remaining slowness is a database-side matter and is now filed separately as LMFDB#7136: |
|
GPT signed off. |
|
Superseded by LMFDB#7169, opened upstream from this same branch. Closing here; review continues upstream. |
The number field search's "Intermediate field" box previously accepted a single subfield. It now
accepts a comma-separated list of subfields (polynomials, field labels, or nicknames, freely mixed),
returning number fields that contain every listed subfield — i.e. the AND of the containment
conditions, equivalently fields containing their compositum. This makes it easy to search for fields
such as Q(√2,√3,√5) or Q(∜2,∛5) without first computing a defining polynomial for the compositum.
Implementation-wise,
parse_subfieldsplits on commas and parses each piece with the existinginput_to_subfieldhelper, emitting a single{"$contains": [...]}on thetext[]subfieldscolumn; this is the same
@>containment operator the single-field search already used, sosingle-subfield behavior is unchanged. An empty entry (a leading, trailing or repeated comma) is
rejected with a flashed error rather than dropped, since dropping it would silently broaden the
search. Help text was added, along with tests that check the parsed query directly (single entry,
list by polynomial, list by label, mixed formats, ordering, and each malformed or empty input) plus
one bounded end-to-end search confirming the AND semantics.
Addresses LMFDB#6827.
🤖 Generated with Claude Code