You are here:  » Related items (or 'Did you mean:') on noresults.php

Support Forum



Related items (or 'Did you mean:') on noresults.php

Submitted by matthew on Tue, 2008-03-18 13:58 in

Hi all,

Well done on a great product David, it's really taken loads of leg-work away from what I wanted to achieve. Nice one.

After managing to get this far (www.pricebeep.co.uk) using Price Tapestry, I think I've finally worn my brain out.

What I'd like is to show is a related items style table or Google style 'Did you mean:' suggestion, for when there are no search results.

For example, a search for 'LCD 47' should return 47inch LCD TVs, but it doesn't (a full text search limitation?), so I'd like the noresults.php page to show any similar items that Price Tapestry can find.

Any thoughts would be great.

Matt

Submitted by support on Tue, 2008-03-18 14:08

Hello Matt,

That's a great looking site!

Regarding the search results - yes that is a limitation in some respects of the full text search method. I recently made a significant improvement to the non-full text search mode, which for smaller sites may return better results than the full text index - particularly where you have products with short keywords, digits or model numbers. Basically, anything search.php, you can extract the recent modifications by copying the default: section of the switch($parts[0]) statement down to the closing break; (lines 62 to 102) and then replacing the same section in your existing file with the new code.

If you're not sure where to make the changes, feel free to email me your search.php and I'll make the changes for you (reply to your reg code or forum registration email is the easiest way to get me)

This should return any (even partly) relevant results, which may remove the need for a "Did you mean..." section...

Cheers,
David.

Submitted by matthew on Tue, 2008-03-18 19:39

Cool, thanks for the help.

I've updated the search.php and it's much better now.

I'm logging all the satisfied searches and un-satisfied searches, so it'll be interesting to see how they pan out.

Do you normally send an email when you release an update to the code?

Matt

Submitted by support on Tue, 2008-03-18 19:42

Hi Matt,

Updates are rare (intentionally, because most users heavily customise their sites making upgrading somewhat awkward); rather I normally document new features as mods through the forum!

Cheers,
David.

Submitted by Kelly and Stuart on Tue, 2008-04-29 21:25

Hi David - I too am interested in a "Did you mean?" section. I have one site in particular that google has indexed and now the titles have changed and so the "product not found" is coming up on loads of items that feature well naturally in google.

I have added the code mentioned in 1495

header("Location: ".$config_baseHREF."search.php?q=".urlencode($q)); exit();

it has worked for some but not others, for example:
http://www.petprice.co.uk/search.php?q=Skudo+Electronic+Flea+amp+Tick+Repeller comes up not found with no alternatives listed, yet remove the "amp" from the search and voila there is the exact product.
http://www.petprice.co.uk/search.php?q=Skudo+Electronic+Flea+Tick+Repeller

Can you explain a little more how this would can be implemented, or if there is any other way around it?

many thanks
kelly

Submitted by Kelly and Stuart on Wed, 2008-04-30 01:46

Also....

I noticed there was a noresults.php. Can this be utilised to bring up a list of 'related to the search' products?

if yes, how?

Cheers for you help

Kelly

Submitted by support on Wed, 2008-04-30 07:36

Hi Kelly,

The code you have added is what most people who have done this are using; the issue here is caused by the fact that as "amp" is less than 4 characters long the redirected search is using the basic search method which looks for all words; whereas the full text search method is able to return results without certain words.

What I think might help is, in the redirect code; check the query for any words less than 4 characters and if there are any remove them - but if all words are under 4 characters then leave the query untouched. For example, instead of:

  header("Location: ".$config_baseHREF."search.php?q=".urlencode($q));
  exit();

...try this:

  $shortwords = array();
  $words = explode(" ",$q);
  foreach($words as $word)
  {
    if (strlen($word)<4)
    {
      $shortwords[] = $word;
    }
  }
  if (count($shortwords) < count($words))
  {
    foreach($shortwords as $shortword)
    {
      unset($words[$shortword]);
    }
  }
  $q = implode(" ",$words);
  header("Location: ".$config_baseHREF."search.php?q=".urlencode($q));
  exit();

Cheers,
David.

Submitted by Kelly and Stuart on Wed, 2008-04-30 10:56

Hi David

Thanks for the reply only it doesn't seem to have made any impact.

Do you have any other tricks up your sleeve?

Here is another example for you

search.php?q=Hagen+Aqua+Fizz+1quot+A+960
is not found. The correct product is now
search.php?q=Hagen+Aqua+Fizz+A+960

Just need something there on the page to stop people bouncing.
thanks K

Submitted by support on Wed, 2008-04-30 12:23

Hi Kelly,

Could you email me a link to an example "not found" page and a copy of your products.php so I can take a look and have a think about the options...

Cheers,
David.

Submitted by Kelly and Stuart on Wed, 2008-04-30 17:08

We often have probs with people getting our emails - did you get it? its from smart-trades.co.uk
Kelly

Submitted by support on Wed, 2008-04-30 17:11

Not yet, sorry Kelly (I checked my spam folder).

Please use the address on this page...

Cheers,
David.

Submitted by Kelly and Stuart on Thu, 2008-05-01 10:24

If anyone else is looking for this, this is the amended code that David did for me. If the actual product isn't featured, very relevant alternatives come up if you insert this code as directed above:

<?php $shortwords = array();
      $words = explode(" ",$q);
      foreach($words as $word)
      {
        if (strlen($word)<4)
        {
          $shortwords[$word] = 1;
        }
      }
      if (count($shortwords))
      {
        $newwords = array();
        foreach($words as $word)
        {
          if (!$shortwords[$word]) $newwords[] = $word;
        }
        $q = implode(" ",$newwords);
        header("Location: ".$config_baseHREF."search.php?q=".urlencode($q));
        exit();
      }
      else
      {
        $banner["h2"] .= "(".translate("product not found").")";
      }
?>

Thanks you so much David

Kelly

Submitted by paul30 on Sat, 2008-09-27 06:53

Sorry I got lost... - Where is that have to be pasted to?

Thanks
Pasha

Submitted by support on Sat, 2008-09-27 08:14

Hi Pasha,

The above code should be inserted in place of the following code:

$banner["h2"] .= "(".translate("no results found").")";

...which is on line 151 of the distribution version of search.php. I have just modified the above to ensure that the redirect only happens if there are short words in the query, otherwise I think it would go into a redirect loop...!

Cheers,
David.

Submitted by paul30 on Sat, 2008-09-27 09:22

Yep!! - That is initially why I initially asked the question! - I was getting browser time outs because of the loops :)

Thanks.