/    Sign up×
Community /Pin to ProfileBookmark

Mysql Query With Php To Match Keywords And Rank According To Most Match

My Dear Php Buddies,

Consider a mysql tbl index.tbl that looks like this with entries:

id | Url | Description

0| http://cheapnames.it | Register Domain Names from $1 to $25.

1|http://lownames.usa | Get Domain Names from $1 to $20.

2| http://lowcostnames.uk | Register Domains for as low as $1.

3| http://getdoman.biz | Register Names from between $1 to $25.

Now, imagine you did a search for “register domain names”.

Now, I want the query to rank the rows based on the most matched keywords. So, from our example, the ranking should be like this:

0| http://cheapnames.it | Register Domain Names from $1 to $25.

1|http://lownames.usa | Get Domain Names from $1 to $20.

3| http://getdoman.biz | Register Names from between $1 to $25.

2| http://lowcostnames.uk | Register Domains for as low as $1.

Note that, the id=0 has 3 KWs matches. Hence on top.

Both the id=1 & id=3 have 2 matches. Hence 2nd & 3rd. Amongst these 2, priority of rank is given based on “id” (link submission id).

And ofcourse, the last matched row is at the bottom.

Q1a. How would you write the Sql query be doing the querying & ranking like I described ?

Q1b. Is just the Sql querying enough here to do the ranking display like described or have to get php to do the ranking display aswell ? Or, maybe Sql should not be doing the ranking display atall but php ? In that case, my I see a php sample code ?

This no good which I got so far:

$query = “SELECT * FROM notices WHERE description = register  AND Domain AND Names”; 

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@ginerjmNov 13.2018 — I've not seen this done before. Can't see how SQL language could accomplish. Think you'll have to run the query, do a fetchall, and then loop thru that array to examine how many of your search arguments are found on each record and assign a value/number to the record and then do a follow-up sort of the array using this value/number. (Note - you should create an empty column in your query to use for the sort value.)
Copy linkTweet thisAlerts:
@site-developerauthorNov 13.2018 — @ginerjm#1597789

Jimmy My Friend, My Pal,

How-about you think of all the possibilities and then show me their example codes ? That way, I can quickly test which works and which not and give you feedback and myself learn the code that worked ?

Anyway, someone suggested I look into this:

https://dev.mysql.com/doc/refman/5.7/en/fulltext-search.html

Read these but my head is spinning with too many readings. Bogging me down clogging my head:

https://dev.mysql.com/doc/refman/5.7/en/fulltext-boolean.html

https://dev.mysql.com/doc/refman/5.7/en/column-indexes.html

https://dev.mysql.com/doc/refman/5.7/en/innodb-fulltext-index.html

https://dev.mysql.com/doc/refman/5.7/en/fulltext-restrictions.html

You understand my problem ?
Copy linkTweet thisAlerts:
@ginerjmNov 13.2018 — Yes - I truly understand your problem....

I gave you a perfectly valid answer and you have nothing but sarcasm in return. Why do I bother? Why does anyone bother to take you seriously?
Copy linkTweet thisAlerts:
@ginerjmNov 13.2018 — Learn something every day.....

https://docs.microsoft.com/en-us/sql/relational-databases/search/limit-search-results-with-rank?view=sql-server-2017
Copy linkTweet thisAlerts:
@site-developerauthorNov 13.2018 — @ginerjm#1597791

Sarcasm ? You are paranoid! It is my habit to ask for code samples. Remember ?

Anyway, someone suggested this reading:

https://dev.mysql.com/doc/refman/5.5/en/fulltext-boolean.html

So, you suggest I use this format found there:

'+apple +(>turnover <strudel)'

Yes ?
Copy linkTweet thisAlerts:
@site-developerauthorNov 13.2018 — @ginerjm#1597796

Thanks.
×

Success!

Help @site-developer spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.27,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...