/** * merge one MingoCriteria instance into this MingoCriteria instance * * @since 1-3-12 * @param \MingoCriteria $criteria the criteria to merge into this one * @return self */ public function merge(MingoCriteria $criteria) { $this->command_symbol = $criteria->getCommandSymbol(); $this->map_where = $criteria->getWhere(); $this->map_sort = $criteria->getSort(); $this->field_map = $criteria->getFields(); if ($criteria->hasLimit()) { $this->setLimit($criteria->getLimit()); } //if if ($criteria->hasPage()) { $this->setPage($criteria->getPage()); } //if if ($criteria->hasOffset()) { $this->setOffset($criteria->getOffset()); } //if return $this; }
/** * this should be used to take the generic $where_criteria and turn it into something * the interface can use (eg, for a SQL interface, the $where_criteria would be turned * into a valid SQL string). * * currently not supported: 'near' * * @link http://lucene.apache.org/java/2_4_0/queryparsersyntax.html * * @param MingoTable $table * @param MingoCriteria $where_criteria * @return mixed return whatever you want, however you want to return it, whatever is easiest for you */ protected function normalizeCriteria(MingoTable $table, MingoCriteria $where_criteria = null) { $ret_map = array(); $ret_map['where_criteria'] = $where_criteria; $ret_map['limit'] = array(0, 0); $query = new Zend_Search_Lucene_Search_Query_Boolean(); if ($where_criteria !== null) { // add all the required search keys and their values... $criteria_where = $where_criteria->getWhere(); foreach ($criteria_where as $name => $map) { $subquery = null; $where_sql = ''; $where_val = array(); $required = true; if (is_array($map)) { $command = $where_criteria->normalizeCommand('in'); if (isset($map[$command])) { $subquery = $this->handleMulti($name, $map[$command], true); $required = true; } //if // according to: http://lucene.apache.org/java/2_4_0/queryparsersyntax.html // Lucene cannot do nin queries without something before it (eg, foo:1 NOT foo(2 3) but // (NOT foo(2 3) doesn't work) $command = $where_criteria->normalizeCommand('nin'); if (isset($map[$command])) { $subquery = $this->handleMulti($name, $map[$command], false); $required = false; } //if $command = $where_criteria->normalizeCommand('not'); if (isset($map[$command])) { $subquery = $this->handleEquals($name, $map[$command], false); } //if $command1 = $where_criteria->normalizeCommand('gte'); $command2 = $where_criteria->normalizeCommand('lte'); if (isset($map[$command1]) && isset($map[$command2])) { $subquery = $this->handleRange($name, $map[$command1], $map[$command2], true); } //if if (isset($map[$command1])) { $subquery = $this->handleRange($name, $map[$command1], null, true); } //if if (isset($map[$command2])) { $subquery = $this->handleRange($name, null, $map[$command2], true); } //if $command = $where_criteria->normalizeCommand('gt'); if (isset($map[$command])) { $subquery = $this->handleRange($name, $map[$command], null, false); } //if $command = $where_criteria->normalizeCommand('lt'); if (isset($map[$command])) { $subquery = $this->handleRange($name, null, $map[$command], false); } //if } else { if ($name === '_q') { $subquery = Zend_Search_Lucene_Search_QueryParser::parse($map); } else { $subquery = $this->handleEquals($name, $map, true); } //if/else } //if/else if ($subquery) { $query->addSubquery($subquery, $required); } //method } //foreach // limit offset... $offset = $where_criteria->getOffset(); $ret_map['limit'] = array($where_criteria->getLimit() + $offset, $offset); // caution from docs: // Please use caution when using a non-default search order; // the query needs to retrieve documents completely from an index, // which may dramatically reduce search performance. // http://framework.zend.com/manual/en/zend.search.lucene.searching.html#zend.search.lucene.searching.sorting if ($where_criteria->hasSort()) { $criteria_sort = $where_criteria->getSort(); $sort_list = array(); // build the sort sql... foreach ($criteria_sort as $name => $direction) { $sort_list[] = $name; $sort_list[] = SORT_REGULAR; ///$sort_list[] = SORT_STRING; ///SORT_NUMERIC; $sort_list[] = $direction > 0 ? SORT_ASC : SORT_DESC; } //foreach $ret_map['sort'] = $sort_list; } //if } //if $ret_map['query'] = $query; return $ret_map; }