From f9fde2370888cc38b003da0ba0c609e527d0e28f Mon Sep 17 00:00:00 2001 From: "J. King" Date: Fri, 22 Feb 2019 11:13:42 -0500 Subject: [PATCH] Context changes to support basic text searching --- lib/Misc/Context.php | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/lib/Misc/Context.php b/lib/Misc/Context.php index 93e4ac43..fa6241a9 100644 --- a/lib/Misc/Context.php +++ b/lib/Misc/Context.php @@ -34,6 +34,7 @@ class Context { public $labelName; public $labelled = null; public $annotated = null; + public $searchTerms = []; protected $props = []; @@ -52,7 +53,7 @@ class Context { } } - protected function cleanArray(array $spec): array { + protected function cleanIdArray(array $spec): array { $spec = array_values($spec); for ($a = 0; $a < sizeof($spec); $a++) { if (ValueInfo::id($spec[$a])) { @@ -64,6 +65,18 @@ class Context { 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) { return $this->act(__FUNCTION__, func_num_args(), $spec); } @@ -142,14 +155,14 @@ class Context { public function editions(array $spec = null) { if (isset($spec)) { - $spec = $this->cleanArray($spec); + $spec = $this->cleanIdArray($spec); } return $this->act(__FUNCTION__, func_num_args(), $spec); } public function articles(array $spec = null) { if (isset($spec)) { - $spec = $this->cleanArray($spec); + $spec = $this->cleanIdArray($spec); } return $this->act(__FUNCTION__, func_num_args(), $spec); } @@ -169,4 +182,11 @@ class Context { public function annotated(bool $spec = null) { 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); + } }