8000 Show indexed Commons files as images in standard search, from the index alone by daoudclarke · Pull Request #650 · mwmbl/mwmbl · GitHub
[go: up one dir, main page]

Skip to content

Show indexed Commons files as images in standard search, from the index alone - #650

Open
daoudclarke wants to merge 2 commits into
mainfrom
seed-images-display-slim
Open

daoudclarke wants to merge 2 commits into
mainfrom
seed-images-display-slim

Conversation

@daoudclarke
@daoudclarke daoudclarke commented Nov 12, 2026 •
Copy link
Copy Markdown
Contributor

From Claude:

What changed

A result whose source is a DocumentSource.COMMONS_* member (set by the indexing PR A; the enum is from #648) now has a nullable image object in /api/v2/search/ and Combined Search web results: thumbnail_url, license_name, license_url, page_url (the file page, which names the author). Every other hit has image: null. No width or height: the front end uses a fixed box. Additive and backwards compatible; v1 and the HTML search page are unchanged.

  • mwmbl/imagesearch/display.py derives everything from the Document alone: the licence from source (LICENCE_NAMES_AND_URLS), the file name from the URL (commons_file_key), and the thumbnail URL from the name: https://upload.wikimedia.org/wikipedia/commons/thumb/{h[0]}/{h[:2]}/{name}/330px-{name}, h = md5(name). SVGs get .png appended. Names over 160 bytes use 330px-thumbnail.{ext} (found from the data, see below). Formats we cannot derive confidently (tif, pdf, djvu, video, long SVG names) get image: null and stay plain text results.
  • The hot path is an int-in-dict check on source; md5 and URL parsing run only for Commons results.
  • API descriptions (v2 and Combined Search): what engine commons means, that safety is an LLM reading the file's text only (no pixel check), load thumbnails with referrerpolicy="no-referrer", show the licence and file-page link with the image, escape text, link license_url with rel="noopener noreferrer nofollow".
  • Crawled Commons File pages (source None) and Staan results (source STAAN/STAAN_INDEXED) for Commons URLs stay plain text with no image.

Why

Issue #610. This replaces #637 8000 , whose design read Postgres on every search. Here standard search reads nothing and makes no request: the result is a pure function of the indexed Document. Tested with django_assert_num_queries(0).

It shows nothing until PR A's indexing is switched on (no document has a Commons source before then). A front-end PR is needed to render the thumbnails.

Verification

  • Thumbnail derivation checked against the real thumbnail_url of every Commons file in the Seed Search candidates (devdata/seed_images/candidates): 16,570 distinct files. 16,167 have a /thumb/ path, and all 16,167 (100%) match on directory, escaped name and thumb file name (everything but the width). The first pass matched 98.7%; the misses were all names over 160 bytes, which Commons names thumbnail.{ext} (lower-cased).
  • The other 403 (2.4%) are files narrower than the thumbnail, for which Commons returns the original rather than a thumb path. Our URL for these will likely not load, so the API description tells clients to hide the image if it fails to load.
  • Tests: thumbnail derivation (jpg, png, jpeg, webp, svg, non-ASCII, brackets, long names, unsupported formats), v2 schema with Commons and normal documents, crawled page with no source, Staan source, Combined Search web result, zero queries.
  • make check passes. The changed areas pass (98 tests: thumbnails, format, Combined Search, OpenAPI). The full make test could not finish here because several concurrent sessions were sharing the one test database and Redis; CI is the full gate.

Review (code, security, trust and safety, holistic)

Fixed: a stemless name such as File:Png no longer gets a thumbnail; API docs now say commons results of unsupported formats have image: null; a test needed the DB mark. Checked: nothing but PR A's indexing can set a COMMONS_* source (crawled documents have none, Staan sets STAAN), so a crawler or Staan cannot get an image shown; no XSS surface added (image fields are constants or a quoted name). Left for decision: the browser loads thumbnails from upload.wikimedia.org, so Wikimedia sees the viewer's IP (the front end should say so).

Part of #610

🤖 Generated with Claude Code

daoudclarke and others added 2 commits November 12, 2026 13:08
…ex alone

A document whose source is a COMMONS_* member gets a nullable image object in the
v2 and Combined Search results: a thumbnail URL derived from the file name, the
licence from the source, and the file page. No database read, no request.

No functional changes to the crawler.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…DB mark on test

No functional changes to the crawler.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov
codecov Bot commented Nov 12, 2026
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0