0

Is there a PHP or MySQL function which will check how relevant a matching field is? Could it review the string and match against a percentage of characters?

For example I am doing a basic search script pulling back results but how can I make the more relevant results appear at the top?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Andy
  • 2,991
  • 9
  • 43
  • 62

3 Answers3

0

A lot depends on your data and the type of searches that you are expecting. But basically, you could be looking for a fuzzy search. Soundex and Levenshtein distance are two of the many functions that you can use for string matches

http://php.net/manual/en/function.levenshtein.php

Stewie
  • 3,103
  • 2
  • 24
  • 22
0

Well, you are asking a few complicated questions here. Mostly, I think you are looking for information retrieval techniques. Some answers are all over Stack OVerflow.

What tried and true algorithms for suggesting related articles are out there? is great I think

You might want to use the levenshtein distance if you are just looking for how closely a keyword matches an existing keyword.

I tried :P

Community
  • 1
  • 1
0x1F602
  • 865
  • 5
  • 22
0

Mysql has a function MATCH You can youse it like

SELECT * FROM `table` WHERE MATCH(content) AGAINST('search text')

So it will look within content how relevancy it is. But you need to index field content to FULLTEXT which requires an table type "MYISAM". The output will automaticly sorted ascending.

hope this helps

prdatur
  • 1,010
  • 1
  • 14
  • 20