Posted By

ezerick on 03/12/11


Tagged


Versions (?)

Relevance-based Site Search with SQL | JarrodGoddard.com


 / Published in: SQL
 

URL: http://www.jarrodgoddard.com/web-development/advanced-web-site-search-with-sql

  1. SELECT title, filename, sum(relevance)
  2. FROM (
  3. SELECT title, filename, 10 AS relevance FROM page WHERE title LIKE ‘%about%’
  4. UNION
  5. SELECT title, filename, 7 AS relevance FROM page WHERE filename LIKE ‘%about%’
  6. UNION
  7. SELECT title, filename, 5 AS relevance FROM page WHERE keywords LIKE ‘%about%’
  8. UNION
  9. SELECT title, filename, 2 AS relevance FROM page WHERE description LIKE ‘%about%’
  10. ) results
  11. GROUP BY title, filename
  12. ORDER BY relevance DESC;

Report this snippet  

You need to login to post a comment.