Advanced Search discards the current query and any selected filters
Problem
Every tab in the search navigation carries the current query forward except Advanced Search, which links to a bare /advancedsearch. The form on that page also reads nothing from the request, so a patron who has built up a search and wants to refine it more precisely lands on an empty form and starts from scratch.
It's the one place in the search flow where state is dropped rather than carried, and it lands on the patron most likely to want it — someone whose search is already specific enough that they've gone looking for the advanced form. The form posts back to /search, so it's meant to be part of the same loop.
Reproducing the bug
- Go to https://openlibrary.org/search?q=quantum+entanglement&subject_facet=Physics
- Click "Advanced Search" in the tab strip under the "Search Books" heading
- Expected behavior: the Subject field is prefilled with "Physics", and the free-text query is preserved
- Actual behavior: every field is blank and the query is gone; the Physics filter that was visible as a chip a moment earlier has vanished, with no way back to it except the browser's back button
Context
- Browser (Chrome, Safari, Firefox, etc): any
- OS (Windows, Mac, etc): any
- Logged in (Y/N): N
- Environment (prod, dev, local): prod
Breakdown
Related files
openlibrary/macros/SearchNavigation.html— line 28. The other five tabs build their href as/search/...?$urlencode(dict(q=q)); this one is a barehref="/advancedsearch".openlibrary/templates/search/advancedsearch.html— novalue=bindings anywhere, so the form renders empty regardless of what's in the URL.
Note for maintainers
Four of the visible fields map straight onto search-page facets: subject/subject_facet, person/person_facet, place/place_facet, publisher/publisher_facet, plus author/author_facet. The free-text query is a little different, since q is a hidden input with no visible control — carrying it through would preserve the patron's text search without showing it back to them, which may or may not be what you want.
So this isn't quite a one-liner, and I didn't want to assume the answer: is it just q, or the facets too? Happy to pick it up either way once that's decided.
Thank you @pnelson1337 for submitting this issue!
Contributors, this issue will be ready to work on once:
- [ ] Triage — maintainers will add
Priority: *andLead: @*
Context
- The nav tab confirmed at
openlibrary/macros/SearchNavigation.html#L26-L28— the "Advanced Search"<li>is a barehref="/advancedsearch", while the other five tabs in the same list build their href with/search?$urlencode(dict(q=q)), confirming the asymmetry described. - The route handler at
openlibrary/plugins/worksearch/code.py#L958-L962(class advancedsearch) callsrender_template("search/advancedsearch.html")with no arguments at all — it isnt only the template thats missing bindings, the view passes nothing through either. openlibrary/templates/search/advancedsearch.html#L7-L20confirms none of thetitle/author/isbn/subject/place/person/publisherinputs havevalue=, and the existing<input type="hidden" name="q" id="qtop">(line 10) has no value bound either — its presence suggests carryingqsilently was already the intent, just never wired up.- On the reporters open question of whether to carry
qor just the facets:query_param()(frominfogami.utils.view,@public-registered so its callable directly inside any Templetor template without the Python view passing it through) is already used this exact way elsewhere — e.g.openlibrary/templates/work_search.html#L122($ query = query_param(q)) andopenlibrary/templates/subjects.html#L7. This means the fix likely does not require touchingadvancedsearch.GETat all —advancedsearch.htmlcan callquery_param(...)directly per field, the same waySearchNavigation.htmlalready does forq. - Related, broader issue: #2673 "Improvements to the Advanced Search Page" (open,
Lead: @cdrini) tracks adding more fields to this same form, but does not cover this specific query/filter-carryover gap — not a duplicate.
Issue Assessment
Action items
- [x] Should the hidden
qfield be carried through, or only the visible facet fields? (Answer: Both. The hiddenqtopinput already exists in the template for exactly this purpose, and thequery_param()pattern used to carryqsilently is already established elsewhere in the codebase — see Context above.)
🔔 Stakeholders @cdrini — search/advanced-search area lead per the related open issue #2673, and per the stakeholder area list (solr, search).
Full triage checklist
- [x] Triage — correct labels applied or removed
- [x] Problem / opportunity — problem is clear, audience identified, actionable
- [x] Scope — issue is well-scoped; does not try to do too many things
- [ ] Justification — reasoning given (patrons refining a search lose their state), but no measurable/quantified impact (usage data, affected traffic share) is provided
- [x] Success & testing criteria — defines what "done" looks like, verifiable by a contributor
- [x] Proposal & breakdown — concrete plan present; exact files/lines identified and the one open design question is resolved above
- [x] If bug: environment & repro steps — browser, version, local vs prod; steps to reproduce
- [x] Risks, concerns, open questions — identified and surfaced (and resolved, see Action items)
- [x] Richy context — relevant code, commits, PRs reviewed; no duplicate found
- [x] References — screenshots, designs, docs, and links present where needed
[!NOTE] This comment was automatically generated by Richy, Open Librarys issue enrichment assistant, on behalf of @mekarpeles. This is NOT a sign-off. This issue needs lead review before work begins.
@pnelson1337 i would like to work on this issue
Hi, I’d like to work on this.
I’ll reproduce the advanced search query/filter reset behavior locally and look for a focused fix that preserves the current query and selected filters.
Hi @pnelson1337 , I saw the issue and read your comment on @Utkarsh3725 PR's. The visible subject_field reads from subject_facet and the Templetor already auto-escapes. I will fix both of these bugs and then raise a PR.
@pnelson1337 Hi i am willing to work at this issue.