6. Drupal 8 Search Api
DrupalTalks#6
Forget about core Search
Support for Drupal 7 and 8
You can search everything as you have Entity
Connect any backend for Search:
- Database search
- Apache SOLR, Elasticsearch
7. How Search Api works
DrupalTalks#6
Index
Central configuration
Search what/how?
Backend-independent
Server
Storage mechanism
E.g., database, Solr,
How to index, search, …
Modules
Views, Facets, …
Browser client
Site page, checkboxes,
search input.
8. Nice words to be cool
DrupalTalks#6
Index
Server
Backend
Datasource
Property Perfectionist
Field
Data type
Boost
Processor
14. Facets
DrupalTalks#6
Facet API for Drupal 7
https://www.drupal.org/project/facetapi
and many related modules...
Facets for Drupal 8
https://www.drupal.org/project/facets
23. DrupalTalks#6
<?php
/**
* The slider widget.
*
* @FacetsWidget(
* id = "slider",
* label = @Translation("Slider"),
* description = @Translation("A widget that shows a slider."),
* )
*/
class SliderWidget {}
Annotation!!!
Customize Facets
24. DrupalTalks#6
<?php
namespace Drupalfacets_range_widgetPluginfacetswidget;
class SliderWidget extends WidgetPluginBase {
public function defaultConfiguration() {} // add configuration
public function build() {} // implement build
public function buildConfigurationForm(){} // build admin settings form
public function getQueryType() {}
public function isPropertyRequired() {}
}
Extend PluginBase
Customize Facets
29. DrupalTalks#6
<?php
/**
* Implements hook__search_api_index_items_alter().
*/
function TEST_SITE_search_api_index_items_alter(Drupalsearch_apiIndexInterface $index,
array &$items) {
foreach ($items as $item_id => $item) {
// get original NODE
$object = $item->getOriginalObject();
// get TYPE
$type = $object->get('type')->getValue()[0]['target_id'];
// update TYPE
$type = do_something_and_change_type();
// set TYPE
$object->set('type', $type);
// set new original NODE
$item->setOriginalObject($object);
}
}
Implement hook__search_api_index_items_alter()
Combine Facets