You are here:  » Influence the Relevance Sort Sequence?


Influence the Relevance Sort Sequence?

Submitted by gregor on Sat, 2014-12-06 05:47 in

I have a couple merchants that I want to keep, but they have quite a few missing images in their feeds. I would like to make sure these products do not show up at the top of my category or brand search results pages. Is there a way to influence the sort when the search results page first comes up (with Relevance sort)? How can I push a few of these merchants to the bottom of the list?

Thank you for any ideas you might have

Submitted by support on Sat, 2014-12-06 11:53

Hello Gregor,

Sure - in search.php first of all in search.php look for the following code at line 74:

  $orderByDefault["rating"] = "rating DESC";

...and REPLACE with:

  $orderByDefault["relevance"] = "relevance DESC";
  $orderByDefault["rating"] = "rating DESC";

And then look for the following code at line 291:

    if (isset($orderBySelection[$sort]))
    {
      $sql .= " ORDER BY ".$orderBySelection[$sort];
    }

...and REPLACE with:

    if (isset($orderBySelection[$sort]))
    {
      if ($sort == "relevance")
      {
        $sqlCase = "CASE merchant";
        $merchants = array("Merchant 1","Merchant 2");
        foreach($merchants as $merchant)
        {
          $sqlCase .= " WHEN '".database_safe($merchant)."' THEN 0 ";
        }
        $sqlCase .= " ELSE 1 END as relevance ";
        $sql = str_replace("minPrice","minPrice,".$sqlCase,$sql);
      }
      $sql .= " ORDER BY ".$orderBySelection[$sort];
    }

...replacing Merchant 1, Merchant 2 as required and this will create a virtual "relevance" field with the merchants listed ranked lower than those not which should do the trick!

Cheers,
David.
--
PriceTapestry.com

Submitted by gregor on Sat, 2014-12-06 14:26

Thank you David! It works. With the DESC sort it was sorting the bad merchants to the top instead of the bottom, so I swapped the 0 and the 1 and it now sorts them to the bottom.

I would like to figure out a way to drop the products with missing images, but for now this will be a great help. My search pages will not be littered with missing images.

Thanks again!

Submitted by support on Sun, 2014-12-07 09:27

Hi Gregor,

Glad that's working for you! - 0/1 sense corrected above.

Regarding dropping records with no image URL, you could use a Drop Record RegExp filter attached to the Image URL field with the match expression:

/^$/

The "/" characters are the regular expression delimiters, "^" is the beginning of line marker and "$" the end of line marker, so the above expression will only match an empty field.

If you need to handle broken images they can be replaced on error by adding the following attribute to the image tags in your html/ files:

onerror='JavaScript:this.src="/images/noimage.gif"'

...where /images/noimage.gif is the absolute path to a replacement image file you wish to use in case of broken images.

Cheers,
David.
--
PriceTapestry.com