Commit a834e7b3 authored by Steve Mokris's avatar Steve Mokris Committed by Thomas Seidl
Browse files

Issue #3345999 by smokris, drunken monkey, ressa: Added support for phrase...

Issue #3345999 by smokris, drunken monkey, ressa: Added support for phrase searching to the database backend.
parent eb1431ae
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
Search API 1.x, dev (xxxx-xx-xx):
---------------------------------
- #3345999 by smokris, drunken monkey, ressa: Added support for phrase searching
  to the database backend.
- #3347901 by drunken monkey: Added possibility for dates to be used in number
  field-based boosting.
- #3321499 by andrew-minich, Shriaas, siddharthjain_7998, drunken monkey: Fixed
+2 −3
Original line number Diff line number Diff line
@@ -7,9 +7,8 @@ when creating a new server.
All Search API data types are supported by using appropriate SQL data types for
their respective columns.

The "direct" parse mode for queries will result in a simple splitting of the
query string into keys. Additionally, search keys containing whitespace will be
split for all parse modes, as searching for phrases is currently not supported.
Simple 2-word phrase searching is supported by surrounding the keywords in
double quotes.

## Supported optional features

+3 −0
Original line number Diff line number Diff line
@@ -11,6 +11,9 @@ plugin.plugin_configuration.search_api_backend.search_api_db:
    matching:
      type: 'string'
      label: 'The matching mode  "words", "prefix" or "partial"'
    phrase:
      type: 'string'
      label: 'The phrase indexing mode  "disabled" or "bigram"'
    autocomplete:
      type: mapping
      label: Autocomplete configuration
+31 −0
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@

use Drupal\Core\Database\Database;
use Drupal\Core\Database\SchemaObjectExistsException;
use Drupal\Core\StringTranslation\PluralTranslatableMarkup;
use Drupal\Core\Utility\UpdateException;

/**
@@ -107,3 +108,33 @@ function search_api_db_update_8103() {
  }
  return NULL;
}

/**
 * Ensures phrase indexing is disabled for existing installations.
 */
function search_api_db_update_8104(): ?PluralTranslatableMarkup {
  // @see https://www.drupal.org/project/search_api/issues/3345999

  $config_factory = \Drupal::configFactory();
  $count = 0;
  foreach ($config_factory->listAll('search_api.server.') as $server_id) {
    $server = $config_factory->getEditable($server_id);
    if ($server->get('backend') !== 'search_api_db') {
      continue;
    }

    ++$count;
    $config = $server->get('backend_config') ?: [];
    $config['phrase'] = 'disabled';
    $server->set('backend_config', $config);
    // Mark the resulting configuration as trusted data. This avoids issues
    // with future schema changes.
    $server->save(TRUE);
  }

  if ($count) {
    return \Drupal::translation()
      ->formatPlural($count, 'Updated 1 server.', 'Updated @count servers.');
  }
  return NULL;
}
+1 −0
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ backend_config:
  database: 'default:default'
  min_chars: 3
  matching: 'words'
  phrase: 'bigram'
  autocomplete:
    suggest_suffix: true
    suggest_words: true
Loading