示例与扩展
非官方测试版翻译
本页面由 PageTurner AI 翻译(测试版)。未经项目官方认可。 发现错误? 报告问题 →
这些示例支持交互操作。点击按钮打开搜索模态框并尝试输入查询。
基本关键词搜索
使用默认配置搭配您的索引凭证即可。适用于典型文档站点、博客以及任何符合 DocSearch 索引规范的网站。
<DocSearch
appId="PMZUYBQDAK"
apiKey="24b09689d5b4223813d9b8e48563c8f6"
indexName="docsearch"
insights={true}
translations={{ button: { buttonText: 'keyword search (demo)' } }}
/>
Ask AI:AI 辅助回答
添加 Algolia AskAI 可获取基于索引内容生成的综合答案。通过 searchParameters 中的 facetFilters、filters、attributesToRetrieve、restrictSearchableAttributes 和 distinct 参数限定 LLM 上下文范围。
<DocSearch
appId="PMZUYBQDAK"
apiKey="24b09689d5b4223813d9b8e48563c8f6"
indexName="docsearch"
askAi={{
assistantId: 'askAIDemo',
searchParameters: {
facetFilters: ['language:en'],
},
}}
insights={true}
translations={{ button: { buttonText: 'search with askai (demo)' } }}
/>
侧边栏:持久化 AI 聊天
侧边栏提供固定在页面边缘的持久化聊天界面,特别适合文档类网站——用户可在不离开当前浏览位置的情况下进行追问。点击屏幕右下角的按钮即可体验演示功能。
<DocSearchSidepanel
appId="PMZUYBQDAK"
apiKey="24b09689d5b4223813d9b8e48563c8f6"
indexName="docsearch"
assistantId="askAIDemo"
/>
组合式 API:DocSearchButton + DocSearchModal
通过组合式 API 可将按钮与模态框作为独立组件渲染。您可精确控制各组件的渲染位置以及模态框代码的加载时机。
import { DocSearch } from '@docsearch/core';
import { DocSearchButton, DocSearchModal } from '@docsearch/modal';
import '@docsearch/css/style.css';
<DocSearch>
<DocSearchButton translations={{ buttonText: 'Composable search (demo)' }} />
<DocSearchModal
appId="PMZUYBQDAK"
indexName="docsearch"
apiKey="a00716d83c64f6c61905c078b7d5ab66"
askAi={{
assistantId: 'ccdec697-e3fe-465b-a1c3-657e7bf18aef',
agentStudio: true,
}}
/>
</DocSearch>;