handler_filter_fulltext.inc in Search API Multi-Index Searches 7
File
views/handler_filter_fulltext.inc
View source
<?php
class SearchApiMultiHandlerFilterFulltext extends SearchApiViewsHandlerFilterFulltext {
public function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$form['fields']['#description'] = t('Select the fields that will be searched. If no fields are selected and the "Search keys" mode is used, all available fulltext fields will be searched.');
}
public function query() {
while (is_array($this->value)) {
$this->value = $this->value ? reset($this->value) : '';
}
if ($this->value === '') {
return;
}
$fields = $this->options['fields'];
$filter = $this->options['mode'] == 'filter';
if (!$filter) {
$old = $this->query
->getFields();
$filter = $old && $fields && (array_diff($old, $fields) || array_diff($fields, $old));
}
if ($filter) {
$filter = $this->query
->createFilter('OR');
foreach ($fields as $field) {
$filter
->condition($field, $this->value, $this->operator);
}
$this->query
->filter($filter);
return;
}
if ($this->operator === 'OR') {
$this->query
->setOption('conjunction', $this->operator);
}
if ($fields) {
$this->query
->fields($fields);
}
$old = $this->query
->getOriginalKeys();
$this->query
->keys($this->value);
if ($this->operator == 'NOT') {
$keys =& $this->query
->getKeys();
if (is_array($keys)) {
$keys['#negation'] = TRUE;
}
else {
}
}
if ($old) {
$keys =& $this->query
->getKeys();
if (is_array($keys)) {
$keys[] = $old;
}
elseif (is_array($old)) {
}
else {
$keys = "({$old}) ({$keys})";
}
}
}
protected function getFulltextFields() {
$fields = array();
$indexes = search_api_index_load_multiple(FALSE, array(
'enabled' => TRUE,
));
foreach ($indexes as $index) {
if ($index
->getFields()) {
$prefix = $index->machine_name . ':';
$prefix_name = $index->name . ' » ';
$f = $index
->getFields();
foreach ($index
->getFulltextFields() as $name) {
$fields[$prefix . $name] = $prefix_name . $f[$name]['name'];
}
}
}
return $fields;
}
}