openlibrary icon indicating copy to clipboard operation
openlibrary copied to clipboard

Advanced Search discards the current query and any selected filters

Open pnelson1337 opened this issue 3 months ago • 5 comments

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

  1. Go to https://openlibrary.org/search?q=quantum+entanglement&subject_facet=Physics
  2. 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 bare href="/advancedsearch".
  • openlibrary/templates/search/advancedsearch.html — no value= 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.

pnelson1337 avatar Aug 28 '26 02:08 pnelson1337

Thank you @pnelson1337 for submitting this issue!

Contributors, this issue will be ready to work on once:

  • [ ] Triage — maintainers will add Priority: * and Lead: @*

Context

  • The nav tab confirmed at openlibrary/macros/SearchNavigation.html#L26-L28 — the "Advanced Search" <li> is a bare href="/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) calls render_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-L20 confirms none of the title/author/isbn/subject/place/person/publisher inputs have value=, and the existing <input type="hidden" name="q" id="qtop"> (line 10) has no value bound either — its presence suggests carrying q silently was already the intent, just never wired up.
  • On the reporters open question of whether to carry q or just the facets: query_param() (from infogami.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)) and openlibrary/templates/subjects.html#L7. This means the fix likely does not require touching advancedsearch.GET at all — advancedsearch.html can call query_param(...) directly per field, the same way SearchNavigation.html already does for q.
  • 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 q field be carried through, or only the visible facet fields? (Answer: Both. The hidden qtop input already exists in the template for exactly this purpose, and the query_param() pattern used to carry q silently 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.

openlibrary-bot avatar Aug 28 '26 02:08 openlibrary-bot

@pnelson1337 i would like to work on this issue

Adityakumar37 avatar Aug 29 '26 06:08 Adityakumar37

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.

Utkarsh3725 avatar Aug 29 '26 12:08 Utkarsh3725

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.

Ved-sketch avatar Sep 09 '26 08:09 Ved-sketch

@pnelson1337 Hi i am willing to work at this issue.

AHmedshehab2 avatar Oct 10 '26 02:10 AHmedshehab2