Particletree » Ranked Searches with SQL

A handy trick to add some sort of ranking to SQL search results:

Creating some sort of search functionality is something we all have to do at one point or another. For the good cases, we have fulltext search or an external program available to us. But sometimes, getting down and dirty with plain SQL is the only option.

SELECT
SUM(((LENGTH(Body) - LENGTH(REPLACE(Body, 'term', '')))/4))
AS Occurrences

Particletree: Ranked Searches with SQL

Geef een reactie

Je e-mailadres wordt niet gepubliceerd. Vereiste velden zijn gemarkeerd met *

Deze site gebruikt Akismet om spam te verminderen. Bekijk hoe je reactie gegevens worden verwerkt.