自定义搜索引擎

发布于 2024-09-27 22:26:17 字数 741 浏览 0 评论 0原文

您将如何实现自定义搜索引擎?

您对这样的事情有何看法:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

单挑你×的.吻 2024-10-04 22:26:17

您最好提前根据关键字构建表格。你的代码效率很低。
每次运行此代码时,基本上都会运行 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.

森林迷了鹿 2024-10-04 22:26:17
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'))
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'))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文