I'm writing a complex search algorithm that does the searching in tiers. And for two of the tiers I need very weird order clauses which Zend's sql builder simply couldn't handle. Is there a way to tell Zend to just add a string to the order by clause without it trying to interpret and ruin it?
to those wondering, an example of my order by is
IF(Name LIKE '1234 %' OR Name LIKE '% 1234 %' OR Name LIKE '% 1234' OR Code LIKE '1234 %' OR Code LIKE '% 1234 %' OR Code LIKE '% 1234', 1, 0) + IF(Name LIKE 'ASF %' OR Name LIKE '% ASF %' OR Name LIKE '% ASF' OR Code LIKE 'ASF %' OR Code LIKE '% ASF %' OR Code LIKE '% ASF', 1, 0)
it basically counts the number of words in the search string the current record contains and orders by that.
I want to do something like this
$sql = new Sql($this->adapter);
$select = $sql->select();
$select->from('Table');
$select->where($where);
$select->order($orderString);
If the argument of the
order by
clause is a plain string, so it will be considered as just a column name (followed or not by "ASC" or "DESC").A possible solution is to use the
Expression
class. Something like this :