Open Semantic Framework PHP API  3.0
 All Data Structures Namespaces Files Functions Variables Pages
ExtendedFiltersBuilder.php
Go to the documentation of this file.
1 <?php
2 
5 
11 
12 
57  {
61  private $extendedFilters = "";
62 
63  function __construct(){}
64 
69  function getExtendedFilters()
70  {
71  return($this->extendedFilters);
72  }
73 
80  public function datasetFilter($dataset)
81  {
82  $this->extendedFilters .= "dataset:".urlencode('"'.$dataset.'"');
83 
84  return($this);
85  }
86 
94  public function typeFilter($type, $enableInference = FALSE)
95  {
96  if($enableInference === FALSE)
97  {
98  $this->extendedFilters .= "type:".urlencode('"'.$type.'"');
99  }
100  else
101  {
102  $this->extendedFilters .= "(type:".urlencode('"'.$type.'"').urlencode(" OR ").
103  "inferred_type:".urlencode('"'.$type.'"').")";
104  }
105 
106  return($this);
107  }
108 
118  public function attributeValueFilter($attribute, $value="*", $valueIsUri = FALSE)
119  {
120  // Check if there are Search endpoint control characters in the query.
121  // If there are, then we don't escape the values and we assume
122  // they are properly escaped.
123  //
124  // EXCEPT if the value is a URI
125 
126  str_replace(array(' OR ', ' AND ', ' NOT ', '\\', '+', '-', '&',
127  '|', '!', '(', ')', '{', '}', '[', ']', '^',
128  '~', '*', '?', '"', ';', ' '), "", $value, $found);
129 
130  if($found > 0 && !$valueIsUri)
131  {
132  $this->extendedFilters .= urlencode(urlencode($attribute)).($valueIsUri === TRUE ? "[uri]" : "").":".
133  urlencode(urlencode($value));
134  }
135  else
136  {
137  $this->extendedFilters .= urlencode(urlencode($attribute)).($valueIsUri === TRUE ? "[uri]" : "").":".
138  urlencode(urlencode($this->escape($value)));
139  }
140 
141  return($this);
142  }
143 
147  public function and_()
148  {
149  $this->extendedFilters .= urlencode(" AND ");
150 
151  return($this);
152  }
153 
157  public function or_()
158  {
159  $this->extendedFilters .= urlencode(" OR ");
160 
161  return($this);
162  }
163 
167  public function not_()
168  {
169  $this->extendedFilters .= urlencode(" NOT ");
170 
171  return($this);
172  }
173 
177  public function startGrouping()
178  {
179  $this->extendedFilters .= "(";
180 
181  return($this);
182  }
183 
187  public function endGrouping()
188  {
189  $this->extendedFilters .= ")";
190 
191  return($this);
192  }
193 
199  private function escape($string)
200  {
201  $match = array('\\', '+', '-', '&', '|', '!', '(', ')', '{', '}', '[', ']', '^', '~', '*', '?', ':', '"', ';', ' ');
202  $replace = array('\\\\', '\\+', '\\-', '\\&', '\\|', '\\!', '\\(', '\\)', '\\{', '\\}', '\\[', '\\]', '\\^', '\\~', '\\*', '\\?', '\\:', '\\"', '\\;', '\\ ');
203  $string = str_replace($match, $replace, $string);
204 
205  return $string;
206  }
207  }
208 
210 ?>
attributeValueFilter($attribute, $value="*", $valueIsUri=FALSE)
Add an attribute/value filter.
getExtendedFilters()
Return the list of filters generated by the ExtendedFiltersBuilder class used by the OSF Search endpo...
typeFilter($type, $enableInference=FALSE)
Add a type URI to filter.
or_()
Add a OR operator to the extended filters query.
not_()
Add a NOT operator to the extended filters query.
and_()
Add a AND operator to the extended filters query.
Class used to generate a set of extended attribute filters that should be added to a SearchQuery...