Search API
Drupal Search in nutshell
Artem Sylchuk, F5
Imagine
You want to add search to your site
Putting a Search Engine on Your Website
$sql = "SELECT
`ID`,
`FirstName`,
`LastName`
FROM `Contacts`
WHERE `FirstName` LIKE '%" . $letter . "%'
OR `LastName` LIKE '%" . $letter ."%'";
Why not?
Indexing
Search engine indexing collects, parses, and stores data to facilitate fast and accurate information retrieval. Index design incorporates interdisciplinary concepts from linguistics, cognitive psychology, mathematics, informatics, and computer science. An alternate name for the process in the context of search engines designed to find web pages on the Internet is web indexing.
Search in Drupal core
https://www.acquia.com/blog/drupal-search-how-indexing-works
How does it work?
Wow, amazing! No?
No. We demand:
I want to build my own Google*
*with hookers
Search API
Search API
API Overview:
Extension features:
Search API Views:
Search API Recipes:
No Silver Bullet
Some UI Examples
Search
Drupal 8
Gimme some codez
Database & Indexing
drush sapi-i
SearchAPI + EntityAPI =
Entity Medata Wrapper
$wrapper = entity_metadata_wrapper('node', $node);
$wrapper = $entity->wrapper();
$wrapper->author->mail->value();
$wrapper->author->mail->set('sepp@example.com');
$wrapper->author->mail = 'sepp@example.com';
$wrapper->body->value->value(array('decode' => TRUE));
$wrapper = entity_metadata_wrapper('node', $node);
foreach ($wrapper->field_taxonomy_terms->getIterator() as $delta => $term_wrapper) {
// $term_wrapper may now be accessed as a taxonomy term wrapper.
$label = $term_wrapper->name->value();
}
$first_name = $wrapper->field_tags[0]->name->value();
Death to Field Arrays!
http://www.mediacurrent.com/blog/entity-metadata-wrapper
Add Property To Entity
Views & entity_load()
Processors vs Alters
/**
* Implements hook_search_api_alter_callback_info().
*/
function search_api_search_api_alter_callback_info() {
$callbacks['search_api_alter_bundle_filter'] = array(
'name' => t('Bundle filter'),
'description' => t('Exclude items from indexing based on their bundle (content type, vocabulary, …).'),
'class' => 'SearchApiAlterBundleFilter',
// Filters should be executed first.
'weight' => -10,
);
}
/**
* Implements hook_search_api_processor_info().
*/
function search_api_search_api_processor_info() {
$processors['search_api_case_ignore'] = array(
'name' => t('Ignore case'),
'description' => t('This processor will make searches case-insensitive for fulltext or string fields.'),
'class' => 'SearchApiIgnoreCase',
);
}
Alter callbabks:
Processors:
Availble filters and Processors
Data alterations
Processors
Custom item types / datasource controllers
Intro to Apache Solr
SearchAPI vs Apache SOLR module
Setting up the Search