openlibrary icon indicating copy to clipboard operation
openlibrary copied to clipboard

Unify search algorithm for series

Open IvanPisquiy06 opened this issue 8 months ago • 1 comments

Description, Patron Story

What is the algorithmic change? We are unifying the search autocomplete algorithm used on the Lists and Series edit pages with the primary search algorithm used by the main search box (search.json).

Why is this change necessary? Currently, the autocomplete on the edit pages yields subpar results because it uses an older/different algorithm. Since the new Series feature (and Lists) relies heavily on this UI for curators to add works, inaccurate search results make list-building frustrating and difficult.

Who is it for? Librarians, super-librarians, and everyday patrons who curate Lists and Series.

Constraints or considerations? We must preserve the existing fallback behavior in direct_get that handles the edge case where a newly created Work ID has not yet been indexed by Solr.

Relevant Architecture

The goal is to extract the Solr request execution out of the base autocomplete class and override it in the works_autocomplete subclass.

  • Base Endpoint: openlibrary/plugins/worksearch/autocomplete.py (Specifically extracting the Solr logic into a new method like make_solr_request that direct_get can call).
  • Target Algorithm: The query builder logic found in openlibrary/plugins/worksearch/code.py (the same one search.json uses).
Implementation & Decision Details

Decisions

Based on the current architecture, the refactor will focus on unifying the autocomplete algorithms while preserving necessary fallback behavior:

  • Extract Solr Logic: Refactor the base autocomplete class to separate the Solr query execution from the initial request handling (direct_get). This logic will be moved into a dedicated method (e.g., make_solr_request).

  • Subclass Override: Within the works_autocomplete subclass, override this newly created method.

  • Unify the Algorithm: Update the overridden method to construct its Solr queries using the exact same query-building algorithm that powers the main search.json endpoint.

  • Preserve Fallbacks: Ensure the existing logic within direct_get remains untouched so the system can still gracefully handle specific Work IDs that have recently been added but not yet indexed by Solr.

Stakeholders

cc @cdrini

IvanPisquiy06 avatar Mar 12 '26 05:03 IvanPisquiy06

Hi, @cdrini ! I would like this issue to be assigned to me as discussed on the slack channel. Let me know if the issue was created correctly and any feedback or additional info that needs to be in there would be appreciated as well! c:

IvanPisquiy06 avatar Mar 12 '26 05:03 IvanPisquiy06