1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2024-12-23 05:34:55 +00:00

Context changes to support basic text searching

This commit is contained in:
J. King 2019-02-22 11:13:42 -05:00
parent ad8057a40b
commit f9fde23708

View file

@ -34,6 +34,7 @@ class Context {
public $labelName; public $labelName;
public $labelled = null; public $labelled = null;
public $annotated = null; public $annotated = null;
public $searchTerms = [];
protected $props = []; protected $props = [];
@ -52,7 +53,7 @@ class Context {
} }
} }
protected function cleanArray(array $spec): array { protected function cleanIdArray(array $spec): array {
$spec = array_values($spec); $spec = array_values($spec);
for ($a = 0; $a < sizeof($spec); $a++) { for ($a = 0; $a < sizeof($spec); $a++) {
if (ValueInfo::id($spec[$a])) { if (ValueInfo::id($spec[$a])) {
@ -64,6 +65,18 @@ class Context {
return array_values(array_filter($spec)); return array_values(array_filter($spec));
} }
protected function cleanStringArray(array $spec): array {
$spec = array_values($spec);
for ($a = 0; $a < sizeof($spec); $a++) {
if (strlen($str = ValueInfo::normalize($spec[$a], ValueInfo::T_STRING))) {
$spec[$a] = $str;
} else {
unset($spec[$a]);
}
}
return array_values($spec);
}
public function reverse(bool $spec = null) { public function reverse(bool $spec = null) {
return $this->act(__FUNCTION__, func_num_args(), $spec); return $this->act(__FUNCTION__, func_num_args(), $spec);
} }
@ -142,14 +155,14 @@ class Context {
public function editions(array $spec = null) { public function editions(array $spec = null) {
if (isset($spec)) { if (isset($spec)) {
$spec = $this->cleanArray($spec); $spec = $this->cleanIdArray($spec);
} }
return $this->act(__FUNCTION__, func_num_args(), $spec); return $this->act(__FUNCTION__, func_num_args(), $spec);
} }
public function articles(array $spec = null) { public function articles(array $spec = null) {
if (isset($spec)) { if (isset($spec)) {
$spec = $this->cleanArray($spec); $spec = $this->cleanIdArray($spec);
} }
return $this->act(__FUNCTION__, func_num_args(), $spec); return $this->act(__FUNCTION__, func_num_args(), $spec);
} }
@ -169,4 +182,11 @@ class Context {
public function annotated(bool $spec = null) { public function annotated(bool $spec = null) {
return $this->act(__FUNCTION__, func_num_args(), $spec); return $this->act(__FUNCTION__, func_num_args(), $spec);
} }
public function searchTerms(array $spec = null) {
if (isset($spec)) {
$spec = $this->cleanStringArray($spec);
}
return $this->act(__FUNCTION__, func_num_args(), $spec);
}
} }