I JUST hit this wall with a client
He was VERY frustrated with the search. (IMHO only lazy search engines only used exact phrase matching 30 years ago)
I took a look at this hack and while it was good I found an even better way.
1) It breaks apart the search critera.
2) Searches for each word individually (so brass knob will return results with 'brass knob', 'knob brass', brass and knob)
3) Then Scores the hits with the following rules.
5 if the exact search phrase appears in the title
3 if the exact search phrase appears in the description
Individual words are scored with the following method
If the FIRST word in search phrase appears in the title it gets 4 points
If the Second word in search phrase appears in the title it gets 4 - (4/number of search words).
If the third word in search phrase appears in the title it gets 4 - 2(4/number of search words).
And so on.
The same is true for the description except starting with 3.
This allows for more important words to be placed FIRST in the search.
4) Sorts the hits descending (highest score at the top).
I'm testing it now...
Additional scorings of results could be added (ie a SKU hit could be given a 7 or a price hit a 3) so searches for a product with brass that has a price of 3.50 could be searched by typing 'brass 3.50'
One failing of my code is that it destroys multiple languages. When I get it tested and cleaned up I'll post the changes.
__________________
- X-Cart Version 4.1
- PHP Version 4.4.x eAccelerator
- MySQL 4.1
- Fedora Core 1
- Dual Xeon 2.4Ghz Hyperthreading enabled 2GB Ram
|