Closed gonzasylv closed 4 years ago
Just change the default option to $queryBuilder->addOrderBy("l.createdAt", "DESC");
@gonzasylv , you should put it as the first order by in your query, which will render it before the other ordinators you will use... so, in your ListingSearchManager.php, in the search method you could put the ->addOrderBy('l.createdAt', 'desc');
before switch ($listingSearchRequest->getSortBy()) { case 'price': $queryBuilder->orderBy("l.price", "ASC"); break; case 'distance': $queryBuilder->orderBy("distance", "ASC"); break; default: $queryBuilder->orderBy("distance", "ASC"); break; }
//Order
$queryBuilder->addOrderBy('l.createdAt', 'desc');
switch ($listingSearchRequest->getSortBy()) {
case 'price':
$queryBuilder->orderBy("l.price", "ASC");
break;
case 'distance':
$queryBuilder->orderBy("distance", "ASC");
break;
default:
$queryBuilder->orderBy("distance", "ASC");
break;
}
The result is the same @SchulzWill :/
The result of my search gives: http://imgur.com/wBn7UPUl.png , it puts "Marrakech" in the first search results while my ip is from Casablanca
Have you seen how the query is being mounted? The first one is that the order clauses will be inputted together to the database. You can activate your MySql trace to see how the query is being executed there and identify the order used to input your ordenation
Hello, @gonzasylv . This depends on your MySQL version. You could try changing your MYSQL config as explained in here: https://stackoverflow.com/a/25080306/3618037
hi @cocolabssas ,
I would like the result of a search to be in descending order, that is to say that the result is from recent articles to older ones.
i found:
src/Cocorico/CoreBundle/Controller/Frontend/ListingSearchController.php
It seems to be sorted by distance
src/Cocorico/CoreBundle/Model/Manager/ListingSearchManager.php
How I can simply modify the code so that the search result is from the most recent to the oldest as for the list of ads on the home page ?
Thanks