您将如何实施自定义搜索引擎?
您如何看待这样的事情:
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'))
或者这个:
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
答案 0 :(得分:0)
您最好提前从关键字构建表格。你的代码效率很低。 每次运行此代码时,您基本上都在运行O(n(n + n))。而是事先为所有“木匠”和“建筑物”制作表格,如果搜索查询的表格不存在,则使用您发布的代码。
答案 1 :(得分:0)
SELECT * FROM jobs WHERE
job_id in (SELECT job_id FROM job_words WHERE
word_id in (SELECT word_id FROM words WHERE text in ('carpenter', 'buildings'))