MuckRock / documentcloud-frontend

DocumentCloud's front end source code - Please report bugs, issues and feature requests to info@documentcloud.org
https://www.documentcloud.org
GNU Affero General Public License v3.0
15 stars 5 forks source link

Implement in-document search #556

Closed eyeseast closed 1 month ago

eyeseast commented 1 month ago

Before we can show search highlights (#501) we need to actually search.

The current site hits the single document search endpoint (https://www.documentcloud.org/help/search/#api) and then uses transformHighlights to prepare strings for rendering.

I wonder if we can do this all in the browser. Solr isn't doing much for us on a single document.

The built-in PDF.js viewer has a search utility. As far as I can tell, it's just doing a regex match, but that might actually be enough. My baseline here is cmd-F. If I do a plain in-browser text search, I'll see words highlighted. Whatever we build should be at least as good as that, and that's pretty good.

eyeseast commented 1 month ago

State management is going to be tricky here. We need to render text, then potentially add highlights if there's a query. If the query changes, we need to update it. Maybe that means we just re-render text.

eyeseast commented 1 month ago

We probably need to handle search highlighting separately in TextPage.svelte and PDFPage.svelte, since those handle page text in different ways.

eyeseast commented 1 month ago

Done (very basic) in #559