Skip to content

Allow multiple intermediate fields in number field search - #7169

Open
roed-math wants to merge 3 commits into
LMFDB:mainfrom
roed-math:ai/t38-nf-multi-subfield
Open

Allow multiple intermediate fields in number field search#7169
roed-math wants to merge 3 commits into
LMFDB:mainfrom
roed-math:ai/t38-nf-multi-subfield

Conversation

@roed-math

Copy link
Copy Markdown
Contributor

Closes #6827.

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(sqrt2, sqrt3, sqrt5) or Q(2^(1/4), 5^(1/3)) without first computing a defining polynomial for the compositum.

Implementation-wise, parse_subfield splits on commas and parses each piece with the existing input_to_subfield helper, emitting a single {"$contains": [...]} on the text[] subfields column; this is the same @> containment operator the single-field search already used, so single-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.


Ported from roed-math#35, where the full write-up and comment history live.

🤖 Generated with Claude Code

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow for multiple intermediate fields in number field search

2 participants