<?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");
示例#2
0
 /**
  * Convenience function for creating phrase syntax from a value
  *
  * @param string $value
  * @return string
  */
 public static function phrase($value)
 {
     return Apache_Solr_Service::phrase($value);
 }
 /**
  * Quote and escape search strings
  *
  * @param	string	the search string
  * @return	string	the escaped/quoted string
  */
 public function escape($string)
 {
     if (!is_numeric($string)) {
         if (preg_match('/\\W/', $string) == 1) {
             // multiple words
             $stringLength = strlen($string);
             if ($string[0] == '"' && $string[$stringLength - 1] == '"') {
                 // phrase
                 $string = trim($string, '"');
                 $string = Apache_Solr_Service::phrase($string);
             } else {
                 $string = Apache_Solr_Service::escape($string);
             }
         } else {
             $string = Apache_Solr_Service::escape($string);
         }
     }
     return $string;
 }