CloudCannon / pagefind

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

Multiple Site Indexing and Cross-site search. #17

Closed bwklein closed 2 years ago

bwklein commented 2 years ago

We have 3 different domains build with different SSG tools. We would like to be able to search on any of the sites and return the best results from any of the others. It would be nice if there was a way for the client side JS lib to have more than one index file to consider when finding hits.

bglw commented 2 years ago

Great call, we actually need to implement this for the CloudCannon marketing stack as well — under the hood our docs, blog, marketing, changelog and community sections are all distinct sites 😅

A basic example would look something like:

new PagefindUI({
    element: "#search",
    baseUrl: "/",
    merge_index: [
        "/_pagefind/",
        "/blog/_pagefind/",
        "/docs/_pagefind/",
        "https://example.com/_pagefind/", // Assuming this URL has CORS enabled
    ]
});

Still a little discovery work to do — are there any features you would like integrated into this? For instance, with the above setup you could filter by site if you added a distinct data-pagefind-filter to each of your sites, but this could be made easier if we expanded the config to something like:

new PagefindUI({
    element: "#search",
    baseUrl: "/",
    merge_index: [
        {
            bundle: "/_pagefind/",
            filters: {
                site: "Main"
            }
        },
        {
            bundle: "/blog/_pagefind/",
            filters: {
                site: "Blog"
            }
        },
        {
            bundle: "/docs/_pagefind/",
            filters: {
                site: "Docs"
            }
        },
        {
            bundle: "https://example.com/_pagefind/", // Assuming this URL has CORS enabled
            filters: {
                site: "External"
            }
        },
    ]
});

Allowing you to merge in filters & metadata at this level, which seems like a better idea.

Keen to hear if you have any other thoughts for how this should be implemented! I'll be looking at tackling this within the next fortnight

bwklein commented 2 years ago

This made me think of passing a bias or weighting factor per site we are searching from, so that you could prioritize hits on the site you are on, but still see hits from the others.

bglw commented 2 years ago

Good idea. I'll look at scoping that in :)

bglw commented 2 years ago

Hi @bwklein!

This is all released in v0.8.0 🎉 Including support for merging filters into each site, and a weighting factor per site 🙂

bwklein commented 2 years ago

Thank you @bglw !