visuellverstehen / t3meilisearch
将 Meilisearch 作为搜索扩展。
Requires
- meilisearch/meilisearch-php: ^1.6
- spatie/pdf-to-text: ^1.52.1
- typo3/cms-core: ^10.4 || ^11.5 || ^12.4
This package is auto-updated.
Last update: 2024-09-07 09:03:28 UTC
README
准备
自行安装 Meilisearch 并确保其运行。同时确保您获取到服务器可访问的地址,因为您需要使用该地址配置扩展。否则,扩展无法与 Meilisearch 通信。
您还需要 poppler-utils
来索引 PDF 文件。
安装
您可以通过 Composer 轻松安装此扩展
composer require visuellverstehen/t3meilisearch
您可能需要在 TYPO3 10.4 中激活扩展,但自 TYPO3 11.5 起不再需要。
配置
以管理员或系统维护者的身份登录到 TYPO3,然后转到设置模块。通过设置以下字段来调整 t3meilisearch 的配置
主机
Meilisearch 服务器可访问的地址。可选地包括端口号。
示例
host=127.0.0.1:7700
API
用于验证请求的密钥
示例
apiKey=masterKey
目标页面 uid
主插件所在的页面的 uid(见 用法)。
示例
targetPid=56
索引
您可以通过替换 t3meilisearch 提供的默认值来定义自定义索引。
示例
index=content
就是这样。扩展将在页面和 PDF 缓存后索引它们。
用法
建议创建一个新页面,可以隐藏但不能禁用。插入插件”带有结果的搜索表单(Pi1)“。这将显示搜索表单以及如果有的话,结果。
您还可以使用”搜索表单(Pi2)“插件仅显示搜索表单,该表单将重定向到设置模块中配置的目标页面。您可以像这样将此插件硬编码到例如页脚中
<f:cObject typoscriptObjectPath="tt_content.list.20.t3meilisearch_pi2" />
解析内容
默认情况下,所有在 <body></body>
之间的事物都被索引。您可以通过使用两个 HTML 注释来限制这一点,就像 indexed_search 一样。如果您使用多个块,只有第一个将被索引。
<!-- INDEX_CONTENT_START --> <p>This content will be indexed</p> <!-- INDEX_CONTENT_STOP --> <p>This content will NOT be indexed</p>
覆盖模板
因为它是一个使用 Extbase 构建的基本 TYPO3 扩展,您可以轻松覆盖默认模板并使用自己的模板。首先,在您的 TypoScript 中配置一个额外的位置来查找模板和部分
plugin.tx_t3meilisearch {
view {
templateRootPaths {
5000 = EXT:custom_extension/Resources/Private/Templates/
}
partialRootPaths {
5000 = EXT:custom_extension/Resources/Private/Partials/
}
}
}
接下来,您可以按照您喜欢的样子复制和修改默认模板。重要的是要复制命名空间结构,否则 TYPO3 找不到模板和部分。
排除页面索引
在编辑页面时,您可以通过取消选中”包含在搜索中“复选框来防止页面被索引。
删除索引
想要从头开始?您可以简单地执行一个 HTTP 请求来删除索引
curl -H 'Authorization: Bearer yourApiKey' -X DELETE 'https://:7700/indexes/documents'
t3meilisearch 将根据配置在 $GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['t3meilisearch']['index']
中的名称创建一个新的索引。
删除特定文档
当存在旧的或不需要的结果时,您可以轻松通过执行 HTTP 请求来删除文档。首先通过 Meilisearch 仪表板搜索以找到文档的 id
。然后您可以执行以下请求来删除文档
curl -H 'Authorization: Bearer yourApiKey' -X DELETE 'https://:7700/indexes/documents/documents/:id'
添加排序选项
默认情况下,t3meilisearch 按 crdate(PDF 的文件时间)降序排序结果。您可以通过添加一个选择来添加简单的排序选项
<select name="sorting"> <option selected disabled>Sorting</option> <option value="crdate_desc" {f:if(condition: '{queryParams.sorting} === "crdate_desc" || !{queryParams.sorting}', then: 'selected')}>New first</option> <option value="crdate_asc" {f:if(condition: '{queryParams.sorting} === "crdate_asc"', then: 'selected')}>Old first</option> </select>
排序值必须通过名为sorting
的查询键传递。该值由column-to-sort_direction-to-sort
组成。如果您想进行更复杂的排序,您必须自己完成。
添加类型筛选
默认情况下,我们为文档添加了两种类型:page
用于普通页面内容,pdf
用于PDF文件。您可以自己索引记录并添加自定义类型。通过传递types
参数可以实现类型筛选。
<input class="filter__input" type="checkbox" id="type-page" name="types[]" value="page" {f:if(condition: '"page" == {type}', then: 'checked') -> f:for(each: '{queryParams.types}', as: 'type')}> <label class="filter__label" for="type-page">Allgemein</label>
Meilisearch提供了一个易于使用的API:docs.meilisearch.com