自定义搜索引擎
您将如何实现自定义搜索引擎?
您对这样的事情有何看法:
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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您最好提前根据关键字构建表格。你的代码效率很低。
每次运行此代码时,基本上都会运行 O(n(n+n)) 。相反,请提前为所有“木匠”和“建筑物”制作表格,如果搜索查询的表格不存在,则使用您发布的代码。
You'd be better off building the tables from your keywords in advance. Your code is very inefficient.
You're basically running O(n(n+n)) every time you run this code. Instead make the tables for all the 'carpenter' and 'buildings' before hand and if the table for the search query doesn't exist then use the code you posted.