aboutsummaryrefslogtreecommitdiff
path: root/classes/IsisFinder.php
diff options
context:
space:
mode:
authorSilvio <silvio@devlet.com.br>2010-08-20 18:49:49 -0300
committerSilvio <silvio@devlet.com.br>2010-08-20 18:49:49 -0300
commit0956138b3dae192c3bb8db2b769e7526d1ec489e (patch)
tree92332864a3f747fa68dd83407ca85527fcd07b81 /classes/IsisFinder.php
parente713d07bb78d6160fcb428a9f7c39891b4b07ef0 (diff)
downloadcinisis-0956138b3dae192c3bb8db2b769e7526d1ec489e.tar.gz
cinisis-0956138b3dae192c3bb8db2b769e7526d1ec489e.tar.bz2
Adding simple search app
Diffstat (limited to 'classes/IsisFinder.php')
-rw-r--r--classes/IsisFinder.php122
1 files changed, 122 insertions, 0 deletions
diff --git a/classes/IsisFinder.php b/classes/IsisFinder.php
index 7f7405d..a4da3a0 100644
--- a/classes/IsisFinder.php
+++ b/classes/IsisFinder.php
@@ -94,4 +94,126 @@ class IsisFinder extends IsisConnector {
return FALSE;
}
+
+ /**
+ * Search the next match inside a result.
+ *
+ * @param $field
+ * Field data.
+ *
+ * @param $item
+ * Item name (main field or subfield).
+ *
+ * @param $search
+ * Search token.
+ *
+ * @param $entry
+ * Start entry number to begin the search.
+ *
+ * @param $match
+ * Set to false do find the next result where the
+ * item has not the token specified in $search.
+ */
+ public function nextResult($field, $item, $search, $entry = 1, $match = TRUE) {
+ do {
+ // Get the next entry that has the field/subfield we'll look at.
+ if ($item = 'main') {
+ $next = $this->nextField($field, $entry);
+ }
+ else {
+ $next = $this->nextSubfield($field, $item, $entry);
+ }
+
+ // Check if there's a next matching field/subfield.
+ if ($next === FALSE) {
+ break;
+ }
+ else {
+ list($entry, $result) = $next;
+ }
+
+ // Search for any occurrence.
+ foreach (new IsisRowIterator($this, $field) as $row) {
+ if ($item = 'main') {
+ $verify = $this->matchMainItem($field, $row, $search, $match);
+ }
+ else {
+ $verify = $this->matchSubfield($field, $row, $search, $match);
+ }
+
+ if ($verify !== FALSE)
+ {
+ return array($entry, $result);
+ }
+ }
+ }
+ while ($entry++);
+ }
+
+ /**
+ * Check if a main item match a given value.
+ *
+ * @param $field
+ * Field data.
+ *
+ * @param $row
+ * Row number.
+ *
+ * @param $search
+ * Search token.
+ *
+ * @param $match
+ * Set to false do find the next result where the
+ * item has not the token specified in $search.
+ *
+ * @return
+ * True if match, false otherwise.
+ */
+ public function matchMainItem($field, $row, $search, $match) {
+ if ($this->getMainItem($field, $row) == $search) {
+ if ($match) {
+ return TRUE;
+ }
+ }
+ elseif (!$match) {
+ return TRUE;
+ }
+
+ return FALSE;
+ }
+
+ /**
+ * Check if a subfield match a given value.
+ *
+ * @param $field
+ * Field data.
+ *
+ * @param $subfield
+ * Subfield name.
+ *
+ * @param $row
+ * Row number.
+ *
+ * @param $search
+ * Search token.
+ *
+ * @param $match
+ * Set to false do find the next result where the
+ * item has not the token specified in $search.
+ *
+ * @return
+ * True if match, false otherwise.
+ */
+ public function matchSubfield($field, $subfield, $row, $search, $match) {
+ if ($this->getSubfield($field, $subfield, $row) == $search) {
+ if ($match) {
+ return TRUE;
+ }
+ elseif (!$match) {
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+ }
}