Example #1
0
 /**
  * Convert a QueryGroup object to a query string.
  *
  * @param QueryGroup $query QueryGroup to convert
  *
  * @return array
  */
 protected function queryGroupToArray(QueryGroup $query)
 {
     $nextLevel = $query->getQueries();
     $op = $nextLevel[0]->getOperator();
     $negated = $nextLevel[0]->isNegated();
     $parts = [];
     foreach ($nextLevel[0]->getQueries() as $q) {
         $index = $q->getHandler();
         //$op = $q->getOperator();
         $lookfor = $q->getString();
         $parts[] = compact('index', 'op', 'negated', 'lookfor');
     }
     return $parts;
 }
Example #2
0
 /**
  * Convert a QueryGroup object to a query string.
  *
  * @param QueryGroup $query QueryGroup to convert
  *
  * @return string
  */
 protected function queryGroupToString(QueryGroup $query)
 {
     $groups = $excludes = [];
     foreach ($query->getQueries() as $params) {
         // Advanced Search
         if ($params instanceof QueryGroup) {
             $thisGroup = [];
             // Process each search group
             foreach ($params->getQueries() as $group) {
                 // Build this group individually as a basic search
                 $thisGroup[] = $this->abstractQueryToString($group);
             }
             // Is this an exclusion (NOT) group or a normal group?
             if ($params->isNegated()) {
                 $excludes[] = join(" OR ", $thisGroup);
             } else {
                 $groups[] = join(" " . $params->getOperator() . " ", $thisGroup);
             }
         } else {
             // Basic Search
             $groups[] = $this->queryToString($params);
         }
     }
     // Put our advanced search together
     $queryStr = '';
     if (count($groups) > 0) {
         $queryStr .= "(" . join(") " . $query->getOperator() . " (", $groups) . ")";
     }
     // and concatenate exclusion after that
     if (count($excludes) > 0) {
         $queryStr .= " NOT ((" . join(") OR (", $excludes) . "))";
     }
     return $queryStr;
 }
Example #3
0
 /**
  * Convert a QueryGroup object to a query string.
  *
  * @param QueryGroup $query QueryGroup to convert
  *
  * @return array
  */
 protected function queryGroupToArray(QueryGroup $query)
 {
     $groups = [];
     foreach ($query->getQueries() as $params) {
         // Advanced Search
         if ($params instanceof QueryGroup) {
             // Process each search group
             foreach ($params->getQueries() as $q) {
                 // Build this group individually as a basic search
                 $op = $q->getOperator();
                 if ($params->isNegated()) {
                     $op = 'NOT';
                 }
                 $grp = $this->queryToEdsQuery($q, $op);
                 $groups[] = $grp;
             }
         } else {
             // Basic Search
             $groups[] = $this->queryToEdsQuery($params);
         }
     }
     return $groups;
 }
Example #4
0
 /**
  * Support method for fixBadQuery().
  *
  * @param QueryGroup $query Query to fix
  *
  * @return bool|QueryGroup  Fixed query, or false if no solution is found.
  */
 protected function fixBadQueryGroup(QueryGroup $query)
 {
     $newQueries = [];
     $fixed = false;
     // Try to fix each query in the group; replace any query that needs to
     // be changed.
     foreach ($query->getQueries() as $current) {
         $fixedQuery = $this->fixBadQuery($current);
         if ($fixedQuery) {
             $fixed = true;
             $newQueries[] = $fixedQuery;
         } else {
             $newQueries[] = $current;
         }
     }
     // If any of the queries in the group was fixed, we'll treat the whole
     // group as being fixed.
     if ($fixed) {
         $query->setQueries($newQueries);
         return $query;
     }
     // If we got this far, nothing was changed -- report failure:
     return false;
 }