CloudCannon / pagefind

Static low-bandwidth search at scale
https://pagefind.app
MIT License
3.22k stars 97 forks source link

Blank search #546

Open ColeDCrawford opened 5 months ago

ColeDCrawford commented 5 months ago

I have a page on which I'd like to use Pagefind as the primary way to interact with content. I would like to preload some content on that page, but without any search term. If I use the default UI it seems like Pagefind requires a search term to return any results; same with the Javascript API:

> const empty = await pagefind.search("");
> empty
{results: Array(0), unfilteredResultCount: 0, filters: {…}, totalFilters: {…}, timings: Array(1)}
> const a = await pagefind.search("a")
{results: Array(659), unfilteredResultCount: 659, filters: {…}, totalFilters: {…}, timings: Array(1)}

I'd like to be able to force a "blank" or "empty" search which would just return all the results until the user starts filtering or searching on them. As shown above, Pagefind seems to be returning nothing. Are blank searches currently possible, or possible to add?

bglw commented 5 months ago

Blank searches should be possible by passing null instead of ”” 🙂

ColeDCrawford commented 5 months ago

Nice, that worked great with the Pagefind search API. Is there a setting or equivalent way to do that with the Default UI component?

bglw commented 5 months ago

Not at the moment, no. Work is soon going into rounding out and releasing the modular-ui, which will include features like this.

ColeDCrawford commented 4 months ago

Thanks - is there a separate repo for the modular-ui? Just not sure how stable it is / when I should feel comfortable moving to that instead of the Default UI.

ColeDCrawford commented 1 month ago

@bglw it looks like in the v1.1.0 release there is a search.triggerSearch() method for the Default UI, but it looks like it doesn't work with null? Is it possible to get that updated to allow for a blank search?

jiggsfoo commented 2 weeks ago

@ColeDCrawford did you ever find a solution to this? I'm having the same issue.

ColeDCrawford commented 2 weeks ago

@ColeDCrawford did you ever find a solution to this? I'm having the same issue.

Not for the Default UI. I played around with customizing some of the components in the Modular UI but didn't get anything satisfactory working there either.

ColeDCrawford commented 1 week ago

@bglw if this could get into the next release that would be great ... I went down the path of trying to work with the Modular UI but encountered a number of other issues there.

bglw commented 1 week ago

Can do!