User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 397,639 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,339 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 999 | Replies: 8
Reply
Join Date: Oct 2007
Location: Pennsylvania, US
Posts: 37
Reputation: maddog39 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
maddog39 maddog39 is offline Offline
Light Poster

Calculating relevance from a search

  #1  
Dec 14th, 2007
Hello all,

I am building a website and on my search page I want to be able to display the relevance of each search result. I've searched all over the place but still haven't found any information on how to do this.And obviously im building this website in PHP. Any ideas?

Thanks!
-maddog39
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2007
Location: Arkansas
Posts: 360
Reputation: buddylee17 will become famous soon enough buddylee17 will become famous soon enough 
Rep Power: 2
Solved Threads: 69
buddylee17's Avatar
buddylee17 buddylee17 is online now Online
Posting Whiz

Re: Calculating relevance from a search

  #2  
Dec 16th, 2007
SELECT * FROM mytable WHERE MATCH(title,content)
AGAINST('+search* ~term' IN BOOLEAN MODE) ORDER BY relevance DESC;

Have a look at this for more information.
Reply With Quote  
Join Date: Oct 2007
Location: Pennsylvania, US
Posts: 37
Reputation: maddog39 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
maddog39 maddog39 is offline Offline
Light Poster

Re: Calculating relevance from a search

  #3  
Dec 17th, 2007
Okay thanks, i'm taking a look at it now.
Reply With Quote  
Join Date: Oct 2007
Location: Pennsylvania, US
Posts: 37
Reputation: maddog39 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
maddog39 maddog39 is offline Offline
Light Poster

Re: Calculating relevance from a search

  #4  
Dec 18th, 2007
Okay I took a look at that page and everything. But I'm a bit confused because its telling you to order by relevance, when thats what I am trying to determine in the first place. Any ideas?
Reply With Quote  
Join Date: Nov 2007
Location: Arkansas
Posts: 360
Reputation: buddylee17 will become famous soon enough buddylee17 will become famous soon enough 
Rep Power: 2
Solved Threads: 69
buddylee17's Avatar
buddylee17 buddylee17 is online now Online
Posting Whiz

Re: Calculating relevance from a search

  #5  
Dec 19th, 2007
  1. SELECT * FROM mytable WHERE MATCH(title,content)
  2. AGAINST('+search* ~term' IN BOOLEAN MODE) ORDER BY relevance DESC;
No you, the person writing the query, are telling MySQL to return the results in order of relevance. The +sign means that all words must contain the word search. The * is a wildcard meaning that searched, searching, and searchable will be returned. If the record also contains the word term it will be returned and will be considered less relevant than those which dont contain it, due to the ~ operator. If you want the word term to increase the relevancy, dont use the ~.
MySQL uses your query as a kind of voting system. How you arrange your query and which operators you use, determines which row gets the most number of votes. The row with the most votes gets returned first.
Reply With Quote  
Join Date: Oct 2007
Location: Pennsylvania, US
Posts: 37
Reputation: maddog39 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
maddog39 maddog39 is offline Offline
Light Poster

Re: Calculating relevance from a search

  #6  
Dec 19th, 2007
Yea i understand all of that except the ORDER BY relevance part, where are you (am I) getting that field. Where's it coming from? Thats where I'm confused.
Reply With Quote  
Join Date: Feb 2007
Location: St. Vincent and the Grenadines, Caribbean
Posts: 958
Reputation: scru is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 39
Featured Poster
scru's Avatar
scru scru is offline Offline
Posting Shark

Re: Calculating relevance from a search

  #7  
Dec 20th, 2007
the relevance? It looks as though the query generates it.
Half and a half meck a whole, and I donned it a hundrid purcent
Reply With Quote  
Join Date: Nov 2007
Location: Arkansas
Posts: 360
Reputation: buddylee17 will become famous soon enough buddylee17 will become famous soon enough 
Rep Power: 2
Solved Threads: 69
buddylee17's Avatar
buddylee17 buddylee17 is online now Online
Posting Whiz

Re: Calculating relevance from a search

  #8  
Dec 20th, 2007
I found another way to do this.
The table name is Employees . The field name is Role. The query finds all rows in Role that contain an A and the word Sales and returns them in order of relevancy.
  1. SELECT *, MATCH(Role)
  2. AGAINST('+A* *Sales' IN BOOLEAN MODE)AS relevance FROM Employees ORDER BY relevance DESC;
Hopefully you can manipulate this code and get it to work for you.
Reply With Quote  
Join Date: Oct 2007
Location: Pennsylvania, US
Posts: 37
Reputation: maddog39 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
maddog39 maddog39 is offline Offline
Light Poster

Re: Calculating relevance from a search

  #9  
Dec 20th, 2007
Alright thanks alot. Looks like that query did it for me.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

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

 

DaniWeb PHP Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 10:25 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC