The Search API in Drupal 8 Thomas Seidl (drunken monkey)
Disclaimer Everything shown here is still a work in progress. Details might change until 8.0 release.
Basic architecture Server Index Views Technical implementation Generic information Uses database/solr/ Item type Facets Search how? Fields Processing Search what?
Server Configuration entity Uses plugin service class for operations Stores class and specific settings
Service class Plugin for servers Implementation of server operations Indexing, deleting, searching Reaction to changed indexes Custom configuration form Connects to storage (DB, Solr, )
Index Configuration entity Main connection to other modules Uses datasource plugin
Datasource Index plugin providing the item types Loading, viewing, metadata for types Tracking of new/changed/deleted items Type-specific configuration
Processors Plugins attached to index Alter indexed items and search queries Configurable (Fused with D7 data alterations )
Index Indexing Datasource Processors Server 5. Extracts fields 1. Determines 4. Alter changed items 7. Sends items to server 2. Loads items 3. Provides metadata 10. Marks items as indexed metadata 6. Preprocess fields / items 8. Indexes items 9. Returns indexed items
Search Searching Query Processors Server 1. Creates query 2. Adds keywords 4. Adds filters, sort, etc. 3. Parses keywords 5. Checks input (partially) 7. Preprocess query 9. Postprocess search results 6. Executes query 8. Retrieves results 10. Displays results
Customizations
Service class Integrate new search services with Drupal /** * @SearchApiService( * id = "MODULE_my_service", * label = @Translation("My service"), * description = @Translation("Really cool!") * ) */ class MyService extends ServicePluginBase { function indexitems($index, $items) {} function deleteitems($index, $ids) {} function deleteallitems($index) {} function search($query) {} }
Service class Also available: Configuration form React to new/changed/removed indexes CRUD hooks supportsfeature(), supportsdatatype()
Features Add service-specific functionality Defined by contrib modules Using modules check for support Creation: No code, just documentation E.g.: facets, MLT, location, autocomplete, spellcheck
Data type Let services support non-default data types E.g., location coordinates, special text formats Services state support similar to features D7: hook_search_api_data_type_info() Documentation important
Datasource Support for custom item types /** * @SearchApiDatasource( * id = "MODULE_my_datasource", * name = @Translation(My datasource"), * description = @Translation("My great type.") * ) */ class MyDatasource extends DatasourcePluginBase { function getidfieldinfo() {} function getpropertydefinitions() {} function loaditems($ids) {} function getallitemids() {} }
Datasource Also available: Configuration form Viewing and view modes Get item's ID, label, URL Override tracking mechanism Call search_api_track_item_*()!
Processor Pre-/postprocess indexed items and results /** * @SearchApiProcessor( * id = "MODULE_my_processor", * label = @Translation("My processor"), * description = @Translation("Does stuff.") * ) */ class MyProcessor extends ProcessorPluginBase { function alterpropertydefinitions(&$info) {} function preprocessindexitems(&$items) {} function preprocesssearchquery($query) {} function postprocesssearchresults(&$response, $query) {} }
Processor Also available: supportsindex() Configuration form Default implementation FieldsProcessorPluginBase process(), processfieldvalue(), processkey(), processfiltervalue(), testfield(), testtype()
Parse modes Interpretation of keywords By default: direct, single term, multiple terms Selection when creating search
Query D7: Pluggable in odd way D8: TBD
(Possible) D8 changes Support several item types per index More query functionality (like DB layer) Major changes for processors Possibly: query extenders / per-query processor config Loads of other stuff
Thank you!
What do you think?
Other questions?