diff --git a/search_api_db/tests/src/Kernel/BackendTest.php b/search_api_db/tests/src/Kernel/BackendTest.php
index 0f00050..a21acac 100644
--- a/search_api_db/tests/src/Kernel/BackendTest.php
+++ b/search_api_db/tests/src/Kernel/BackendTest.php
@@ -185,6 +185,9 @@ protected function updateIndex() {
$index->save();
$index_fields = array_keys($index->getFields());
+ // Include the two "magic" fields we're indexing with the DB backend.
+ $index_fields[] = 'search_api_datasource';
+ $index_fields[] = 'search_api_language';
$db_info = $this->getIndexDbInfo();
$server_fields = array_keys($db_info['field_tables']);
diff --git a/src/Entity/Index.php b/src/Entity/Index.php
index cf6c4a1..a28c7d3 100644
--- a/src/Entity/Index.php
+++ b/src/Entity/Index.php
@@ -870,9 +870,6 @@ public function indexSpecificItems(array $search_objects) {
if (!$this->status) {
throw new SearchApiException(new FormattableMarkup("Couldn't index values on index %index (index is disabled)", array('%index' => $this->label())));
}
- if (empty($this->getFields())) {
- throw new SearchApiException(new FormattableMarkup("Couldn't index values on index %index (no fields selected)", array('%index' => $this->label())));
- }
/** @var \Drupal\search_api\Item\ItemInterface[] $items */
$items = array();
diff --git a/src/Plugin/views/filter/SearchApiFulltext.php b/src/Plugin/views/filter/SearchApiFulltext.php
index bf29030..bbeea4a 100644
--- a/src/Plugin/views/filter/SearchApiFulltext.php
+++ b/src/Plugin/views/filter/SearchApiFulltext.php
@@ -154,8 +154,6 @@ public function query() {
$this->value = $this->value ? reset($this->value) : '';
}
// Catch empty strings entered by the user, but not "0".
- // @todo Is this needed? It seems Views doesn't call filters with empty
- // values by default anyways.
if ($this->value === '') {
return;
}
diff --git a/src/Plugin/views/query/SearchApiQuery.php b/src/Plugin/views/query/SearchApiQuery.php
index 36c14f1..15499b5 100644
--- a/src/Plugin/views/query/SearchApiQuery.php
+++ b/src/Plugin/views/query/SearchApiQuery.php
@@ -812,7 +812,7 @@ public function addCondition($field, $value, $operator = '=', $group = NULL) {
$group = 0;
}
$condition = array($field, $value, $operator);
- $this->conditions[$group]['conditions'][] = $condition;
+ $this->where[$group]['conditions'][] = $condition;
}
return $this;
}
diff --git a/src/Tests/IntegrationTest.php b/src/Tests/IntegrationTest.php
index 4975cc0..3b40573 100644
--- a/src/Tests/IntegrationTest.php
+++ b/src/Tests/IntegrationTest.php
@@ -747,7 +747,13 @@ protected function configureFilter() {
$processors = $index->getProcessors();
if (isset($processors['ignorecase'])) {
$configuration = $processors['ignorecase']->getConfiguration();
- $this->assertFalse(empty($configuration['fields']['title']), 'Title field enabled for ignore case filter.');
+ unset($configuration['weights']);
+ $expected = array(
+ 'fields' => array(
+ 'title',
+ ),
+ );
+ $this->assertEqual($expected, $configuration, 'Title field enabled for ignore case filter.');
}
else {
$this->fail('"Ignore case" processor not enabled.');
diff --git a/src/Tests/ProcessorIntegrationTest.php b/src/Tests/ProcessorIntegrationTest.php
index 540505d..e1a58fa 100644
--- a/src/Tests/ProcessorIntegrationTest.php
+++ b/src/Tests/ProcessorIntegrationTest.php
@@ -42,8 +42,8 @@ public function setUp() {
* avoid the overhead of having one test per processor.
*/
public function testProcessorIntegration() {
- // By default, the add_url and language processors are already enabled.
- $enabled = array('language', 'add_url');
+ // The add_url processor is always enabled.
+ $enabled = array('add_url');
sort($enabled);
$actual_processors = array_keys($this->loadIndex()->getProcessors());
sort($actual_processors);
@@ -119,9 +119,8 @@ public function testProcessorIntegration() {
sort($actual_processors);
$this->assertEqual($enabled, $actual_processors);
- // The 'language' and 'add_url' processors are are not available to be
- // removed because they are locked processors.
- $this->checkLanguageIntegration();
+ // The 'add_url' processor is not available to be removed because it's
+ // locked.
$this->checkUrlFieldIntegration();
// Check whether disabling processors also works correctly.
@@ -192,40 +191,35 @@ public function checkContentAccessIntegration() {
* Tests the UI for the "Highlight" processor.
*/
public function checkHighlightIntegration() {
- $this->enableProcessor('highlight');
-
- $edit = array(
- 'processors[highlight][settings][highlight]' => 'never',
- 'processors[highlight][settings][excerpt]' => FALSE,
- 'processors[highlight][settings][excerpt_length]' => 128,
- 'processors[highlight][settings][prefix]' => '',
- 'processors[highlight][settings][suffix]' => '',
+ $configuration = array(
+ 'highlight' => 'never',
+ 'excerpt' => FALSE,
+ 'excerpt_length' => 128,
+ 'prefix' => '',
+ 'suffix' => '',
);
- $this->editSettingsForm($edit, 'highlight');
+ $this->editSettingsForm($configuration, 'highlight');
}
/**
* Tests the UI for the "HTML filter" processor.
*/
public function checkHtmlFilterIntegration() {
- // Enable the "HTML filter" processor in the same request as setting the
- // settings, since we otherwise run into a weird bug only present in the
- // testing environment regarding the YAML in the "tags" setting.
- $edit = array(
- 'status[html_filter]' => 1,
- 'processors[html_filter][settings][title]' => FALSE,
- 'processors[html_filter][settings][alt]' => FALSE,
- 'processors[html_filter][settings][tags]' => 'h1: 10',
+ $configuration = $form_values = array(
+ 'title' => FALSE,
+ 'alt' => FALSE,
+ 'tags' => array(
+ 'h1' => 10,
+ ),
);
- $this->editSettingsForm($edit, 'html_filter');
+ $form_values['tags'] = 'h1: 10';
+ $this->editSettingsForm($configuration, 'html_filter', $form_values);
}
/**
* Tests the UI for the "Ignore case" processor.
*/
public function checkIgnoreCaseIntegration() {
- $this->enableProcessor('ignorecase');
-
$this->editSettingsForm(array(), 'ignorecase');
}
@@ -233,27 +227,34 @@ public function checkIgnoreCaseIntegration() {
* Tests the UI for the "Ignore characters" processor.
*/
public function checkIgnoreCharactersIntegration() {
- $this->enableProcessor('ignore_character');
-
- $edit = array(
- 'processors[ignore_character][settings][ignorable]' => '[¿¡!?,.]',
- 'processors[ignore_character][settings][strip][character_sets][Cc]' => TRUE,
+ $configuration = $form_values = array(
+ 'ignorable' => '[¿¡!?,.]',
+ 'strip' => array(
+ 'character_sets' => array(
+ 'Pc' => 'Pc',
+ 'Pd' => 'Pd',
+ 'Pe' => 'Pe',
+ 'Pf' => 'Pf',
+ 'Pi' => 'Pi',
+ 'Po' => 'Po',
+ 'Ps' => 'Ps',
+ 'Cc' => 'Cc',
+ 'Cf' => FALSE,
+ 'Co' => FALSE,
+ 'Mc' => FALSE,
+ 'Me' => FALSE,
+ 'Mn' => FALSE,
+ 'Sc' => FALSE,
+ 'Sk' => FALSE,
+ 'Sm' => FALSE,
+ 'So' => FALSE,
+ 'Zl' => FALSE,
+ 'Zp' => FALSE,
+ 'Zs' => FALSE,
+ ),
+ ),
);
- $this->editSettingsForm($edit, 'ignore_character');
- }
-
- /**
- * Tests the UI for the "Language" processor.
- */
- public function checkLanguageIntegration() {
- $index = $this->loadIndex();
- $processors = $index->getProcessors();
- $this->assertTrue(!empty($processors['language']), 'The "language" processor is enabled by default.');
- $index->removeProcessor('language');
- $index->save();
-
- $processors = $this->loadIndex()->getProcessors();
- $this->assertTrue(!empty($processors['language']), 'The "language" processor cannot be disabled.');
+ $this->editSettingsForm($configuration, 'ignore_character', $form_values);
}
/**
@@ -267,48 +268,50 @@ public function checkNodeStatusIntegration() {
* Tests the UI for the "Rendered item" processor.
*/
public function checkRenderedItemIntegration() {
- $this->enableProcessor('rendered_item');
-
- $edit = array(
- 'processors[rendered_item][settings][roles][]' => 'authenticated',
- 'processors[rendered_item][settings][view_mode][entity:node][page]' => 'default',
- 'processors[rendered_item][settings][view_mode][entity:node][article]' => 'default',
+ $configuration = $form_values = array(
+ 'roles' => array(
+ 'authenticated' => 'authenticated',
+ ),
+ 'view_mode' => array(
+ 'entity:node' => array(
+ 'page' => 'default',
+ 'article' => 'default',
+ ),
+ ),
);
- $this->editSettingsForm($edit, 'rendered_item');
+ $form_values['roles'] = array('authenticated');
+ $this->editSettingsForm($configuration, 'rendered_item', $form_values);
}
/**
* Tests the UI for the "Stopwords" processor.
*/
public function checkStopWordsIntegration() {
- $this->enableProcessor('stopwords');
-
- $edit = array(
- 'processors[stopwords][settings][stopwords]' => 'the',
+ $configuration = array(
+ 'stopwords' => array('the'),
+ );
+ $form_values = array(
+ 'stopwords' => 'the',
);
- $this->editSettingsForm($edit, 'stopwords');
+ $this->editSettingsForm($configuration, 'stopwords', $form_values);
}
/**
* Tests the UI for the "Tokenizer" processor.
*/
public function checkTokenizerIntegration() {
- $this->enableProcessor('tokenizer');
-
- $edit = array(
- 'processors[tokenizer][settings][spaces]' => '',
- 'processors[tokenizer][settings][overlap_cjk]' => FALSE,
- 'processors[tokenizer][settings][minimum_word_size]' => 2,
+ $configuration = array(
+ 'spaces' => '',
+ 'overlap_cjk' => FALSE,
+ 'minimum_word_size' => 2,
);
- $this->editSettingsForm($edit, 'tokenizer');
+ $this->editSettingsForm($configuration, 'tokenizer');
}
/**
* Tests the UI for the "Transliteration" processor.
*/
public function checkTransliterationIntegration() {
- $this->enableProcessor('transliteration');
-
$this->editSettingsForm(array(), 'transliteration');
}
@@ -344,29 +347,78 @@ protected function enableProcessor($processor_id) {
}
/**
- * Edits a processor's settings.
+ * Enables a processor with a given configuration.
*
- * @param array $edit
- * The settings to set for the processor.
+ * @param array $configuration
+ * The configuration to set for the processor.
* @param string $processor_id
- * The ID of the processor whose settings are edited.
+ * The ID of the processor to edit.
+ * @param array|null $form_values
+ * (optional) The processor configuration to set, as it appears in the form.
+ * Only relevant if the processor does some processing on the form values
+ * before storing them, like parsing YAML or cleaning up checkboxes values.
+ * Defaults to using $configuration as-is.
+ * @param bool $enable
+ * (optional) If TRUE, explicitly enable the processor. If FALSE, it should
+ * already be enabled.
*/
- protected function editSettingsForm($edit, $processor_id) {
+ protected function editSettingsForm(array $configuration, $processor_id, array $form_values = NULL, $enable = TRUE) {
+ if (!isset($form_values)) {
+ $form_values = $configuration;
+ }
+
$this->loadProcessorsTab();
+ $edit = $this->getFormValues($form_values, "processors[$processor_id][settings]");
+ if ($enable) {
+ $edit["status[$processor_id]"] = 1;
+ }
$this->drupalPostForm(NULL, $edit, $this->t('Save'));
$processors = $this->loadIndex()->getProcessors();
- // @todo Actually test something here. Idea: pass in a $configuration array,
- // convert to POST format in here automatically and then check if the
- // processor's configuration matches.
- if (isset($processors[$processor_id])) {
- $configuration = $processors[$processor_id]->getConfiguration();
- $this->assertTrue(empty($configuration['fields']['search_api_language']));
+ $processor_present = !empty($processors[$processor_id]);
+ $this->assertTrue($processor_present, "Successfully enabled the '$processor_id' processor.'");
+ if ($processor_present) {
+ $actual_configuration = $processors[$processor_id]->getConfiguration();
+ unset($actual_configuration['fields'], $actual_configuration['weights']);
+ $configuration += $processors[$processor_id]->defaultConfiguration();
+ $this->assertEqual($configuration, $actual_configuration, "Processor configuration for processor '$processor_id' was set correctly.");
}
- else {
- $this->fail($processor_id . ' settings not applied.');
+ }
+
+ /**
+ * Converts a configuration array into an array of form values.
+ *
+ * @param array $configuration
+ * The configuration to convert.
+ * @param string $prefix
+ * The common prefix for all form values.
+ *
+ * @return string[]
+ * An array of form values ready for submission.
+ */
+ protected function getFormValues(array $configuration, $prefix) {
+ $edit = array();
+
+ foreach ($configuration as $key => $value) {
+ $key = $prefix . "[$key]";
+ if (is_array($value)) {
+ // Handling of numerically indexed and associative arrays needs to be
+ // different.
+ if ($value == array_values($value)) {
+ $key .= '[]';
+ $edit[$key] = $value;
+ }
+ else {
+ $edit += $this->getFormValues($value, $key);
+ }
+ }
+ else {
+ $edit[$key] = $value;
+ }
}
+
+ return $edit;
}
/**
diff --git a/src/Tests/ViewsTest.php b/src/Tests/ViewsTest.php
index 12c529b..cf1b10f 100644
--- a/src/Tests/ViewsTest.php
+++ b/src/Tests/ViewsTest.php
@@ -226,7 +226,7 @@ public function testViewsAdmin() {
$this->assertText($this->t('Authored on'));
$this->assertText($this->t('Body (indexed field)'));
$this->assertText($this->t('Index Test index'));
- $this->assertText($this->t('Entity ID'));
+ $this->assertText($this->t('Item ID'));
$this->assertText($this->t('Excerpt'));
$this->assertText($this->t('The search result excerpted to show found search terms'));
$this->assertText($this->t('Relevance'));