/**
  * Escape all special characters in a query string
  *
  * @access	public
  *
  * @param	string		$query: The query string
  *
  * @return	string		The escaped query string
  */
 public static function escapeQuery($query)
 {
     // Load class.
     if (!class_exists('Apache_Solr_Service')) {
         require_once t3lib_div::getFileAbsFileName('EXT:' . self::$extKey . '/lib/SolrPhpClient/Apache/Solr/Service.php');
     }
     // Escape query phrase or term.
     if (preg_match('/^".*"$/', $query)) {
         return '"' . Apache_Solr_Service::escapePhrase(trim($query, '"')) . '"';
     } else {
         return Apache_Solr_Service::escape($query);
     }
 }
示例#2
0
 /**
  * Escape a value meant to be contained in a phrase for special query characters
  *
  * @param string $value
  * @return string
  */
 public static function escapePhrase($value)
 {
     return Apache_Solr_Service::escapePhrase($value);
 }
<?php

require dirname(__FILE__) . '/../../bootstrap/unit.php';
$t = new limeade_test(3, limeade_output::get());
$val = "this is my+ es\\caped ?*string";
$escaped = Apache_Solr_Service::escape($val);
$expected = 'this is my\\+ es\\\\caped \\?\\*string';
$t->cmp_ok($escaped, '===', $expected, "::escape  ok");
$val = "this is \"my escaped\" phrase";
$escaped = Apache_Solr_Service::escapePhrase($val);
$expected = 'this is \\"my escaped\\" phrase';
$t->cmp_ok($escaped, '===', $expected, "::escapePhrase  ok");
$escaped = Apache_Solr_Service::phrase($val);
$expected = '"this is \\"my escaped\\" phrase"';
$t->cmp_ok($escaped, '===', $expected, "::phrase  ok");
 /**
  * Escape a value meant to be contained in a phrase for special query
  * characters
  *
  * @param string $value            
  * @return string
  */
 public static function escapePhrase($value)
 {
     return parent::escapePhrase($value);
 }
示例#5
0
 /**
  * Build SQL statement for condition
  *
  * @param string $fieldName
  * @param integer|string|array $condition
  * @return string
  */
 public function orWhere($cond, $condition = null)
 {
     if (!is_null($condition) && is_null($condition)) {
         $cond = str_replace('?', '"' . Apache_Solr_Service::escapePhrase($condition) . '"', $cond);
     }
     $this->_query[] = array('type' => self::SOLR_OR, 'sql' => $cond);
     return $sql;
 }