Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Fuse.js search format #2507

Merged
merged 23 commits into from
May 31, 2024
Merged

Add support for Fuse.js search format #2507

merged 23 commits into from
May 31, 2024

Conversation

SIGSTACKFAULT
Copy link
Contributor

@SIGSTACKFAULT SIGSTACKFAULT commented May 24, 2024

Sanity check:

  • Have you opened a thread on the forum? yes but nobody responded
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?
  • Are you doing the PR on the next branch?
  • Have you created/updated the relevant documentation page(s)?

the Fuse.js format looks like this (I'm working on Bevy's website:

[
  {
    "title": "2D",
    "body": "\n  TODO\n  \nExplain how 2D graphics in Bevy is actually 3D with a weird camera projection\nDefine the relevant abstractions\n\n\n\n",
    "path": "/learn/book/graphics/2d/"
  },
  {
    "title": "Sprite Sheets",
    "body": "\n  TODO\n  \nDemonstrate how to import and use a sprite sheet for basic animations\n\n\n\n",
    "path": "/learn/book/graphics/2d/sprite-sheets/"
  },
  {
    "title": "Sprites",
    "body": "\n  TODO\n  \nDemonstrate how to import and use a sprite\n\n\n\n",
    "path": "/learn/book/graphics/2d/sprites/"
  }
]

it happens to also be compatible with tinysearch, and almost compatible with stork.

components/search/src/fuse.rs Outdated Show resolved Hide resolved
components/search/Cargo.toml Outdated Show resolved Hide resolved
components/site/src/lib.rs Outdated Show resolved Hide resolved
components/site/src/lib.rs Outdated Show resolved Hide resolved
match self.config.search.index_format {
IndexFormat::ElasticlunrJson | IndexFormat::FuseJson => content,
IndexFormat::ElasticlunrJavascript | IndexFormat::FuseJavascript => {
format!("window.searchIndex = {}", content)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can probably go on the enum as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

of course it could, but I feel like it would be a weird thing to do? completely subjective.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

like at that point i might as well put the entire thing inside IndexFormat

@Keats
Copy link
Collaborator

Keats commented May 24, 2024

Sorry I've seen the message but didn't get to respond yet.

@SIGSTACKFAULT
Copy link
Contributor Author

bump @Keats because i replied to some of your reviews with followups

### Fuse

Compatible with [fuse.js](https://www.fusejs.io/), [tinysearch](https://github.com/tinysearch/tinysearch), and almost
compatible with [stork](https://stork-search.net/)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does it mean "almost compatible"? Does it work with stork or not?

Copy link
Contributor Author

@SIGSTACKFAULT SIGSTACKFAULT May 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stork's format is very similar but the keys are slightly different, it's toml, and it wants a bit of a extra metadata. One could conceivably convert fuse_json to stork with a shell script and a copy of jq

I should probably either write all that in the docs or remove the reference entirely

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually maybe i should have fuse_json have a url key instead of path, since fuse doesn't care and that will be more compatible with stork and tiny.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oooh wait i see why include_path exists

@Keats Keats merged commit 8c56a0e into getzola:next May 31, 2024
5 checks passed
@Keats
Copy link
Collaborator

Keats commented May 31, 2024

Thanks!

@Keats
Copy link
Collaborator

Keats commented May 31, 2024

Note: I haven't tried it myself but I assume you did right?

@SIGSTACKFAULT
Copy link
Contributor Author

SIGSTACKFAULT commented May 31, 2024

@Keats yeah i have a branch of bevy-website working using this. When will it ship?

@Keats
Copy link
Collaborator

Keats commented Jun 3, 2024

I need to have a look at all PRs and issues but i hope this week or the next one

Keats pushed a commit that referenced this pull request Jun 20, 2024
* inital "just barely works" Fuse.js support

* implement FuseJavascript; refactor index_for_lang

* support search config

* move fuse index building to it's own file

* update doc of Search.index_format

* update config docs

* update search documentation

* use &str where possible

* use libs::serde_json

remmeber to commit Cargo.lock

* move extension logic to IndexFormat

* move the entire filename logic inside IndexFormat

* move elasticlunr to it's own module

* only create elasticlunr.min.js if we're actually using elasticlunr

* move ELASTICLUNR_JS to elasticlunr.js

* hide the details of search's submodules

* optionally include path

* explain include_path better

* remove references to stork

* replace if with match

* support include_description

* specify "permalink"

* move body cleaning and truncation to a function

* update truncate_content_length docs to specify *code points*
@Jieiku
Copy link
Contributor

Jieiku commented Aug 7, 2024

Just wanted to add that the fuse_json index format helped with implementing pagefind in abridge, here is the demo: https://abridge-pagefind.pages.dev/

I planned to update tinysearch in abridge to use fuse_json, but a while ago I ran into an issue that I have not been able to figure out: tinysearch/tinysearch#175

berdandy pushed a commit to berdandy/azola that referenced this pull request Sep 17, 2024
* inital "just barely works" Fuse.js support

* implement FuseJavascript; refactor index_for_lang

* support search config

* move fuse index building to it's own file

* update doc of Search.index_format

* update config docs

* update search documentation

* use &str where possible

* use libs::serde_json

remmeber to commit Cargo.lock

* move extension logic to IndexFormat

* move the entire filename logic inside IndexFormat

* move elasticlunr to it's own module

* only create elasticlunr.min.js if we're actually using elasticlunr

* move ELASTICLUNR_JS to elasticlunr.js

* hide the details of search's submodules

* optionally include path

* explain include_path better

* remove references to stork

* replace if with match

* support include_description

* specify "permalink"

* move body cleaning and truncation to a function

* update truncate_content_length docs to specify *code points*
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.

3 participants