pantheon-systems/search_api_pantheon 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

pantheon-systems/search_api_pantheon

Composer 安装命令:

composer require pantheon-systems/search_api_pantheon

包简介

Connection module for Pantheon Search

README 文档

README

Search API Pantheon Actively Maintained

Table of Contents

Overview

This module provides Drupal 10+ integration with Apache Solr (versions 8 and 9) on Pantheon's Platform, simplifying the usage of Search API and Search API Solr.

Search API Solr provides the ability to connect to any Solr server by providing numerous configuration options. This module automatically sets the Solr connection options by extending the plugin from Search API Solr. The module also changes its connection information based on different Pantheon environments and each Pantheon Environment has its own Solr Core. Doing so eliminates the need to do extra work setting up Solr servers for each environment.

Solr Versions on Pantheon

Requirements

  • Drupal 10 or 11
  • PHP 8.1 or later (tested through PHP 8.5)
  • Search API Solr 4.3.x
  • Hosting on Pantheon's platform
  • Composer-based workflow using one of the following:
    • Pantheon's integrated composer (build step: true in your pantheon.yml)
    • A CI/CD service (e.g., GitHub Actions, CircleCI)
  • Dashboard access to the platform (necessary to deploy code changes)

Installation

Stable Release

composer require 'drupal/search_api_pantheon:^8'

Development Version

composer require 'drupal/search_api_pantheon:8.5.x-dev@dev'

Upgrading

Upgrading from an earlier version? See UPGRADE.md for detailed migration guides:

Setup

Enable Solr on Pantheon

Under "Settings" in your Pantheon site dashboard, enable Solr as an add on. This feature is available for sandbox sites as well as paid plans at the Professional level and above.

Configure pantheon.yml

Add or update the following in your pantheon.yml file:

search:
  version: 9

Or, to use Solr 8:

search:
  version: 8

As you deploy code, the pantheon.yml file will follow the code through environments enabling the Solr server. However you will need to create an index for each environment and ensure the content is indexed after creation. Solr indices are environment-specific and cannot be exported or moved once created.

Enable the Modules

  • Go to admin/modules and enable "Search API Pantheon."
  • Doing so will also enable Search API and Search API Solr if they are not already enabled.

OPTIONAL: Disable Drupal Core's search module

If you are using Search API, you probably will not be using Drupal Core's Search module. Uninstall it to save some confusion in the further configuration steps: admin/modules/uninstall.

Verify Installation

  • Navigate in the Drupal interface to CONFIG => SEARCH & METADATA => SEARCH API
  • Validate that the PANTHEON SEARCH server and Primary Index exist and are "enabled".

Use the Server with an Index

When you enable the Search API Pantheon module, a Primary index is automatically created and linked to the Pantheon search server. You can use this default index or create your own custom index.

To use the default 'Primary' index:

  • Go to admin/config/search/search-api and select the "Primary" index
  • Configure fields to be indexed by selecting the "Fields" tab
  • Add fields you want to search (e.g., "Title", "Body", etc.)
  • Click "Save" to save your field configuration
  • Post the schema (see Schema Updates below)
  • Click "Index now" to populate the index with your content. Alternatively, content will be indexed automatically when cron runs.

To create a custom index:

  • Go to admin/config/search/search-api/add-index
  • Name your index and choose a data source. If this is your first time using Search API, start by selecting "Content" as a data source. That option will index the articles, basic pages, and other node types you have configured.
  • Select "Pantheon Search" as the server
  • Save the index
  • Configure fields to be searched by selecting the "Fields" tab. You may want to index many fields. "Title" is a good field to start with.
  • Click "Save" to save your field configuration
  • Post the schema (see Schema Updates below)
  • Click "Index now" to populate the index with your content. Alternatively, content will be indexed automatically when cron runs.

Search the Index

  • Create a new view using the search index of type 'Index'.
  • Add fields to be included in the search results. Include the 'relevance' field to enable sorting by relevance.
  • Expose the search keywords filter to allow users to enter search terms.
  • Sort results by the "relevance" field. Solr assigns higher relevance ratings to documents that better match the search terms.

Export Your Changes

It is a best practice in Drupal to export your changes to yml files. Using Terminus while in SFTP mode, you can run terminus drush <site>.<env> -- "config:export -y" to export the configuration changes you have made. Once committed, these changes can be deployed out to Test and Live environments.

Schema Updates

The default schema Pantheon provisions with a new Solr container depends on the Solr version:

  • Solr 9: The 4.3.10 version of the Solr 9 jump-start config-set from Search API Solr module
  • Solr 8: The 4.2.1 version of the Solr 8 jump-start config-set from Search API Solr module

When you first create your index or alter it significantly, you will need to update the schema on the Solr server.

Running with an outdated schema can cause broken search, indexing errors, and missing features such as highlighting or autocomplete. Specifically, you should update the schema:

  • After initial module installation
  • After adding new Solr field types (e.g., custom analyzers or tokenizers) that are not already defined in the schema
  • After upgrading search_api_solr to a version that changes the generated schema (e.g., 4.2.x → 4.3.x)
  • After switching Solr versions (8 ↔ 9) — see UPGRADE.md
  • After enabling or disabling Search API Solr sub-modules (e.g., multilingual, autocomplete)

Schema updates can be performed using:

terminus drush <site>.<env> -- search-api-pantheon:postSchema [path]

The [path] argument is optional. Provide it only if you want to use a custom config-set directory. If omitted, the module uses Search API Solr to generate config files that match your installed module version and Solr version.

Once you have enabled the Search API Pantheon module, when you reload the schema the module will use the config-set for the version of the Search API Solr module installed in your codebase. See the Search API Solr 4.3.0 release notes for more information about upgrading to a 4.3.0+ compatible schema.

Examples

Auto-generated config: Generates schema files based on your Solr version, Search API Solr version, and index configuration.

terminus drush <site>.<env> -- search-api-pantheon:postSchema

Jump-start config-set from Search API Solr: Uses the pre-built config-set bundled with the Search API Solr module. Useful if you want a known baseline without any site-specific customizations.

terminus drush <site>.<env> -- search-api-pantheon:postSchema /code/web/modules/contrib/search_api_solr/jump-start/solr9/config-set/
terminus drush <site>.<env> -- search-api-pantheon:postSchema /code/web/modules/contrib/search_api_solr/jump-start/solr8/config-set/

Custom config-set directory: Uses your own schema files. For advanced use cases where you need custom analyzers, tokenizers, or field types beyond what the module generates.

terminus drush <site>.<env> -- search-api-pantheon:postSchema /code/solr/config

For more details on using custom Solr configurations, see Pantheon's custom config guide.

Core Reloading

Automatic Core Reload

Search API Pantheon automatically reloads the Solr core after schema updates to prevent schema reversions and maintain index integrity.

Manual Core Reload

If needed, manually reload the core using:

terminus drush <site>.<env> -- search-api-solr:reload

Pantheon Environments

Each Pantheon environment (Dev, Test, Live, and Multidevs) has its own Solr server. Indexing and searching in one environment does not impact any other environment.

When you enable the Search API Pantheon module, 'Pantheon Search' server is automatically installed by default. The Pantheon connector supports only a single Search API server per environment. Creating additional servers using the Pantheon connector will cause all servers to point to the same Solr core, which may result in schema conflicts or unexpected indexing behavior.

Diagnostic Commands

Diagnostic commands automatically use the first server connected via Pantheon connector. The server_id argument is no longer needed or accepted.

Command Alias Arguments Description
drush search-api-pantheon:diagnose sapd None Checks the various pieces of the Search API install and throws errors on pieces that are not working.
drush search-api-pantheon:select saps <query> (required) Runs the given query against Solr server. Use ?debug=true in any Solr page to get a good query to pass to this command.
drush search-api-pantheon:force-cleanup sapfc None Deletes all of the contents for the Solr server (no matter if hash or index_id have changed).
drush search-api-pantheon:postSchema sapps [path] (optional) Uploads schema files to the solr server. Can reset a schema to default, upgrade a schema, or use a custom config set.
drush search-api-pantheon:test-index-and-query sap-tiq None Connects to the search server, indexes a single item, and immediately queries it.

Troubleshooting

Common Issues

Issue Solution
Schema reverts unexpectedly Ensure core reload is happening after updates
Search index corruption Try reposting schema and reindexing content
Core reload failures Check Solr logs and connection status
Error after Search API Solr upgrade Schema incompatibility from 4.2.x → 4.3.x. See UPGRADE.md

Solr Jargon

Term Definition
Commit To make document changes permanent in the index.
Core An instance of the Solr server suitable for creating zero or more indices.
Collection Solr Cloud's version of a "CORE". Not currently used at Pantheon.
Document A group of fields and their values. The basic unit of data in a collection.
Facet The arrangement of search results into categories based on indexed terms.
Field The content to be indexed/searched along with metadata.
Index A group of metadata entries gathered by Solr into a searchable catalog.
Schema A series of plain text and XML files that describe the data Solr will be indexing.

Feedback and Collaboration

Bug reports, feature requests, and feedback should be posted in the drupal.org issue queue. For code changes, please submit pull requests against the GitHub repository.

pantheon-systems/search_api_pantheon 适用场景与选型建议

pantheon-systems/search_api_pantheon 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 828.08k 次下载、GitHub Stars 达 11, 最近一次更新时间为 2021 年 08 月 03 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 pantheon-systems/search_api_pantheon 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 pantheon-systems/search_api_pantheon 我们能提供哪些服务?
定制开发 / 二次开发

基于 pantheon-systems/search_api_pantheon 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 828.08k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 11
  • 点击次数: 17
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 11
  • Watchers: 7
  • Forks: 28
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0-or-later
  • 更新时间: 2021-08-03