Post by mystifier » Fri Apr 22, 2011 7:18 pm

Free Extension added 'Improved Search' (v1.4.9.3 / 1.4.9.4)

The standard Search and Advanced Search look for a single extract so keywords have to be consectutive and in the same order.

This Improved Search breaks the search term into individual keywords and searches for them seperately so it will find them if they are not consecutive and in any order.

Description and Model may still be selected.

Free v1.4.9 Extensions: Default Specials | Improved Search | Customer Activity Report | Customer Groups | Royal Mail With Handling | Improved Product Page | Random Products | Stock Report | All Products


User avatar
Active Member

Posts

Joined
Tue May 18, 2010 5:15 pm

Post by JAY6390 » Sun Apr 24, 2011 7:21 pm

Great work. Couple of code improvements if I may

Firstly, make all the keywords lowercase, trim any excess space either side, change any double spacings or more into single spaces using a regular expression, and when exploded, use array_unique to make sure you're not searching the same term twice

Code: Select all

            $search_words = trim(preg_replace('/\s\s+/', '', strtolower($keyword));
            $search_words = explode(" ", $search_words);
            $search_words = array_unique($search_words); 

Image


User avatar
Guru Member

Posts

Joined
Wed May 26, 2010 11:47 pm
Location - United Kingdom

Post by mystifier » Sun Apr 24, 2011 8:32 pm

Thanks Jay, although strtolower is already used in the actual query to make it case-insensitive.

Explode removes the delimiting space and sometimes, it may be useful to use additional whitespace to look for whole words. I didn't bother making sure that keywords were unique because the user enters them to search and if they use the same keyword twice, I figured they deserve to wait a little longer for the result. :laugh:

I didn't actually realise that the standard search was so weak because it has never been reported to me as a problem; I was responding to someone in support. I think it should be core behaviour.

Free v1.4.9 Extensions: Default Specials | Improved Search | Customer Activity Report | Customer Groups | Royal Mail With Handling | Improved Product Page | Random Products | Stock Report | All Products


User avatar
Active Member

Posts

Joined
Tue May 18, 2010 5:15 pm

Post by JAY6390 » Sun Apr 24, 2011 8:40 pm

true enough, if people are silly enough to put stuff twice, extra spaces etc they are idiots, but it puts more strain on your server with no need and personally I don't want any more strain on my server than necessary, as it slows it down for other people on the server that have common sense

The explode doesn't quite work as you would expect. Say someone puts
"Keyword1 Keyword2 Keyword3"
Then the three spaces between Keyword2 and Keyword3 changes into 2 empty strings which will still be used in the query and foreach, so you would end up with like %% which will match everything, and really start straining on your db

The strotolower is nothing to do with the query as such, its to make sure the array_unique finds two words the same and removes them, since it will class Hello and hello as two separate words, even though they are the same when it comes to the query

As I say, it was only what I would consider improvements on the code, it's up to you

Image


User avatar
Guru Member

Posts

Joined
Wed May 26, 2010 11:47 pm
Location - United Kingdom

Post by Johnathan » Wed Apr 27, 2011 12:02 am

Just thought I'd point out that the modified file also has the p.date_available change for getLatestProducts(), which you probably didn't mean to include. :)

Image Image Image Image Image


User avatar
Administrator

Posts

Joined
Fri Dec 18, 2009 3:08 am


Post by mystifier » Wed Apr 27, 2011 4:55 am

Two improvements for the price of none - date_added replaced by the more sensible date_available ;D

Okay, I guess I should change it back to the date_added if that is what it used to be.

Free v1.4.9 Extensions: Default Specials | Improved Search | Customer Activity Report | Customer Groups | Royal Mail With Handling | Improved Product Page | Random Products | Stock Report | All Products


User avatar
Active Member

Posts

Joined
Tue May 18, 2010 5:15 pm

Post by Johnathan » Wed Apr 27, 2011 6:03 am

mystifier wrote:Two improvements for the price of none - date_added replaced by the more sensible date_available ;D
I completely agree -- I think we decided together that it's better that way. But you know how the naysayers are. ;)

Image Image Image Image Image


User avatar
Administrator

Posts

Joined
Fri Dec 18, 2009 3:08 am


Post by mystifier » Wed Apr 27, 2011 2:50 pm

I changed it back to the default anyway. The problem is that after each update, I apply an ever increasing number of small tweaks (eg force 'jOHn sMiTh' to 'John Smith' on account create) and now, split search keywords and use them individually, so some MODS may inadvertently contain other small changes.

Together with numerous free 'essential' extensions/mods (eg. Filter By Category, Manufacturer Description, Recent Products Module), they comprise my 'core' due to a strange reluctance to make them official.

Free v1.4.9 Extensions: Default Specials | Improved Search | Customer Activity Report | Customer Groups | Royal Mail With Handling | Improved Product Page | Random Products | Stock Report | All Products


User avatar
Active Member

Posts

Joined
Tue May 18, 2010 5:15 pm

Post by traceofwind » Sat May 14, 2011 5:06 am

Hi mystifier,

I just wanted to say thanks for your contribution, this worked great with Opencart v1.4.9.3.

Best regards,

Gary

New member

Posts

Joined
Fri Jul 02, 2010 6:37 am

Post by mystifier » Sat May 14, 2011 3:07 pm

Thanks traceofwind,

Still didn't make it into v1.4.9.5 though, so it needs patching again so that it doesn't look like the search is broken.

Oh well, I can only try!

Free v1.4.9 Extensions: Default Specials | Improved Search | Customer Activity Report | Customer Groups | Royal Mail With Handling | Improved Product Page | Random Products | Stock Report | All Products


User avatar
Active Member

Posts

Joined
Tue May 18, 2010 5:15 pm

Post by traceofwind » Sat May 14, 2011 7:16 pm

Hi mistifier,

Well I feel both bad for users of 1.4.9.5 and lucky that I stayed with 1.4.9.3! :)

But it is shocking that such a core function of an e-commerce website, search, by default is so lacking in user functionality. You are a real credit to the community here and I hope that your extension gets the due credit it deserves.

All the best!

New member

Posts

Joined
Fri Jul 02, 2010 6:37 am
Who is online

Users browsing this forum: No registered users and 1 guest