S
S
suzyry2016-01-17 12:40:13
PHP
suzyry, 2016-01-17 12:40:13

How to display matched search results?

Good day to all.
Previously, I implemented the search through a similarity query:
SELECT * FROM table WHERE title LIKE "%слово%"
Everything is fine, but now it became necessary to sort the results by their similarity, i.e. the first results are those that are more similar or where the given string matches more (by number).
For example, I'm looking for the word "hare".
Entries should be displayed in this order:
id | title
------------------------------------------------- ------------------------------------
1| A hare and another hare, and another hare after that hare
2| One hare, and one more hare, after that hare
3| Hare and hare
4| Hare yats
5| Hare
The question itself - is it possible to somehow implement such sorting through sql query or other methods?
Thank you for your attention!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dimonchik, 2016-01-17
@dimonchik2013

sphinxsearch

R
Rsa97, 2016-01-17
@Rsa97

Full Text Search
sqlfiddle.com/#!9/2e996/9

I
igruschkafox, 2016-01-17
@igruschkafox

in MS SQL, you need to use Data Quality Service - as a result of the query, there will be a Similarity column (similarity - in percent), you can sort
it and something similar should be in other DBMS

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question