You are here:  » Changing default search results order

Support Forum



Changing default search results order

Submitted by marco on Sat, 2007-06-16 14:03 in

Hi,

The default presentation of search results is on relevence.
How can i change this to rating?

Thanks,
Marco.

Submitted by support on Sat, 2007-06-16 14:07

Hi Marco,

In search.php you will find the following code on line 8:

$sort = (isset($_GET["sort"])?$_GET["sort"]:"relevance");

Change this to:

$sort = (isset($_GET["sort"])?$_GET["sort"]:"rating");

That should do the trick!

Cheers,
David.

Submitted by marco on Sat, 2007-06-16 14:27

It did the trick! Thanks for your quick response,

Marco.

Submitted by babyuniverse on Fri, 2007-09-07 12:08

Can i also set these search results to be in random order?
I would like random to be the first result and then user can sort by other fields.

Submitted by support on Fri, 2007-09-07 12:28

Hi,

Yes - random sort can be easily added (and made to be the default). In search.php, make the following changes:

After the following EXISTING code:

$orderByDefault = array();
Add the following NEW code:
$orderByDefault["rand"] = "RAND()";

After the following EXISTING code:

$orderByFullText = array();
Add the following NEW code:
$orderByFullText["rand"] = "RAND()";

After the following EXISTING code:

$sortRelevance = ($sort=="relevance"?"<strong>".translate("Relevance")."</strong>":"<a href='".$sortHREF."relevance'>".translate("Relevance")."</a>");
Add the following NEW code:
$sortRand = ", ".($sort=="rand"?"<strong>".translate("Random")."</strong>":"<a href='".$sortHREF."rand'>".translate("Random")."</a>");

Modify the following code:

$banner["h3"] = translate("Order by").": ".$sortRelevance.$sortRating." | ".translate("Price").": ".$sortPriceAsc.", ".$sortPriceDesc;
As follows:
$banner["h3"] = translate("Order by").": ".$sortRelevance.$sortRand.$sortRating." | ".translate("Price").": ".$sortPriceAsc.", ".$sortPriceDesc;

Finally, to make random the default sort, look for the following code at the top of search.php (line 8 in the distribution):

  $sort = (isset($_GET["sort"])?$_GET["sort"]:"relevance");

...and change this to:

  $sort = (isset($_GET["sort"])?$_GET["sort"]:"rand");

Cheers,
David.

Submitted by babyuniverse on Sat, 2007-09-08 04:51

thanks David - this works great