Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

RELEASED: Search Results with Highlight v1.0


Druide

Recommended Posts

MOD: Search Results with Highlight v1.0

By: Robert Hellemans

 

 

NOTE: this mod is Case Sensitive !!!

 

PREVIEW at LIVE store: http://www.ruddlesmills.com/advanced_searc...s=Case&x=30&y=7

LIVE STORE !!!: http://www.ruddlesmills.com

no fake orders, you will be billed !

 

Difficulty: EASY INSTALL

Time: Less then 1 minute

 

Files to change: 1

catalog/includes/modules/product_listing.php

 

Admin:

to set a different background color for the searchresults,

look at ADMIN > configuration > My Store > Search Result Highlight Color

you can set to colorname like: yellow

or this way: #FFFF00

 

What does it do ?:

This little but effective MOD will Highlight the keywords that you have given in the search query.

I made it so that it only checks the fields: products_name & products_model

which should be more then enough because not many people have their descriptions listed in product_listing.php

 

Let's start to have some fun !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

 

insert into your database:

INSERT INTO configuration VALUES ('', 'Search Result Highlight Color', 'SEARCH_RESULT_BACKGROUND_COLOR', 'yellow', 'This will be the background color from the matching keywords in searchresults<br>This is Case Sensitive !', 1, 7000, NULL, '2003-03-18 11:05:37', NULL, NULL);

 

find in catalog/includes/modules/product_listing.php

 

          case 'PRODUCT_LIST_MODEL':

           $lc_text = ' ' . $listing_values['products_model'] . ' ';

           break;

         case 'PRODUCT_LIST_NAME':

           if ($HTTP_GET_VARS['manufacturers_id']) {

             $lc_text = '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'manufacturers_id=' . $HTTP_GET_VARS['manufacturers_id'] . '&products_id=' . $listing_values['products_id'], 'NONSSL') . '">' . $listing_values['products_name'] . '</a>';

           } else {

             $lc_text = ' <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing_values['products_id']) . '">' . $listing_values['products_name'] . '</a> ';

           }

           break;

 

REPLACE WITH:

 

          case 'PRODUCT_LIST_MODEL':

 $fldname = $listing_values['products_model'];

 if ($HTTP_GET_VARS['keywords'] != "" )

	 {

	 $string_to_split = $HTTP_GET_VARS['keywords'];

	 $tok = split(" ", $string_to_split);

	 $size = sizeof($tok);

	 for ($i = 0; $i < $size; $i++) 

	 $fldname = str_replace($tok[$i], '<span style="background-color: ' . SEARCH_RESULT_BACKGROUND_COLOR . '">' . $tok[$i] . '</span>', $fldname); 

	 }          

           $lc_text = ' ' . $fldname . ' ';

           break;

         case 'PRODUCT_LIST_NAME':

           if ($HTTP_GET_VARS['manufacturers_id']) {

             $lc_text = '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'manufacturers_id=' . $HTTP_GET_VARS['manufacturers_id'] . '&products_id=' . $listing_values['products_id'], 'NONSSL') . '">' . $listing_values['products_name'] . '</a>';

           } else {

 $fldname = $listing_values['products_name'];

 if ($HTTP_GET_VARS['keywords'] != "" )

	 {

	 $string_to_split = $HTTP_GET_VARS['keywords'];

	 $tok = split(" ", $string_to_split);

	 $size = sizeof($tok);

	 for ($i = 0; $i < $size; $i++) 

	 $fldname = str_replace($tok[$i], '<span style="background-color: ' . SEARCH_RESULT_BACKGROUND_COLOR . '">' . $tok[$i] . '</span>', $fldname); 

	 }

             $lc_text = ' <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing_values['products_id']) . '">' . $fldname . '</a> ';

           }

           break;

 

i couldn't make it easier for you all, sorry for that ;)

 

Let me know if you liked it !

Robert

 

We all need to learn it once, how hard it may seem when you look at it, also you will master it someday ;)

Link to comment
Share on other sites

Hi.

I like your feature, I am using version 2.2

Loaded sql fine but on a product search all descriptions dissapear.

Is it possible to email me a copy of your product_listing.php

Maybee while pasting the code something goes wrong.

Thanks

Luis

[email protected]

 

 

the code is correct, i have verified it

 

i think one of your installed MODS is making the error

 

It's just NOT POSSIBLE that the code is not right, sorry...

 

I am just 110% sure about this one

 

---------------

 

check your original file, i hope you did a backup (you should do that ANY TIME you install a MOD)

 

here is my piece of code to verify yours

 

        switch ($column_list[$col]) {

         case 'PRODUCT_LIST_MODEL':

 $fldname = $listing_values['products_model'];

 if ($HTTP_GET_VARS['keywords'] != "" )

	 {

	 $string_to_split = $HTTP_GET_VARS['keywords'];

	 $tok = split(" ", $string_to_split);

	 $size = sizeof($tok);

	 for ($i = 0; $i < $size; $i++) 

	 $fldname = str_replace($tok[$i], '<span style="background-color: ' . SEARCH_RESULT_BACKGROUND_COLOR . '">' . $tok[$i] . '</span>', $fldname); 

	 }          

           $lc_text = ' ' . $fldname . ' ';

           break;

         case 'PRODUCT_LIST_NAME':

           if ($HTTP_GET_VARS['manufacturers_id']) {

             $lc_text = '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'manufacturers_id=' . $HTTP_GET_VARS['manufacturers_id'] . '&products_id=' . $listing_values['products_id'], 'NONSSL') . '">' . $listing_values['products_name'] . '</a>';

           } else {

 $fldname = $listing_values['products_name'];

 if ($HTTP_GET_VARS['keywords'] != "" )

	 {

	 $string_to_split = $HTTP_GET_VARS['keywords'];

	 $tok = split(" ", $string_to_split);

	 $size = sizeof($tok);

	 for ($i = 0; $i < $size; $i++) 

	 $fldname = str_replace($tok[$i], '<span style="background-color: ' . SEARCH_RESULT_BACKGROUND_COLOR . '">' . $tok[$i] . '</span>', $fldname); 

	 }

             $lc_text = ' <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing_values['products_id']) . '">' . $fldname . '</a> ';

           }

           break;

         case 'PRODUCT_LIST_DESCRIPTION':

           $lc_text = ' ' . osc_trunc_string(strip_tags($listing_values['products_description'], '<a><b><em><font><i><s><span><strong><sub><sup><u>'), PRODUCT_LIST_DESCRIPTION_LENGTH) . ' ';

           $col_to_span = sizeof($column_list)-1;

           if (PRODUCT_LIST_IMAGE > 0) {

             $col_to_span -= 1;

           }

           $lc_params = 'colspan="' . $col_to_span . '" ';

           break;

         case 'PRODUCT_LIST_MANUFACTURER':

           $lc_text = ' <a href="' . tep_href_link(FILENAME_DEFAULT, 'manufacturers_id=' . $listing_values['manufacturers_id'], 'NONSSL') . '">' . $listing_values['manufacturers_name'] . '</a> ';

           break;

         case 'PRODUCT_LIST_PRICE':

           $lc_align = 'right';

           if ($listing_values['specials_new_products_price']) {

             $lc_text = ' <s>' .  $currencies->display_price($listing_values['products_price'], tep_get_tax_rate($listing_values['products_tax_class_id'])) . '</s>  <span class="productSpecialPrice">' . $currencies->display_price($listing_values['specials_new_products_price'], tep_get_tax_rate($listing_values['products_tax_class_id'])) . '</span> ';

           } else {

             $lc_text = ' ' . $currencies->display_price($listing_values['products_price'], tep_get_tax_rate($listing_values['products_tax_class_id'])) . ' ';

           }

           break;

 

NOTE: it not the whole file !

only a piece

Robert

 

We all need to learn it once, how hard it may seem when you look at it, also you will master it someday ;)

Link to comment
Share on other sites

Druide, thanks for the cool mod, but for some reason, the highlight is not shown on the search result. Currently I am using the latest snapshot along with the Description mod.

 

any idea?

 

thanks

Link to comment
Share on other sites

did you read the line:

 

NOTE: this mod is Case Sensitive !!!

 

that means if you search for: Case

like i do show in the preview URL it only highlight when 'Case' is found, and NOT when 'case' is found.

 

That is why you dont see it always i think ;)

Robert

 

We all need to learn it once, how hard it may seem when you look at it, also you will master it someday ;)

Link to comment
Share on other sites

Druide, thanks for the cool mod, but for some reason, the highlight is not shown on the search result. Currently I am using the latest snapshot along with the Description mod.  

 

any idea?

 

thanks

 

where is your site or code (not whole file !) what you have added ?

 

I cannot look through walls, still trying to make a MOD for that one....lol

Robert

 

We all need to learn it once, how hard it may seem when you look at it, also you will master it someday ;)

Link to comment
Share on other sites

did you read the line:

 

NOTE: this mod is Case Sensitive !!!

 

that means if you search for: Case

like i do show in the preview URL it only highlight when 'Case' is found, and NOT when 'case' is found.

 

That is why you dont see it always i think ;)

 

Sorry, I have forgotten it's Case Sensitive. It works smoothly now. Is it possible for to highlight the description as well?

 

I cannot look through walls, still trying to make a MOD for that one

 

Can't wait to see try out this MOD. :P

 

Once again, thanks for this awesome mod!

Link to comment
Share on other sites

Sorry, I have forgotten it's Case Sensitive.

How could you have forgotten that, you have just installed it ???

I hope you do not forget to install the MODS 'completely' :roll:

 

 

Is it possible for to highlight the description as well?  

Yes that is possible but i dont know the variables from MS1, need to know all the values & names of the variables.

But i dont have too much time for that, just look at the code, it's really simple to add it yourself, but BACKUP before you start to try...

 

One day you will be happy that you started coding PHP

Robert

 

We all need to learn it once, how hard it may seem when you look at it, also you will master it someday ;)

Link to comment
Share on other sites

  • 4 weeks later...

I happen to be messing around with this on MS1, and couldn't get the damned thing to work... But I have figured it out...

 

The variable

$listing_values
no longer exists in MS1... It's now
$listing

 

So the contrib, for MS1, should look like this...

 

 

 

         case 'PRODUCT_LIST_MODEL':

 $fldname = $listing['products_model'];

 if ($HTTP_GET_VARS['keywords'] != "" )

	 {

	 $HTTP_GET_VARS['keywords'] = strtolower($HTTP_GET_VARS['keywords']);

	 $string_to_split = strtoupper($HTTP_GET_VARS['keywords']); // is result UPPERCASE ?

	 $tok = split(" ", $string_to_split);

	 $size = sizeof($tok);

	 for ($i = 0; $i < $size; $i++) 

	 $fldname = str_replace($tok[$i], '<span style="background-color: ' . SEARCH_RESULT_BACKGROUND_COLOR . '">' . $tok[$i] . '</span>', $fldname);



	 $string_to_split = $HTTP_GET_VARS['keywords']; // is result LOWERCASE ?

	 $tok = split(" ", $string_to_split);

	 $size = sizeof($tok);

	 for ($i = 0; $i < $size; $i++) 

	 $fldname = str_replace($tok[$i], '<span style="background-color: ' . SEARCH_RESULT_BACKGROUND_COLOR . '">' . $tok[$i] . '</span>', $fldname);



	 $string_to_split = ucwords($HTTP_GET_VARS['keywords']); // is result starting with 1 uppercase and rest is lowercase ?

	 $tok = split(" ", $string_to_split);

	 $size = sizeof($tok);

	 for ($i = 0; $i < $size; $i++) 

	 $fldname = str_replace($tok[$i], '<span style="background-color: ' . SEARCH_RESULT_BACKGROUND_COLOR . '">' . $tok[$i] . '</span>', $fldname); 

	 }          

           $lc_text = ' ' . $fldname . ' ';

           break;

         case 'PRODUCT_LIST_NAME':

           if ($HTTP_GET_VARS['manufacturers_id']) {

             $lc_text = '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'manufacturers_id=' . $HTTP_GET_VARS['manufacturers_id'] . '&products_id=' . $listing_values['products_id'], 'NONSSL') . '">' . $listing_values['products_name'] . '</a>';

           } else {

 $fldname = $listing['products_name'];

 if ($HTTP_GET_VARS['keywords'] != "" )

	 {

	 $HTTP_GET_VARS['keywords'] = strtolower($HTTP_GET_VARS['keywords']);

	 $string_to_split = strtoupper($HTTP_GET_VARS['keywords']); // is result UPPERCASE ?

	 $tok = split(" ", $string_to_split);

	 $size = sizeof($tok);

	 for ($i = 0; $i < $size; $i++) 

	 $fldname = str_replace($tok[$i], '<span style="background-color: ' . SEARCH_RESULT_BACKGROUND_COLOR . '">' . $tok[$i] . '</span>', $fldname);



	 $string_to_split = $HTTP_GET_VARS['keywords']; // is result LOWERCASE ?

	 $tok = split(" ", $string_to_split);

	 $size = sizeof($tok);

	 for ($i = 0; $i < $size; $i++) 

	 $fldname = str_replace($tok[$i], '<span style="background-color: ' . SEARCH_RESULT_BACKGROUND_COLOR . '">' . $tok[$i] . '</span>', $fldname);



	 $string_to_split = ucwords($HTTP_GET_VARS['keywords']); // is result starting with 1 uppercase and rest is lowercase ?

	 $tok = split(" ", $string_to_split);

	 $size = sizeof($tok);

	 for ($i = 0; $i < $size; $i++) 

	 $fldname = str_replace($tok[$i], '<span style="background-color: ' . SEARCH_RESULT_BACKGROUND_COLOR . '">' . $tok[$i] . '</span>', $fldname);

	 }

             $lc_text = ' <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing_values['products_id']) . '">' . $fldname . '</a> ';

           }

           break;

 

EDITED: Edited for readability. Thanks, Linda

Link to comment
Share on other sites

  • 2 weeks later...

Hi

 

thanks for a great contribution. i think i have found a bug though. if you do a search on 'un' on a standard install of OSC with the standard products loaded in the catalog, and you've chosen to see 'Product Model' in Admin->Configuration->Product Listing you get some strange results in the search results ....

 

search-error.png

 

I think it has something to do with the following similar lines of code in catalogincludesmodulesproduct_listing.php within the case 'PRODUCT_LIST_MODEL': statement around line 123

 

$fldname = str_replace($tok[$i], '<span style="background-color: ' . SEARCH_RESULT_BACKGROUND_COLOR . '">' . $tok[$i] . '</span>', $fldname);

 

has anyone got any ideas where to change the code ? tia

Link to comment
Share on other sites

  • 1 year later...

I do not have a problem with that, seems to work fine at http://www.popthetop.com/catalog/index.php

L8r,

PopTheTop

 

Published osC Contributions:

- eCheck Payment Module v3.1

- Reviews in Product Display v2.0

- Fancier Invoice & Packingslip v6.1

- Admin Notes / Customer Notes v2.2

- Customer Zip & State Validation v2.2

- Search Box with Dropdown Category Menu v1.0

 

Pop your camper's top today!

It's a popup thing...

You wouldn't understand

Link to comment
Share on other sites

  • 3 months later...
I do not have a problem with that, seems to work fine at http://www.popthetop.com/catalog/index.php

 

Hi

 

I was just on you online-shop (www.popthetop.com) and I tried to search with "camp c" on the quick find. The result has the same error on the column "SKU#" like I do have in my shop. I tried to find out the error in the code, but I'm not really that good in programming :blush: Hope you can help me out.

 

Sincerely,

Jimi

Link to comment
Share on other sites

Wow, I do have that problem after all. What is causing that???

L8r,

PopTheTop

 

Published osC Contributions:

- eCheck Payment Module v3.1

- Reviews in Product Display v2.0

- Fancier Invoice & Packingslip v6.1

- Admin Notes / Customer Notes v2.2

- Customer Zip & State Validation v2.2

- Search Box with Dropdown Category Menu v1.0

 

Pop your camper's top today!

It's a popup thing...

You wouldn't understand

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...