Facets
Provides faceted search interfaces for Drupal, allowing site builders to easily create and manage faceted navigation for Search API-based and core search displays.
facets
インストール
composer require 'drupal/facets:^3.0'
概要
Facetsモジュールは、コードを書かずに高度なファセット検索インターフェースを作成・管理することを可能にします。ファセットとは、ユーザーがカテゴリ、日付、価格帯、またはインデックスされた任意のフィールドなど、特定の条件を選択して検索結果を絞り込むためのフィルターです。
このモジュールは、複数のウィジェットタイプ(リンク、チェックボックス、ドロップダウン)、ファセット結果の変換とフィルタリングのための多数のプロセッサ、柔軟なURL処理を備えた包括的なプラグインシステムを提供します。Search APIおよびViewsとシームレスに統合され、ブロックベースの配置とFacets 3で導入された新しいExposed Filtersアプローチの両方をサポートします。
主な機能には、タクソノミーの階層ファセットサポート、エンティティラベルの自動翻訳による多言語サポート、依存ファセット条件、カスタマイズ可能な空の動作、適切なキャッシュコンテキスト処理による広範なキャッシュが含まれます。また、facets_restサブモジュールを通じてRESTエクスポートもサポートしています。
Features
- タクソノミー、エンティティ参照、日付、数値、テキストフィールドを含む任意のSearch APIインデックスフィールドからファセットを作成
- 複数のウィジェットタイプ:リンクリスト、チェックボックス、ドロップダウンセレクター、Array(REST用)
- ファセット結果のソート、フィルタリング、変換のための25以上の組み込みプロセッサを備えた広範なプロセッサシステム
- 展開可能なツリー構造と親子関係を持つ階層タクソノミーサポート
- 設定可能なURLエイリアスとクエリ文字列処理によるURLベースのフィルタリング
- 依存ファセット条件 - 他のファセット選択に基づいてファセットの表示/非表示を切り替え
- 空の動作オプション:ファセットを非表示、空のファセットを表示、またはカスタムテキストを表示
- エンティティラベルの自動翻訳による多言語サポート
- アクティブなファセット選択を表示するパンくずリスト統合
- 現在の検索フィルターを表示するFacets Summaryサブモジュール
- facets_range_widgetサブモジュールによる範囲スライダーウィジェット
- facets_searchbox_widgetサブモジュールによる検索ボックスフィルターウィジェット
- ヘッドレスアプリケーション向けfacets_restサブモジュールによるREST APIサポート
- facets_exposed_filtersサブモジュールによるViews Exposed Filters統合
- JavaScriptで追加のファセット項目を表示/非表示にするソフトリミット機能
- ファセットフィルタリングされたページの適切なキャッシュのためのキャッシュコンテキストサポート
- ファセットURL、クエリ文字列、キャッシュメタデータをカスタマイズするためのイベントシステム
Use Cases
E-commerce Product Filtering
Create facets for product attributes like category, brand, price range, color, and size. Use the Range Widget submodule for price sliders. Enable hierarchy for nested categories. Configure AND/OR operators based on whether filters should be exclusive or additive.
Content Archive with Taxonomy Filters
Build a filterable content archive using taxonomy term facets. Enable 'Transform entity ID to label' processor to show term names. Use hierarchy for nested vocabularies. Add 'Hide non-narrowing results' to only show relevant filter options.
Search Results with Multiple Filter Types
Combine text facets (author, tags), date facets (publication date with granularity), and boolean facets (featured, published). Use dependent facets to show related filters only when parent facets are selected.
Headless/Decoupled Search API
Use the facets_rest submodule with Array widget to return facet data in REST API responses. Build custom frontend facet UIs while leveraging Drupal's Search API indexing and facet processing.
Multi-language Faceted Search
Enable 'Transform entity ID to label' processor which automatically loads translated entity labels. The module respects the current language context and provides proper cache contexts for language-aware caching.
Tips
- Use the new Facets Exposed Filters approach (facets_exposed_filters submodule) for new sites - it provides better Views integration
- Enable 'Sort by active state' processor to keep selected items at the top of the list
- Use URL aliases that are short but descriptive - they appear in URLs when facets are active
- Configure soft limits on links/checkbox widgets to show a manageable number of items with 'Show more' expansion
- Test facet behavior with browser caching disabled during development
- Use the facets_debug_cacheable_metadata setting to debug caching issues in development
Technical Details
Admin Pages 5
/admin/config/search/facets
Main administration page listing all configured facets grouped by their facet sources. Allows creating, editing, cloning, and deleting facets. Shows facet weight for ordering and provides quick access to facet source configuration.
/admin/config/search/facets/add-facet
Form for creating a new facet. Select a facet source (Views display), choose a field to facet on, and provide a name and machine name.
/admin/config/search/facets/{facets_facet}/edit
Main facet configuration form for editing widget, processors, and display settings.
/admin/config/search/facets/{facets_facet}/settings
Basic settings form for editing facet source, name, and field selection.
/admin/config/search/facets/facet-sources/{facets_facet_source}/edit
Configure facet source settings including URL processor and breadcrumb options.
権限 1
Hooks 1
hook_facets_search_api_query_type_mapping_alter
Alter the Facets Query Type mapping to customize how data types are handled in Search API based Facets
Troubleshooting 6
Enable the 'Transform entity ID to label' processor on the facet. Ensure the indexed field is an entity reference (not just the entity ID field).
Check that 'Hide facet when facet source is not rendered' is unchecked if displaying facets on pages without the search view. Verify the facet block is placed in a visible region.
Add a language filter to your Views query, or implement hook_search_api_query_alter() to restrict results to the current language.
Ensure your Views cache is set to 'Search API (none)' or a cache plugin that respects facet selections. The facets module adds appropriate cache contexts automatically.
Enable 'Ensure that only one result can be displayed' in facet settings to make dropdown behave as single-select.
Enable the 'Index hierarchy' processor on the Search API index for taxonomy fields. Enable 'Use hierarchy' on the facet and select Taxonomy as hierarchy type.
Security Notes 3
- The 'administer facets' permission grants full control over facet configuration - assign carefully
- URL aliases are sanitized to prevent XSS - only alphanumeric characters, dots, hyphens, underscores, and tildes are allowed
- Facet processors that display entity labels respect entity access - unpublished content labels are not exposed to unauthorized users