Relevance-based Site Search with SQL | JarrodGoddard.com


/ Published in: SQL
Save to your folder(s)



Copy this code and paste it in your HTML
  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;

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.