Skip to content

Instantly share code, notes, and snippets.

@krlucas
Last active March 15, 2016 13:07
Show Gist options
  • Save krlucas/5568644 to your computer and use it in GitHub Desktop.
Save krlucas/5568644 to your computer and use it in GitHub Desktop.
name = MyModule
description = My Module
core = 7.x
package = MyModule
php = 5.2.4
dependencies[] = views
files[] = mymodule_handler_filter_fulltext.inc
<?php
/**
* Implements hook_views_data_alter().
*/
function mymodule_views_data_alter(&$data) {
// Adds direct parse mode views fulltext filter to the Default Node Index.
$data['search_api_index_default_node_index']['mymodule_views_fulltext'] = array(
'group' => t('Search'),
'title' => t('Fulltext search using Solr/Lucene syntax'),
'help' => t('Search several or all fulltext fields using direct Solr/Lucene syntax.'),
'filter' => array(
'handler' => 'MyModuleViewsHandlerFilterFulltext',
),
);
}
<?php
/**
* @file
* Views Search API fulltext field handler that supports direct searches.
*
* Note that the tokenizer processor must be disabled.
*/
class MyModuleViewsHandlerFilterFulltext extends SearchApiViewsHandlerFilterFulltext {
/**
* Add this filter to the query.
*/
public function query() {
// Set parse mode to direct so the search input is sent directly to Solr.
$this->query->setOption('parse mode', 'direct');
parent::query();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment