SunQuest
 
           MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old July 13th, 2004, 12:55 PM
PcCowboy PcCowboy is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 6 PcCowboy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question Scoring MySQL Results

Hello,

I am working a web site that uses MySQL as it's database. I have a deveopment requirement that calls for the results of a search to be scored by percent of match, i.e. if all criteria match the score is 100, if only half the criteria match the score is 50. The site is bult using php 4.3.x but will soon upgrade to php 5.x.

Is there a query method that can give these results or do I need to accomplish this in php? If I need to use php, what is the best approach? Should I simply query the database for matches using 25% of the criteria and then use php to find the level of matching per row? Or perhaps, query the db multiple times select only a single criteria each time and the search for like rows in each result?

Any help or suggestions would be of great help.


Thanks

Reply With Quote
  #2  
Old July 13th, 2004, 03:26 PM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
What's your actual search look like? When you mention criteria, are you talking about a search on (for example) name, city, state, and zip wherein if only the zip matches it's 25%, if zip and state, it's 50%, and so on?
__________________
Please don't PM me asking for solutions outside the scope of a thread.
Keeping all responses in a thread stands to help others who come along later,
which is after all what this forum's all about.

Reply With Quote
  #3  
Old July 14th, 2004, 12:28 AM
PcCowboy PcCowboy is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 6 PcCowboy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
My application is a heavy equipment classifieds site. A user may search based on the criteria presented on a form ( multiple forms really...) The criteria is based on the type of equipment the user is searching for. So, the queries are dynamically created by appending various tables and fields to the base query. The options for a 580C Case Backhoe are quit different than those from an International Harvester Combine, or a Farm All Model 'A' row tractor.

Exert from Requirements Doc.

"The results return everything in the category (Farm Tractor, Industrial Tractor, Combine, Hay & Cotton Bailers, Dump Trucks, etc..) and within the year range desired (as entered by the user <year from> & <year to>) and shall return at the top of the list, the nearest match. the total matches returned are limited by a user entered value, as is the total number of matches returned per-page.

Each match shall contain a score that represents the completeness of the match as compared to the user's entered criteria. If all record matches all the user's criteria, the match is scored as 100. If half the user's criteria are matched, the match is scored as 50. The score shall be a fixed point decimal number with a precision of 1/100th of a percent (i.e. the score will range from 0.00 to 100.00)"

So, this is what I need to do.... I would expect the solution to be something like those dating sites and search engines use to show how close a match is.



Thanks for your input




Reply With Quote
  #4  
Old July 14th, 2004, 12:34 PM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
That's kind of a pain in the ass. I can think of a couple of ways of going about this. One is to do a bunch of different queries, one for each form option specified, and to add result ids/names to an array and keep a count. You'd only add to the array if the item isn't already found in the array. You'd increment a count each time. Then you can compare counts for each match against the count of criteria specified. This is pretty ugly. The other method that springs to mind is to build an array of search criteria, to perform one big assembled query, and for each result, to check all relevant columns against the corresponding search criteria and keep a count that way. This drops you down to one query but is still pretty ugly.

Reply With Quote
  #5  
Old July 15th, 2004, 12:50 PM
PcCowboy PcCowboy is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 6 PcCowboy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks,

So far, everything I've come up with has been very messy... The best approach seems to be to query the db for all records in the given category. Then use php to step through each record in the result set and calculate the score based on the number of fields and that match the search criteria.

What I'm thinking is something like this....

1. Get the user category, year from, and year to, and query the database using this info.

2. Get all the user entered criteria and place in an array.

3. Create a 2D score array (to include query result row id and score.)

4. Get result row from query results and compare each field with those in the criteria array.

5. Increment the score value for each field value that matches the same criteria.

6. Goto 4 until done...

7. Sort Score array by score

8. Find multiplier to adjust score value (100/num_fields)

9. For number of results per page, loop through score array printing the result row and adjusting the score value.



Tell me what you think? Not very clean but perhaps do-able.....

Reply With Quote
  #6  
Old July 15th, 2004, 02:35 PM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
Seems about right to me.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > Scoring MySQL Results


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway