You are here

public static function DrupalApacheSolrService::escape in Apache Solr Search 8

Same name and namespace in other branches
  1. 6.3 Drupal_Apache_Solr_Service.php \DrupalApacheSolrService::escape()
  2. 7 Drupal_Apache_Solr_Service.php \DrupalApacheSolrService::escape()

Escape a value for special query characters such as ':', '(', ')', '*', '?', etc.

NOTE: inside a phrase fewer characters need escaped, use {@link DrupalApacheSolrService::escapePhrase()} instead

Parameters

string $value:

Return value

string

File

./Drupal_Apache_Solr_Service.php, line 544

Class

DrupalApacheSolrService
Starting point for the Solr API. Represents a Solr server resource and has methods for pinging, adding, deleting, committing, optimizing and searching.

Code

public static function escape($value) {

  //list taken from http://lucene.apache.org/java/docs/queryparsersyntax.html#Escaping%20Special%20Characters
  $pattern = '/(\\+|-|&&|\\|\\||!|\\(|\\)|\\{|}|\\[|]|\\^|"|~|\\*|\\?|:|\\\\)/';
  $replace = '\\\\$1';
  return preg_replace($pattern, $replace, $value);
}