internetarchive / internetarchive/openlibrary

Unify search algorithm for series

Open
#12,079 1 comment 0 reactions 1 assignee Claimed by @IvanPisquiy06 View on GitHub
Lead: @cdrini Needs: Review Assignee Priority: 3 Theme: Design Type: Feature Request
Dominant language
Python
Stars
6.7k
Forks
2k
Avg merge
2d 19h
Merged PRs (30d)
138

Description

## 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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.