Jump to content


Corporate Sponsors


Latest News: (loading..)

- - - - -

[Tip] Strip plural from search terms - more accurate results


  • You cannot reply to this topic
10 replies to this topic

#1 Paul_w

  • Community Member
  • 102 posts
  • Real Name:Paul Whiter
  • Location:Northamptonshire, UK

Posted 10 May 2003, 21:32

On my own site I have observed several times now, people searching for products in the plural, e.g: 'plugs' or 'gaskets' etc etc

I list my products by single item name eg: 900 (79 - 92) spark plug - BP7 ES

It seems that if somebody searches in the plural for 'spark plugs' an empty result set is brought up by the search facility, consequently the potential customer thinks I don't sell spark plugs, this is obviously not good.......

So I have a quick fix below.

This code addition will strip an 's' off the end of the search term entered if it contains one. The good thing is that even if the 's' should be there the search will still match the correct terms due to the in-built partial matching facility.

The code:

In advanced_search_result.php at the top, just above:



  require('includes/application_top.php');



ADD



if(isset($_GET['keywords']) && $_GET['keywords'] != ''){

 	 $pwstr_check = strtolower(substr($_GET['keywords'], strlen($_GET['keywords'])-1, strlen($_GET['keywords'])));

 	 if($pwstr_check == 's'){

    $pwstr_replace = substr($_GET['keywords'], 0, strlen($_GET['keywords'])-1);

    header('location: ' . $_SERVER['PHP_SELF'] . '?keywords=' . $pwstr_replace . '&search_in_description=1');

    exit;

 	 } 

}

Hopefully this will help others.

#2 Paul_w

  • Community Member
  • 102 posts
  • Real Name:Paul Whiter
  • Location:Northamptonshire, UK

Posted 11 May 2003, 06:14

A quick change to the code to make it more compliant with osC standards, namely to use the tep_href_link() function and so avoid losing any sessions...

if(isset($_GET['keywords']) && $_GET['keywords'] != ''){

 	 $pwstr_check = strtolower(substr($_GET['keywords'], strlen($_GET['keywords'])-1, strlen($_GET['keywords'])));

 	 if($pwstr_check == 's'){

       $pwstr_replace = substr($_GET['keywords'], 0, strlen($_GET['keywords'])-1);

       header('location: ' . tep_href_link( FILENAME_ADVANCED_SEARCH_RESULT , 'keywords=' . urlencode($pwstr_replace) . '&search_in_description=1' ));

       exit;

 	 }

}


#3 JenRed

  • Community Member
  • 249 posts
  • Real Name:Jen Honner
  • Location:Australia

Posted 13 May 2003, 04:52

What a good idea! Thanks for thinking of it.

I added your second bit of code and got a "blank" white page when searching, then tried the first bit of code and it worked beautifully.

thanks

Jen
I haven't lost my mind - I have it backed up on disk somewhere.

#4 JenRed

  • Community Member
  • 249 posts
  • Real Name:Jen Honner
  • Location:Australia

Posted 13 May 2003, 04:55

Any ideas how to set it up to cater for something like "dresses" which then gets stripped to "dresse" and isn't found?

Jen
I haven't lost my mind - I have it backed up on disk somewhere.

#5 Paul_w

  • Community Member
  • 102 posts
  • Real Name:Paul Whiter
  • Location:Northamptonshire, UK

Posted 13 May 2003, 10:31

Quote

Any ideas how to set it up to cater for something like "dresses" which then gets stripped to "dresse" and isn't found?

Jen

Did you actually try searching for dresses? It should still match that term even with the final 's' stripped off due to the inbuilt partial matching of search words.

Paul

#6 JenRed

  • Community Member
  • 249 posts
  • Real Name:Jen Honner
  • Location:Australia

Posted 13 May 2003, 11:34

Yeah I did and it looks for "dresse" and doesn't find "dress"

I just did a search on "dress" and it looks for "dre" - and finds the dresses.

Try it here: www.redinstead.com.au

Jen
I haven't lost my mind - I have it backed up on disk somewhere.

#7 Paul_w

  • Community Member
  • 102 posts
  • Real Name:Paul Whiter
  • Location:Northamptonshire, UK

Posted 13 May 2003, 12:13

Quote

Yeah I did and it looks for "dresse" and doesn't find "dress"

I just did a search on "dress" and it looks for "dre" - and finds the dresses.

Try it here: www.redinstead.com.au

Jen

It wouldn't match 'dress' when searching for 'dresses' or 'dresse' so this is normal, unfortunately it is not possible to cater for all possibilities or you risk causing unforeseen problems.

With regard to the dress becoming dre, this could be fixed to only strip the one 's' if I add a flag to the redirect url. But it is still going to match what you want it to anyway, only problem is it may possibly bring up too many results.

I have actually written a Google style script whereby I can swap out search words for any replacement I wish and present the user with an option : 'Did you mean: .xxxxxxx... ' they can then click on this to re-search on the new phrase, if this is used in conjunction with a script to log all search terms used, then you can fine tune your search facility over time to dish up correct results for most searches. When I get the time I'll try and package this up as a contribution.

I think with these few enhancements the search facility for osC is very powerful indeed.

#8 JenRed

  • Community Member
  • 249 posts
  • Real Name:Jen Honner
  • Location:Australia

Posted 13 May 2003, 12:50

Quote

unfortunately it is not possible to cater for all possibilities or you risk causing unforeseen problems.

I understand! Just wanted to see what your mind could do with it :)

The Google style script sounds great - would love to see it as a contribution. Will you post here when it is done?

thanks

Jen
I haven't lost my mind - I have it backed up on disk somewhere.

#9 JenRed

  • Community Member
  • 249 posts
  • Real Name:Jen Honner
  • Location:Australia

Posted 13 May 2003, 13:00

Quote

if this is used in conjunction with a script to log all search terms used, then you can fine tune your search facility over time to dish up correct results for most searches

This reminded me of a Mod I had seen but not installed:
http://www.oscommerce.com/community/contributions,375

Do you know of it? It was written in March 2002 so I haven't gotten around to seeing if it works with newer snapshots.

Jen
I haven't lost my mind - I have it backed up on disk somewhere.

#10 JenRed

  • Community Member
  • 249 posts
  • Real Name:Jen Honner
  • Location:Australia

Posted 13 May 2003, 13:00

Quote

if this is used in conjunction with a script to log all search terms used, then you can fine tune your search facility over time to dish up correct results for most searches

This reminded me of a Mod I had seen but not installed:
http://www.oscommerce.com/community/contributions,375

Do you know of it? It was written in March 2002 so I haven't gotten around to seeing if it works with newer snapshots.

Jen
I haven't lost my mind - I have it backed up on disk somewhere.

#11 wizardsandwars

  • Community Member
  • 4,476 posts
  • Real Name:Chris Bradley

Posted 13 May 2003, 15:21

Paul, I'd be very interested in seeing this contribution.

Please let me know if I can be of assistance.
-------------------------------------------------------------------------------------------------------------------------
NOTE: As of Oct 2006, I'm not as active in this forum as I used to be, but I still work with osC quite a bit.
If you have a question about any of my posts here, your best bet is to contact me though either Email or PM in my profile, and I'll be happy to help.