How would you implement a custom search engine?
What do you think about something like this:
SELECT *
FROM jobs
WHERE job_id IN (
SELECT job_id
FROM job_words
WHERE word_id IN (SELECT word_id FROM words w WHERE text = 'carpenter'))
AND job_id IN (
SELECT job_id
FROM job_words
WHERE word_id IN (SELECT word_id FROM words w WHERE text = 'buildings'))
or this:
SELECT j.*
,s.matches
FROM jobs as j INNER JOIN
(SELECT jw.job_id, count(*) as matches
FROM job_words AS jw
INNER JOIN (SELECT word_id FROM words w WHERE text IN ('carpenter', 'buildings')) AS w ON w.word_id = jw.word_id
GROUP BY jw.job_id) as s ON s.job_id = j.job_id