MySql FULLTEXT 与查找表中的关键字列表匹配

发布于 2024-11-14 12:05:48 字数 386 浏览 2 评论 0原文

我不知道这是否可行,但它会简化我的计算,以便能够通过单个查询来匹配查找表中的每个单词。 (否则,我可能会将表拉入内存并在 python 中编写一系列查询):

SELECT count(*) FROM input_form
WHERE MATCH (title,story) AGAINST (word);

上面将返回包含“word”的故事数量的计数,但是有什么方法可以让它重复这个计数对于包含这些单词的表中的每个单词?

SELECT 
word,
count(MATCH (title,story) AGAINST (word))
FROM keywords;

类似的事情?请注意,标题和故事来自一张表,单词来自另一张表。

I don't know if this is possible, but it would simplify my calculations to be able to match against each word in a lookup table with a single query. (otherwise, I'll probably pull the tables into memory and program a sequence of queries in python):

SELECT count(*) FROM input_form
WHERE MATCH (title,story) AGAINST (word);

The above will return a count for number of stories that contain 'word', but then is there some way to have it repeat this count for every word in a table containing these words?

SELECT 
word,
count(MATCH (title,story) AGAINST (word))
FROM keywords;

Something like that? Note that title and story are from one table, and word comes from another.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

云醉月微眠 2024-11-21 12:05:48

我有点生疏,但我认为你想使用嵌套选择:

SELECT tbl.word, count(*) FROM (SELECT * FROM input_form WHERE MATCH(title, story) AGAINST (word)) as tbl;

如果我记得的话,你可能需要添加另一层嵌套。

I'm a little rusty, but I think you want to use nested selects:

SELECT tbl.word, count(*) FROM (SELECT * FROM input_form WHERE MATCH(title, story) AGAINST (word)) as tbl;

You may have to add another level of nesting if I recall.

云之铃。 2024-11-21 12:05:48

是的。一段时间后,我认为这在 MySql 中几乎是不可能的,但我确实在循环内使用了 python MySql 模块的 db.cursor() 和cursor.execute() 方法来生成所需的表,然后将其上传到数据库(因为为页面动态执行此操作会很疯狂)。

Yup. After a while I decided this may be near impossible in MySql, but I did use the db.cursor() and cursor.execute() method of the python MySql module inside of a loop to generate the required table, then uploaded it into the database (since doing this dynamically for a page would be crazy).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文