/
lib_solr_utils.php
38 lines (24 loc) · 987 Bytes
/
lib_solr_utils.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
#################################################################
function solr_utils_hash2query(&$hash, $join=null){
$q = array();
foreach ($hash as $k => $v){
$k = urlencode($k);
$v = (preg_match("/^raw:(.*)$/", $v, $m)) ? $m[1] : solr_utils_escape($v);
$q[] = "{$k}:{$v}";
}
if ($join){
$q = implode($join, $q);
}
return $q;
}
#################################################################
# http://e-mats.org/2010/01/escaping-characters-in-a-solr-query-solr-url/
function solr_utils_escape($string){
$match = array('\\', '+', '-', '&', '|', '!', '(', ')', '{', '}', '[', ']', '^', '~', '*', '?', ':', '"', ';', ' ');
$replace = array('\\\\', '\\+', '\\-', '\\&', '\\|', '\\!', '\\(', '\\)', '\\{', '\\}', '\\[', '\\]', '\\^', '\\~', '\\*', '\\?', '\\:', '\\"', '\\;', '\\ ');
$string = str_replace($match, $replace, $string);
return $string;
}
#################################################################
?>