Running a query using select configuration
In addition to building the
select
query through functions, it is also possible to build a select
query using an array of key-value pairs. Here is a selectconfig
query with parameters for the preceding query:
$selectConfig = array( 'query' => 'cat:book AND author:Martin', 'start' => 3, 'rows' => 3, 'fields' => array('id','name','price','author'), 'sort' => array('price' => 'asc') );
We can also add multiple sorting fields as an array using the addSorts(array $sorts)
function. To sort by price and then by score, we can use the following parameters in the addSorts()
function:
$query->addSorts(array('price'=>'asc','score'=>'desc'));
We can use the getQuery()
function to get the query parameter. And the getSorts()
function to get the sorting parameter from our select query. We can also use the
removeField($fieldStr)
and removeSort($sortStr)
functions to remove parameters from the fields list and sort list of our query...