0

I have tried to fetch a sql row that matches the most similar sentence entered by the user. For example user types "Are you having fever"

and mysql table has records namely 1: "having, fever". 2: "fever"

It should fetch the number 1 record with it being the nearest match.

We have tried using LIKE, MATCH query like below one, but to no avail.

SELECT * FROM mbrace_pd.mbrace_pd WHERE MATCH(input) AGAINST ('Are you having fever');

How to do this?

Update: Okay it has started working partly. The "fever text" has started working. I added who,you content to the table and tried fetching it by typing who are you. But it did not work.

Husain
  • 119
  • 2
  • 8
  • 1
    What problem did you have with `MATCH`? – Nick Oct 06 '18 at 02:09
  • It was not fetching the row as specified above. – Husain Oct 06 '18 at 02:21
  • It works fine for me in a small test case, can you edit your post with the query you used? – Nick Oct 06 '18 at 02:22
  • edited the post. – Husain Oct 06 '18 at 02:26
  • `input` is the column with the strings in it? Do you have a `FULLTEXT` index on `input`? – Nick Oct 06 '18 at 02:28
  • Yeah input is the column.Regarding fulltext I already did that with this sql query "ALTER TABLE mbrace_pd ADD FULLTEXT(input)" – Husain Oct 06 '18 at 02:30
  • What you have should work... it does in this small example: http://rextester.com/XZSO50783 – Nick Oct 06 '18 at 02:36
  • Can you just tell me in what version of mysql sql MATCH works. Because the mysql version i have in the localhost is old. – Husain Oct 06 '18 at 02:54
  • 1
    Instead of saying it's "old" why not tell us what version it is? – miken32 Oct 06 '18 at 03:15
  • It was introduced in 5.5 – Nick Oct 06 '18 at 03:20
  • 1
    If you need proper way to get the closest matching value then you might need to look into [levenshtein distance](https://en.wikipedia.org/wiki/Levenshtein_distance). You can implement it as a function and then use it [here is sql implementation](https://stackoverflow.com/questions/560709/levenshtein-distance-in-t-sql) – Mahesh Oct 06 '18 at 03:57

0 Answers0