473,396 Members | 1,989 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

order results by relevancy

10
Hello everybody, I'm trying to find a way to order by relevancy the result of my simple search engine...
I've found on the web different solutions, but I'm not able to adapt them to my case.

Expand|Select|Wrap|Line Numbers
  1. $querystr = "SELECT img,link,numclick,description,order FROM table1 WHERE 1=1 ";
  2.  
  3.             for ($x = 0; $x < count($keys); $x++) {
  4.                $querystr .= "and concat( description, order ) like \"%$keys[$x]%\"";
  5.             }
  6.  
  7.             $querystr .= " limit 20";
  8.  
Some advices?
Many thanks
Aug 23 '10 #1
5 1569
code green
1,726 Expert 1GB
What do you see as relevancy?
Aug 23 '10 #2
deiv82
10
At the moment I get the results in the order by how they are in the database and not by the most similarity of the word searched...
I've tried using MATCH and AGAINST but I don't know how to use it in my code and also no idea if it's useful for my case.

If not I found also this solution it seemed to be good but I can't make it work ...

Expand|Select|Wrap|Line Numbers
  1. $querystr = "SELECT 
  2. ( if ( instr( title , $keys[0] ) > 0 , 3 , 0 )
  3.  
  4. + if ( instr( title , $keys[1] ) > 0 , 3 , 0 )
  5.  
  6. + if ( instr( title , $keys[2] ) > 0 , 3 , 0 )
  7.  
  8. + if ( instr( description, $keys[0]) ‘ ) > 0 , 1 , 0 )
  9.  
  10. + if ( instr( description, $keys[1]) ‘ ) > 0 , 1 , 0 )
  11.  
  12. + if ( instr( description, $keys[2]) ‘ ) > 0 , 1 , 0 )
  13.  
  14. ) as relevance ,
  15.  
  16. img,
  17. link,
  18. numclick,
  19. description,
  20. title 
  21.  
  22. FROM MyTable 
  23.  
  24. WHERE 
  25.  
  26. concat_ws(‘ ‘ , title , description) like ‘%$keys[0]%’
  27.  
  28. and concat_ws(‘ ‘ , title , description) like ‘%$keys[1]%’
  29.  
  30. and concat_ws(‘ ‘ , title , description) like ‘%$keys[2]%’";
  31.  
  32.             for ($x = 0; $x < count($keys); $x++) {
  33.                $querystr .= "and concat( description, title ) like \"%$keys[$x]%\"";
  34.             }
  35.             $querystr .= " ORDER BY relevance DESC LIMIT 20";
  36.  
Aug 23 '10 #3
code green
1,726 Expert 1GB
This thread seems suspiciously similar to this one
http://bytes.com/topic/mysql/answers...e-record-below
Is it assignment time again
Aug 23 '10 #4
Oralloy
988 Expert 512MB
@code_green,

Your link doesn't work.

What I see is
Expand|Select|Wrap|Line Numbers
  1. http://how%20to%20return%20the%20record%20above%20and%20the%20record%20below/
Will you please fix it?
Aug 23 '10 #5
deiv82
10
I have not understood what is the problem...?
Aug 24 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Damjan | last post by:
Hi All; this is not a specific PHP question, but as I am working in PHP.... My SQL queries return one, two, sometimes even three levels of XML data. So for orders in my system I would like to...
23
by: ian justice | last post by:
Before i post actual code, as i need a speedyish reply. Can i first ask if anyone knows off the top of their head, if there is a likely obvious cause to the following problem. For the moment i've...
20
by: Xenophobe | last post by:
I have successfully converted the ASP code included in the following article to PHP: http://www.4guysfromrolla.com/webtech/040100-1.shtml As described the high and low latitudes and longitudes...
1
by: Constantine Kakoushis | last post by:
Hi, I'm looking for the most efficient way of displaying results from an SQL query that must be ordered by a value that is derived following retrieval. The user enters their location (postal...
2
by: Phil Powell | last post by:
Relevancy scores are normally defined by a MySQL query on a table that has a fulltext index. The rules for relevancy scoring will exclude certain words due to their being too short (minimum...
0
by: Phil Powell | last post by:
The table already has a fulltext index and from there I can use the MySQL fulltext search query to get results as well as the relevancy score. The problem I have is that MySQL has a default...
18
by: ian justice | last post by:
Before i post actual code, as i need a speedyish reply. Can i first ask if anyone knows off the top of their head, if there is a likely obvious cause to the following problem. For the moment i've...
0
by: Phil Powell | last post by:
I have a rather complicated query with a combination of LEFT JOINs and two MATCHES where the first match is non-boolean to get the accurate score, the second to search as boolean: SELECT...
1
by: Jamie Burns | last post by:
Hello, I am writing a search engine that uses mysql to keep a word index. I have just added the "position" of each word, in relation to the document it is in. My table thus is as follows: ...
2
by: ojsimon | last post by:
Hi This is a script which combines many different video feeds together, at the moment you can see that it shuffle($all); instead of an algorithm to sort the records, i would like to change it so...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.