helsingborg-stad/algolia-index

将wordpress网站内容索引到algolia。


README

管理algolia索引(具有ms支持和混合索引)。此插件旨在由开发人员使用。此插件提供以下功能集

  • 用algolia替换前端上的algolia搜索。
  • 在文章更新或创建时索引所有公共可搜索的文章。
  • 使用WpCLI作业批量索引网站上的所有文章。
  • 支持混合索引(同一索引中的多个wordpress站点)。
  • 大记录分割(内容字段)。
  • 在查询algolia之前执行“需要更新”检查,以节省昂贵的更新。此功能不适用于分割记录。

安装

  1. 使用: "composer require helsingborg-stad/algolia-index" 安装
  2. 在插件内部运行composer install
  3. 添加必要的常量定义。
  4. 运行wp-cli作业 "wp algolia-index build"

常量

  • define('ALGOLIAINDEX_APPLICATION_ID', 'ALGOLIAAPPID'); - 必需
  • define('ALGOLIAINDEX_API_KEY', 'ALGOLIAAPIKEY'); - 必需
  • define('ALGOLIAINDEX_INDEX_NAME', 'INDEX'); - 可选
  • define('ALGOLIAINDEX_PUBLIC_API_KEY', 'INDEX'); - 可选,由js搜索页面插件要求

过滤器

  • AlgoliaIndex/ShouldIndex: 向应索引函数添加更多规则(不可删除)。
  • AlgoliaIndex/Record: 向algolia发送哪些数据。
  • AlgoliaIndex/Compare: 比较哪些字段以确定文章是否已更新。
  • AlgoliaIndex/SearchableAttributes: 记录中哪些属性可搜索。
  • AlgoliaIndex/GeneratedIndexName: 过滤自动生成的索引名称。
  • AlgoliaIndex/RecordToLarge: 通过返回false关闭记录过大报告。用于禁用记录分割。仅兼容企业计划,不推荐!
  • AlgoliaIndex/IndexablePostTypes: 要索引哪些文章类型。
  • AlgoliaIndex/HitsPerPage: 每页的命中数。
  • AlgoliaIndex/AttributesToSnippet: 要片段的属性。
  • AlgoliaIndex/SnippetEllipsisText: 片段的后缀。
  • AlgoliaIndex/BackendSearchActive: 发送false以禁用后端搜索。
  • AlgoliaIndex/IndexablePostStatuses: 允许索引哪些文章状态。

操作

  • AlgoliaIndex/IndexPostId: 触发特定文章ID的重新索引。
  • AlgoliaIndex/SendSettings: 发送设置。

WP CLI

  • wp algolia-index build: 索引网站上的所有页面/文章。

WP CLI参数

  • 在构建前清除index*,请添加标志 --clearindex=true。
  • 在构建前发送所需的搜索配置,请添加标志 --settings=true。

示例

wp site list --field=url --public=1 --archived=0 --deleted=0 --allow-root | xargs -n1 -I % wp algolia-index build --settings=true --url=% --allow-root

  • 此操作与一个共享索引中的多个站点不完全兼容!共享同一索引的站点将被清除但不会重新索引。