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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338
<?php
namespace Gedcomx\Rs\Client;
/**
* This is a helper utility for building syntactically correct person search query strings.
*
* Class GedcomxSearchQuery
*
* @package Gedcomx\Rs\Client
*/
class GedcomxSearchQuery
{
/**
* The name parameter in person search queries
*/
const NAME = "name";
/**
* The given name parameter in person search queries
*/
const GIVEN_NAME = "givenName";
/**
* The surname parameter in person search queries
*/
const SURNAME = "surname";
/**
* The gender parameter in person search queries
*/
const GENDER = "gender";
/**
* The birth date parameter in person search queries
*/
const BIRTH_DATE = "birthDate";
/**
* The birth place parameter in person search queries
*/
const BIRTH_PLACE = "birthPlace";
/**
* The death date parameter in person search queries
*/
const DEATH_DATE = "deathDate";
/**
* The death place parameter in person search queries
*/
const DEATH_PLACE = "deathPlace";
/**
* The marriage date parameter in person search queries
*/
const MARRIAGE_DATE = "marriageDate";
/**
* The marriage place parameter in person search queries
*/
const MARRIAGE_PLACE = "marriagePlace";
/**
* The father name parameter in person search queries
*/
const FATHER_NAME = "fatherName";
/**
* The father given name parameter in person search queries
*/
const FATHER_GIVEN_NAME = "fatherGivenName";
/**
* The father surname parameter in person search queries
*/
const FATHER_SURNAME = "fatherSurname";
/**
* The father gender parameter in person search queries
*/
const FATHER_GENDER = "fatherGender";
/**
* The father birth date parameter in person search queries
*/
const FATHER_BIRTH_DATE = "fatherBirthDate";
/**
* The father birth place parameter in person search queries
*/
const FATHER_BIRTH_PLACE = "fatherBirthPlace";
/**
* The father death date parameter in person search queries
*/
const FATHER_DEATH_DATE = "fatherDeathDate";
/**
* The father death place parameter in person search queries
*/
const FATHER_DEATH_PLACE = "fatherDeathPlace";
/**
* The father marriage date parameter in person search queries
*/
const FATHER_MARRIAGE_DATE = "fatherMarriageDate";
/**
* The father marriage place parameter in person search queries
*/
const FATHER_MARRIAGE_PLACE = "fatherMarriagePlace";
/**
* The mother name parameter in person search queries
*/
const MOTHER_NAME = "motherName";
/**
* The mother given name parameter in person search queries
*/
const MOTHER_GIVEN_NAME = "motherGivenName";
/**
* The mother surname parameter in person search queries
*/
const MOTHER_SURNAME = "motherSurname";
/**
* The mother gender parameter in person search queries
*/
const MOTHER_GENDER = "motherGender";
/**
* The mother birth date parameter in person search queries
*/
const MOTHER_BIRTH_DATE = "motherBirthDate";
/**
* The mother birth place parameter in person search queries
*/
const MOTHER_BIRTH_PLACE = "motherBirthPlace";
/**
* The mother death date parameter in person search queries
*/
const MOTHER_DEATH_DATE = "motherDeathDate";
/**
* The mother death place parameter in person search queries
*/
const MOTHER_DEATH_PLACE = "motherDeathPlace";
/**
* The mother marriage date parameter in person search queries
*/
const MOTHER_MARRIAGE_DATE = "motherMarriageDate";
/**
* The mother marriage place parameter in person search queries
*/
const MOTHER_MARRIAGE_PLACE = "motherMarriagePlace";
/**
* The spouse name parameter in person search queries
*/
const SPOUSE_NAME = "spouseName";
/**
* The spouse given name parameter in person search queries
*/
const SPOUSE_GIVEN_NAME = "spouseGivenName";
/**
* The spouse surname parameter in person search queries
*/
const SPOUSE_SURNAME = "spouseSurname";
/**
* The spouse gender parameter in person search queries
*/
const SPOUSE_GENDER = "spouseGender";
/**
* The spouse birth date parameter in person search queries
*/
const SPOUSE_BIRTH_DATE = "spouseBirthDate";
/**
* The spouse birth place parameter in person search queries
*/
const SPOUSE_BIRTH_PLACE = "spouseBirthPlace";
/**
* The spouse death date parameter in person search queries
*/
const SPOUSE_DEATH_DATE = "spouseDeathDate";
/**
* The spouse death place parameter in person search queries
*/
const SPOUSE_DEATH_PLACE = "spouseDeathPlace";
/**
* The spouse marriage date parameter in person search queries
*/
const SPOUSE_MARRIAGE_DATE = "spouseMarriageDate";
/**
* The spouse marriage place parameter in person search queries
*/
const SPOUSE_MARRIAGE_PLACE = "spouseMarriagePlace";
/**
* The parent name parameter in person search queries
*/
const PARENT_NAME = "parentName";
/**
* The parent given name parameter in person search queries
*/
const PARENT_GIVEN_NAME = "parentGivenName";
/**
* The parent surname parameter in person search queries
*/
const PARENT_SURNAME = "parentSurname";
/**
* The parent gender parameter in person search queries
*/
const PARENT_GENDER = "parentGender";
/**
* The parent birth date parameter in person search queries
*/
const PARENT_BIRTH_DATE = "parentBirthDate";
/**
* The parent birth place parameter in person search queries
*/
const PARENT_BIRTH_PLACE = "parentBirthPlace";
/**
* The parent death date parameter in person search queries
*/
const PARENT_DEATH_DATE = "parentDeathDate";
/**
* The parent death place parameter in person search queries
*/
const PARENT_DEATH_PLACE = "parentDeathPlace";
/**
* The parent marriage date parameter in person search queries
*/
const PARENT_MARRIAGE_DATE = "parentMarriageDate";
/**
* The parent marriage place parameter in person search queries
*/
const PARENT_MARRIAGE_PLACE = "parentMarriagePlace";
/**
* @var SearchParameter[]
*/
private $parameters = array();
/**
* Builds the query string to use for searching.
*
* @return string
*/
public function __toString()
{
return implode(' ', $this->parameters);
}
/**
* Creates a generic search parameter with the specified name and value. The parameter is added to the array of
* current parameters and $this is returned.
* @param string $name
* @param string $value
* @param bool $exact
* @return GedcomxSearchQuery $this
*/
public function param($name, $value = null, $exact = false)
{
array_push($this->parameters, new SearchParameter($name, $value, $exact));
return $this;
}
}
/**
* Represents a generic search parameter.
*/
class SearchParameter
{
/**
* @var string
*/
private $name;
/**
* @var string
*/
private $value;
/**
* @var bool
*/
private $exact;
private static $whitespace = array("\n", "\t", "\f", "\013");
/**
* Constructs a new generic search parameter using the specified values.
*
* @param string $name
* @param string $value
* @param bool $exact
*/
function __construct($name, $value, $exact = false)
{
$this->name = $name;
$this->value = $value;
$this->exact = $exact;
}
/**
* Gets a value indicating whether the current search parameter requires exact value match results. See remarks.
*
* @return boolean
*/
public function getExact()
{
return $this->exact;
}
/**
* Gets the name of the current search parameter..
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Gets the value of the current search parameter.
*
* @return string
*/
public function getValue()
{
return $this->value;
}
/**
* Returns a string that is a syntactically conformant search query that can be used in REST API search requests.
*
* @return string
*/
public function __toString()
{
$str = $this->name;
if ($this->value) {
$str = $str . ':';
$escaped = str_replace(SearchParameter::$whitespace, ' ', $this->value);
$escaped = str_replace('"', '\\"', $escaped);
$needsQuote = strpos($escaped, ' ');
if ($needsQuote) {
$str = $str . '"';
}
$str = $str . $escaped;
if ($needsQuote) {
$str = $str . '"';
}
if ($this->exact) {
$str = $str . '~';
}
}
return $str;
}
}