/** * Comparison function for query terms. Field names are compared first, * then field terms are compared case insensitively. * * @param QueryTerm $a Query term A. * @param QueryTerm $b Query term B. * @return integer 1, -1 or 0 depending on comparison result. */ public static function cmp(QueryTerm $a, QueryTerm $b) { if ($a->getUserField() > $b->getUserField()) { return 1; } if ($a->getUserField() < $b->getUserField()) { return -1; } if (strtolower($a->getTerm()) > strtolower($b->getTerm())) { return 1; } if (strtolower($a->getTerm()) < strtolower($b->getTerm())) { return -1; } return 0; }
/** * Return a QueryTerm object from the list. * * @param QueryTerm|string $query_term QueryTerm object or term string. * @return QueryTerm|null Matching QueryTerm object, or null if none found. */ public function getQueryTerm($query_term) { if (is_string($query_term)) { $query_term = QueryTerm::fromString($query_term, $this->_user_sph_map); } if ($query_term instanceof QueryTerm) { $hash = $query_term->toHash(); if (isset($this->_qts[$hash])) { return $this->_qts[$hash]; } } return null; }