rubix-studios-pty-ltd/payload-typesense

GitHub: rubix-studios-pty-ltd/payload-typesense

为 Payload CMS 提供 Typesense 搜索引擎集成的生产就绪插件,支持实时同步、拼写容错和可选的向量语义搜索。

Stars: 28 | Forks: 3

# PayloadCMS + Typesense 插件 Rubix Studios 为 Payload CMS 开发的 Typesense 集成专为生产环境的搜索工作流而构建,具有轻量级、模块化的结构,并可选支持诸如向量查询等高级功能。 该插件由 Rubix Studios 积极维护。 [![npm 版本](https://img.shields.io/npm/v/@rubixstudios/payload-typesense.svg)](https://www.npmjs.com/package/@rubixstudios/payload-typesense) ![发布](https://static.pigsec.cn/wp-content/uploads/repos/cas/42/42ba98a60a0bb3b0ad908f024db145f9c5b831eb7df822f56ac578ee7d7215b3.svg) ## 安装 ``` pnpm add @rubixstudios/payload-typesense ``` ``` // payload.config.ts import { buildConfig } from 'payload/config' import { typesenseSearch } from '@rubixstudios/payload-typesense' export default buildConfig({ plugins: [ typesenseSearch({ typesense: { apiKey: 'xyz', nodes: [ { host: 'localhost', port: 8108, protocol: 'http', }, ], }, collections: { posts: { enabled: true, searchFields: ['title', 'content'], facetFields: ['category', 'status'], displayName: 'Blog Posts', icon: '📝', syncLimit: 500, // Overrides the default sync limit of 1000 }, }, // This feature is experimental vectorSearch: { enabled: true, // Enables vector-based semantic search embedFrom: ['title', 'content'], // Omit to fall back to collection searchFields embeddingModel: 'azure/text-embedding-ada-002', modelConfig: { api_key: 'your-api-key', url: 'https://modelendpoint.com/openai', }, }), ], }) ``` ``` import { HeadlessSearchInput } from '@rubixstudios/payload-typesense' export function GlobalSearchPage() { return ( { console.log('Selected document:', result.document) }} /> ) } export function CollectionSearch() { return ( { console.log('Selected document:', result.document) }} /> ) } export function VectorSearch() { return ( { console.log('Selected document:', result.document) }} /> ) } ``` ## 功能 - **高性能** 通过优化的请求处理实现亚毫秒级的搜索响应。 - **灵活搜索** 使用单个组件即可实现单集合、多集合或全局搜索。 - **向量搜索** 使用 embedding 进行可选的语义搜索,并无缝回退至关键字搜索。 - **现代化 UI** 兼容 Tailwind CSS 的无头、响应式实现。 - **实时同步** 与 Payload CMS 持续进行索引和同步。 - **高效缓存** 带有可配置 TTL 和竞态条件保护机制的内存缓存。 - **生产就绪** 稳健的错误处理、部署安全的默认设置以及平台兼容性。 - **可 Tree-Shake 架构** 模块化设计,可生成更小的 bundle 并支持选择性使用功能。 ## 接口 - `GET /api/search` - 跨所有集合的全局搜索 - `GET /api/search/{collection}` - 搜索特定集合 - `POST /api/search/{collection}` - 带有过滤器的高级搜索 - `GET /api/search/{collection}/suggest` - 搜索建议 - `GET /api/search/collections` - 集合元数据 - `GET /api/search/health` - 健康检查 ## 组件 - **HeadlessSearchInput**:支持所有搜索模式的单个组件: - **集合**:`collections={['posts', 'products']}` - 支持全局搜索的智能过滤 - **全局搜索**:无需 collection 属性 - 跨所有集合进行搜索 - **完全的 UI 控制**:通过全面的主题系统实现可自定义渲染 ## 主题 该插件包含一个强大的主题系统,拥有 2 个预构建主题并支持无限的自定义: ### 预构建 ``` // Modern theme (default) // Dark theme ``` ### 自定义 ``` const customTheme = { theme: 'modern', colors: { inputBorderFocus: '#10b981', inputBackground: '#f0fdf4', resultsBackground: '#f0fdf4', }, spacing: { inputPadding: '1rem 1.25rem', inputBorderRadius: '1.5rem', }, enableAnimations: true, enableShadows: true, } ``` ### 主题特性 - **2 个预构建主题**:Modern、Dark - **无限自定义**:覆盖任何颜色、间距、排版或动画 - **性能选项**:禁用动画/阴影以获得更好的性能 - **响应式设计**:自动进行移动端优化 - **CSS 变量**:使用 CSS 自定义属性进行高级样式设计 - **TypeScript 支持**:为所有主题配置提供完整的类型安全 ## 生产环境 - **竞态条件保护**:`ensureCollection` 可防止启动时崩溃 - **类型安全**:正确的 Payload CMS 类型可防止运行时错误 - **文档验证**:在同步前过滤格式错误的数据 - **优雅降级**:静默失败不会中断 Payload 的操作 ## 开发者 - **更小的组件**:更易于理解和维护 - **可维护性**:严格遵循单一职责原则 - **完善的文档**:清晰的关注点分离 ## 许可证 该项目基于 MIT 许可证授权 - 详情请参阅 [LICENSE](LICENSE) 文件。 ## 支持 如需支持或咨询: - LinkedIn:[rubixvi](https://www.linkedin.com/in/rubixvi/) - 网站:[Rubix Studios](https://rubixstudios.com.au) ## 作者 Rubix Studios [https://rubixstudios.com.au](https://rubixstudios.com.au) ## 鸣谢 - [FrontTribe](https://github.com/FrontTribe/typesense-search)
标签:CMS插件, Payload CMS, Syscall, Typesense, Web开发, 搜索引擎, 数据同步, 自动化攻击