Allow multiple intermediate fields in number field search - #7169
Open
roed-math wants to merge 3 commits into
Open
Allow multiple intermediate fields in number field search#7169roed-math wants to merge 3 commits into
roed-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>
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.
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_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, 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