TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 06-03-2010, 05:42 PM   #1 (permalink)
The Acquainted
 
Join Date: Feb 2008
Posts: 107
Thanks: 3
CΛSTΞX is on a distinguished road
Arrow Mysql order by method

For example, if the search is

Norton free 2010 Download

How to order results like this

Norton free download
Norton download
Norton 2010 for pc

The first one includes 3 words of the search, so it is first. How to do this, thanks...
__________________
Downloadic
infolizer
Send a message via MSN to CΛSTΞX
CΛSTΞX is offline  
Reply With Quote
Old 06-04-2010, 02:10 AM   #2 (permalink)
The Addict
 
Join Date: May 2009
Posts: 287
Thanks: 5
adamdecaf is on a distinguished road
Default

Are you looking to sort the results be word length or by relevance?
__________________
My Site
adamdecaf is offline  
Reply With Quote
Old 06-04-2010, 03:03 AM   #3 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

Quote:
Originally Posted by CΛSTΞX View Post
For example, if the search is

Norton free 2010 Download

How to order results like this

Norton free download
Norton download
Norton 2010 for pc

The first one includes 3 words of the search, so it is first. How to do this, thanks...
If I understand this correctly, you want to order by the number of words that are the same THEN the percentage of words the same. Here is another result set:
Search "Google SEO Tips"
1. Google SEO Tips
2. Google SEO Tips blog
3. Google search Tips
3. Google search Tips blog

If so there is no easy way. The query would require custom functions to be defined using stored procedures. If you want to hire me I will be willing to do this, but here is the best I can/will do for free:
This will give you the occurrences of a string in another string (we are finding the number of occurrences of stringB in stringA).
mysql Code:
set @stringA="Google Search Google", @stringB="Google";

SELECT ((LENGTH(@stringA) - LENGTH(REPLACE(@stringA,@stringB, '')))/LENGTH(@stringB)) AS `occurrences`

It will return 2.
__________________

Village Idiot is offline  
Reply With Quote
Old 06-04-2010, 12:30 PM   #4 (permalink)
The Acquainted
 
Join Date: Feb 2008
Posts: 107
Thanks: 3
CΛSTΞX is on a distinguished road
Default

Hmm, thank you. How about this >

PHP Code:
SELECT *, ((CASE WHEN `descriptionLIKE '%brown%' THEN 1 ELSE 0 END) + (CASE WHEN `descriptionLIKE '%fox%' THEN 1 ELSE 0 END) + (CASE WHEN `descriptionLIKE '%lazy%' THEN 1 ELSE 0 END) + (CASE WHEN `descriptionLIKE '%dog%' THEN 1 ELSE 0 END)) AS relevance
FROM 
`items`
WHERE `description`LIKE '%quick%' AND (
  `
description`LIKE '%brown%'
  
OR `descriptionLIKE '%fox%'
  
OR `descriptionLIKE '%lazy%'
  
OR `descriptionLIKE '%dog%'
)
ORDER BY relevance DESC
LIMIT 0 
30
Do you think that works properly ? Or what money you want to do the best script for that ?
__________________
Downloadic
infolizer

Last edited by CΛSTΞX : 06-04-2010 at 02:51 PM.
Send a message via MSN to CΛSTΞX
CΛSTΞX is offline  
Reply With Quote
Old 06-04-2010, 04:44 PM   #5 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

Quote:
Originally Posted by CΛSTΞX View Post
Hmm, thank you. How about this >

PHP Code:
SELECT *, ((CASE WHEN `descriptionLIKE '%brown%' THEN 1 ELSE 0 END) + (CASE WHEN `descriptionLIKE '%fox%' THEN 1 ELSE 0 END) + (CASE WHEN `descriptionLIKE '%lazy%' THEN 1 ELSE 0 END) + (CASE WHEN `descriptionLIKE '%dog%' THEN 1 ELSE 0 END)) AS relevance
FROM 
`items`
WHERE `description`LIKE '%quick%' AND (
  `
description`LIKE '%brown%'
  
OR `descriptionLIKE '%fox%'
  
OR `descriptionLIKE '%lazy%'
  
OR `descriptionLIKE '%dog%'
)
ORDER BY relevance DESC
LIMIT 0 
30
Do you think that works properly ? Or what money you want to do the best script for that ?
The first part looks good, but the second part doesn't make sense. From what it looks like, the description would have to have the word quick in it to be included. Change the and to or and you have have something here. The only issue I see is ordering passed the number of similar words, the last two examples from what you gave would not necessarily be in that order.

For me to do it in SQL would take me about an hour to write, debug and prefect, so $50. You can see my portfolio at http://www.qsdconsulting.com At the moment you seem to be on to something, so lets see how that goes first. I'm happy to help you as long as you are giving it your effort.
__________________

Village Idiot is offline  
Reply With Quote
Old 06-04-2010, 05:39 PM   #6 (permalink)
The Acquainted
 
Join Date: Feb 2008
Posts: 107
Thanks: 3
CΛSTΞX is on a distinguished road
Default

Ok, I want you to do this for me, do you have msn ?
__________________
Downloadic
infolizer
Send a message via MSN to CΛSTΞX
CΛSTΞX is offline  
Reply With Quote
Old 06-04-2010, 05:54 PM   #7 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

Quote:
Originally Posted by CΛSTΞX View Post
Ok, I want you to do this for me, do you have msn ?
Yes, phpnsql@hotmail.com
__________________

Village Idiot is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Using the factory pattern (mad rantings of a mind without coffee) sketchMedia Advanced PHP Programming 35 09-25-2009 11:05 AM
mysql order by date nefus General 12 06-23-2009 10:02 PM
Generating XML from a Mysql DB with PHP's DOM functions (part Two) sketchMedia XML, XSLT, XPath, XQuery 7 08-20-2008 12:02 AM
A nice way to use a MySQL class Gibou Advanced PHP Programming 0 11-27-2007 11:42 PM
MySQL - Is there a better way to SELECT Acrylic Absolute Beginners 3 10-24-2007 03:39 PM


All times are GMT. The time now is 01:51 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design