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. -
$querystr = "SELECT img,link,numclick,description,order FROM table1 WHERE 1=1 ";
-
-
for ($x = 0; $x < count($keys); $x++) {
-
$querystr .= "and concat( description, order ) like \"%$keys[$x]%\"";
-
}
-
-
$querystr .= " limit 20";
-
Some advices?
Many thanks
5 1569
What do you see as relevancy?
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 ... -
$querystr = "SELECT
-
( if ( instr( title , $keys[0] ) > 0 , 3 , 0 )
-
-
+ if ( instr( title , $keys[1] ) > 0 , 3 , 0 )
-
-
+ if ( instr( title , $keys[2] ) > 0 , 3 , 0 )
-
-
+ if ( instr( description, $keys[0]) ) > 0 , 1 , 0 )
-
-
+ if ( instr( description, $keys[1]) ) > 0 , 1 , 0 )
-
-
+ if ( instr( description, $keys[2]) ) > 0 , 1 , 0 )
-
-
) as relevance ,
-
-
img,
-
link,
-
numclick,
-
description,
-
title
-
-
FROM MyTable
-
-
WHERE
-
-
concat_ws( , title , description) like %$keys[0]%
-
-
and concat_ws( , title , description) like %$keys[1]%
-
-
and concat_ws( , title , description) like %$keys[2]%";
-
-
for ($x = 0; $x < count($keys); $x++) {
-
$querystr .= "and concat( description, title ) like \"%$keys[$x]%\"";
-
}
-
$querystr .= " ORDER BY relevance DESC LIMIT 20";
-
@code_green,
Your link doesn't work.
What I see is - http://how%20to%20return%20the%20record%20above%20and%20the%20record%20below/
Will you please fix it?
I have not understood what is the problem...?
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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:
...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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
|
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...
|
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,...
|
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...
|
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...
|
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...
|
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 projectplanning, coding, testing,...
| |