You are here

public static function Apache_Solr_Service::escape in Apache Solr Search 5

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

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

Parameters

string $value:

Return value

string

1 call to Apache_Solr_Service::escape()
Apache_Solr_Service_Balancer::escape in SolrPhpClient/Apache/Solr/Service/Balancer.php
Escape a value for special query characters such as ':', '(', ')', '*', '?', etc.

File

SolrPhpClient/Apache/Solr/Service.php, line 158

Class

Apache_Solr_Service
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);
}