一键导入
drupal-search-api
Search API — index configuration, boost processors, field types, number field boosting, engagement metrics, and reindexing workflows.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Search API — index configuration, boost processors, field types, number field boosting, engagement metrics, and reindexing workflows.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
HTMX in Drupal 11.3+ core — the Htmx PHP fluent builder, dynamic forms with swapOob, partial routes with _htmx_route, response headers, and Drupal.behaviors integration. Use when building interactive UI without full-page reloads using Drupal's native HTMX support.
DDEV local development expertise. Use when working with DDEV projects, containers, configuration, or troubleshooting DDEV environments.
Custom Docker Compose local development patterns. Use when working with Docker-based local environments, container configuration, or troubleshooting Docker setups.
Drupal access control — permissions.yml, access callbacks, AccessResult, custom access checkers, and entity access.
Drupal Cache API — cache tags, contexts, max-age, cache bins, invalidation, and adding cache metadata to render arrays.
Drupal Composer management — requiring modules, updates, patches via composer-patches, and version constraints.
| name | drupal-search-api |
| description | Search API — index configuration, boost processors, field types, number field boosting, engagement metrics, and reindexing workflows. |
Boolean Fields for Boosting
type: boolean in index settingsfield_settings:
field_featured:
label: Featured
datasource_id: 'entity:node'
property_path: field_featured
type: boolean # NOT integer
boost: 8.0
Configuration Command
ddev drush config:set search_api.index.{index_name} \
field_settings.field_featured.type boolean
Flag Count Fields
type: integer for count fieldsflag_search_api modulefield_settings:
flag_bookmark_count:
label: 'Bookmark count'
property_path: flag_bookmark_count
type: integer
flag_favorite_count:
label: 'Favorite count'
property_path: flag_favorite_count
type: integer
When to Use
Pattern: FeaturedContentBoost.php — extends ProcessorPluginBase, stage preprocess_index
// Use #[SearchApiProcessor(...)] attribute (use Drupal\search_api\Attribute\SearchApiProcessor) — see README for full class
final class FeaturedContentBoost extends ProcessorPluginBase {
public function preprocessIndexItems(array $items) {
foreach ($items as $item) {
try {
$entity = $item->getOriginalObject()->getValue();
if ($entity->hasField('field_featured') &&
!$entity->get('field_featured')->isEmpty() &&
$entity->get('field_featured')->value == 1) {
$item->setBoost($item->getBoost() * 2.0);
}
}
catch (\Exception $e) {
continue;
}
}
}
}
Key Points
$item->setBoost($old_boost * boost_factor)search_api_boolean_field_boost modulepreprocess_index stageRecommended Boost Factors
2.0x (modest but effective)1.5x - 3.0x1.5x - 2.0xWhen to Use
Configuration Pattern
processor_settings:
number_field_boost:
weights:
preprocess_index: 0
boosts:
flag_bookmark_count:
boost_factor: 0.01
aggregation: max
flag_favorite_count:
boost_factor: 0.1
aggregation: max
How It Works
boost += (field_value * boost_factor)Configuration Commands
# Set bookmark count boost (0.01 per bookmark)
ddev drush config:set search_api.index.{index_name} \
processor_settings.number_field_boost.boosts.flag_bookmark_count.boost_factor 0.01
# Set favorite count boost (0.1 per favorite)
ddev drush config:set search_api.index.{index_name} \
processor_settings.number_field_boost.boosts.flag_favorite_count.boost_factor 0.1
Recommended Boost Factors
0.01 - 0.05 (for counts in 10-1000 range)0.1 - 0.5 (for counts in 1-50 range)0.001 - 0.01 (for counts in 100-10000 range)Problem: Multiple Processors on Same Field
If multiple processors target the same field, they can conflict:
Solution: Remove Conflicting Configuration
# Remove field from number_field_boost if using custom processor
ddev drush config:set search_api.index.{index_name} \
processor_settings.number_field_boost.boosts.field_featured null
Best Practice
When drush config:set fails or produces unexpected results (e.g., side effects on unrelated config), use PHP to directly update active configuration:
ddev drush php:eval "
\$config = \Drupal::configFactory()->getEditable('search_api.index.{index_name}');
// Set field type
\$config->set('field_settings.field_featured.type', 'boolean');
// Remove from number_field_boost
\$boosts = \$config->get('processor_settings.number_field_boost.boosts');
unset(\$boosts['field_featured']);
\$config->set('processor_settings.number_field_boost.boosts', \$boosts);
// Set boost factors
\$config->set('processor_settings.number_field_boost.boosts.flag_bookmark_count.boost_factor', 0.01);
\$config->set('processor_settings.number_field_boost.boosts.flag_favorite_count.boost_factor', 0.1);
\$config->save();
echo \"Configuration updated\n\";
"
When to Use PHP Instead of drush config:set:
server: {server_name} to server: null)null)After PHP Config Updates:
ddev drush config:get search_api.index.{index_name} field_settings.field_featuredddev drush config:export -ygit diff config/sync/Problem: When Solr server config is modified (e.g., pointing to a different backend), config export may downgrade custom field types to generic types:
# BEFORE (correct)
field_display_name:
type: 'solr_text_custom:ngramstring'
# AFTER export (incorrect)
field_display_name:
type: text
Solution: After exporting, restore custom field types via PHP:
ddev drush php:eval "
\$config = \Drupal::configFactory()->getEditable('search_api.index.{index_name}');
\$config->set('field_settings.field_display_name.type', 'solr_text_custom:ngramstring');
\$config->set('field_settings.label.type', 'solr_text_custom:ngramstring');
\$config->set('field_settings.name.type', 'solr_text_custom:ngramstring');
\$config->set('field_settings.title.type', 'solr_text_custom:ngramstring');
\$config->save();
"
ddev drush config:export -y
Fields Using ngram Tokenization:
field_display_name - Display names (partial matching for autocomplete)label - Entity labels/titlesname - User account namestitle - Node titlesNever change these to type: text - it breaks partial name matching (e.g., "mich" won't find "Michael").
When modifying Search API server config (e.g., for local development), Drupal may update index configs to remove server dependencies:
# Unintended change in search_api.index.{index_name}.yml
dependencies:
config:
- - search_api.server.{server_name} # Removed
server: null # Changed from {server_name}
Prevention:
search_api.server.{server_name}.yml for local developmentgit diff config/sync/ before committingRecovery:
# Revert index files if server was set to null
git checkout HEAD -- config/sync/search_api.index.*.yml
Always reindex after:
Reindex Commands
# Full reindex workflow
ddev drush cr
ddev drush search-api:clear {index_name}
ddev drush search-api:index {index_name}
# Check index status
ddev drush search-api:status {index_name}
# Check processor configuration
ddev drush config:get search_api.index.{index_name} processor_settings
# Check field configuration
ddev drush config:get search_api.index.{index_name} field_settings
# Verify index status
ddev drush search-api:status {index_name}
Boost not applying checklist: processor enabled → field type correct (boolean/integer) → full reindex completed → no conflicting processors → cache cleared.