34个版本 (7个破坏性)
0.7.3 | 2022年10月24日 |
---|---|
0.6.2 | 2022年10月8日 |
0.2.1 | 2022年7月24日 |
0.0.11 | 2022年1月5日 |
0.0.6 | 2021年12月30日 |
#373 in WebAssembly
每月 37 次下载
用于 5 个Crates (4个直接)
29KB
597 行
Morsels
为静态站点提供简单、相关且高效的客户端搜索。
描述
Morsels是一个针对静态站点的客户端搜索解决方案,依赖于由CLI工具生成的预构建索引。
这个领域的一些类似工具有 Stork 和 TinySearch。Morsels做的是同样的事情,但更注重提供更丰富和相关的搜索体验,同时对于常见用例(例如单域静态站点)来说更容易上手。

功能
- 功能丰富、相关搜索 🔍:拼写纠正、自动前缀搜索、布尔和短语查询、BM25评分、邻近度评分、持久缓存等。
- WebAssembly & WebWorker 驱动,实现高效、非阻塞的查询处理
- 多线程 CLI索引器由Rust提供支持
- 半可扩展,通过可选地将索引分割成微小的碎片来实现,并配备增量索引。
- 一个 可定制、可访问 用户界面 🖥️
- 支持 多种文件格式 (
.json,csv,pdf,html
),以满足更多定制数据需求。
入门指南
使用Morsels为静态站点提供搜索功能非常简单,只需一个包含您的HTML文件的文件夹 — 标题、标题和其他文本将被自动提取。根据您的文件夹结构自动生成页面链接,但也可以手动指定。
1. 安装索引器
如果您已设置rust / cargo工具链,只需运行 cargo install morsels_indexer --vers 0.7.3
。
或者,从这里下载cli二进制文件 这里。
2. 运行索引器
按照以下方式运行可执行文件,将 <source-folder-path>
替换为您源 HTML 文件的相对或绝对文件夹路径,将 <output-folder-path>
替换为您希望输出的索引文件夹。
morsels <source-folder-path> <output-folder-path>
3. 通过 CDN 安装搜索 UI
将以下资源添加到您的页面中
<!-- Search UI script -->
<script src="https://cdn.jsdelivr.net.cn/gh/ang-zeyu/[email protected]/packages/search-ui/dist/search-ui.ascii.bundle.js"></script>
<!-- Search UI css, this provides some basic styling for the search dropdown, and can be omitted if desired -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net.cn/gh/ang-zeyu/[email protected]/packages/search-ui/dist/search-ui-light.css" />
如果您希望托管文件,可以在索引器生成的 <output-folder-path>/assets
目录中找到它们,或在 发布页面 中。
4. UI 初始化
给您的页面中的任何 <input>
元素一个 id
为 morsels-search
,然后调用
morsels.initMorsels({
searcherOptions: {
// Output folder URL specified as the second parameter in the cli command
// URLs like '/output/' will work as well
url: 'http://<your-domain>/output/',
},
uiOptions: {
// Input folder URL specified as the first parameter in the cli command
// This is where the generated result preview links will point to,
// and where you host your site.
sourceFilesUrl: 'http://<your-domain>/source/',
}
});
文档
用户指南,它也使用 Morsels 作为其搜索功能,可以在 这里 找到。
还可以在这里查看网站 这里!
许可
本项目采用 MIT 许可。
依赖
~215–420KB