如何在 mySql 的完整索引搜索中传递 select 语句值?

发布于 2024-12-26 00:42:37 字数 930 浏览 4 评论 0 原文

我想将 select body fromarticles 结果集而不是 database 作为 AGAINST 参数列表中的关键字传递。我怎样才能做到这一点?我想根据表中匹配的关键字找到相关文章。

SELECT * FROM articles
     WHERE MATCH (title,body)
     AGAINST ('database' IN NATURAL LANGUAGE MODE);

我想这样做:

SELECT * FROM articles
     WHERE MATCH (title,body)
     AGAINST ("select title,body from articles" IN NATURAL LANGUAGE MODE);

编辑 评论
我想根据文章频道中匹配关键词的密度来获取相关文章。我已经创建了 FULLTEXT 索引,并且我的表采用 ISAM 格式。目前文章频道包含字幕和正文自定义字段。由于一切都必须是动态的,所以我无法在 AGAINST('Lorem Manager') 中传递关键字,因为我们不知道当我们访问下一篇新闻文章时关键字是什么,所以我嵌入select 语句来提取标题和正文。我得到了结果,但不知何故我的停止关键字不被识别。

I would like to pass select body from articles result-set instead of database as a keyword inside the AGAINST parameter list. How can I do that?. I want to find the related articles based on the matching keywords from the table.

SELECT * FROM articles
     WHERE MATCH (title,body)
     AGAINST ('database' IN NATURAL LANGUAGE MODE);

I want do to this:

SELECT * FROM articles
     WHERE MATCH (title,body)
     AGAINST ("select title,body from articles" IN NATURAL LANGUAGE MODE);

Edit from comment:
I would like to get the related article based on the density of the matching keywords in the article channel. I have created the FULLTEXT index and my table is in ISAM format. Currently the article channel contains subtitle and body custom fields. Since everything has to be dynamic so I cannot pass the keywords inside the AGAINST('Lorem Manager') because we don't know what will be the keywords when we visit the next news article, so I embed select statement to pull the title and body. I am getting result but somehow my stop keywords are not recognized.

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

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

发布评论

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

评论(1

揽清风入怀 2025-01-02 00:42:37

您到底希望实现什么目标?

为了更好地理解(并可能说明)您所要求的内容,让我们用 ExpressionEngine 的用语来讨论,毕竟这就是您标记问题的内容。

使用 Agile Records ExpressionEngine 站点主题,让我们使用“关于”通道中的两个字段 — 正文和员工职务:

正文
自定义字段:{about_body}
MySQL 列:field_id_4

职员职称
自定义字段:{about_staff_title}
MySQL 列:field_id_6

首先,如果您还没有这样做,您需要 创建一个 FULLTEXT 索引,其中包含您正在搜索的所有列。

使用上面的两列,从 phpMyAdmin 或您最喜欢的 MySQL GUI 客户端执行以下 SQL 语句:

CREATE FULLTEXT INDEX related_articles
    ON exp_channel_data (field_id_4, field_id_6);

您可以使用以下查询验证新创建的 INDEX:

SHOW INDEX FROM exp_channel_data;

要针对文本集合 ( ) 对字符串(关键字)执行自然语言搜索一个或多个数据库列),请考虑以下内容...其中 LoremManager 是您的关键字:

SELECT * FROM exp_channel_data
    WHERE MATCH (field_id_4, field_id_6)
    AGAINST ('Lorem Manager' IN NATURAL LANGUAGE MODE);

这将返回如下结果集(为了便于阅读而进行了简化):

+----------+-------------+------------------------+
| entry_id | field_id_4  | field_id_6             |
+----------+-------------+------------------------+
|        3 | Lorem ipsum |                        |
|        8 |             | Product Manager        |
|        4 |             | Co-Owner/Label Manager |
+----------+-------------+------------------------+

使用自然语言全文时搜索时,要求 MATCH() 函数中指定的列与表中某些 FULLTEXT 索引中包含的列相同。

例如,在前面的示例中,请注意 MATCH() 函数中命名的列(field_id_4field_id_6)与文章表定义中命名的列相同全文索引。

如果您想单独搜索列,则需要为每列创建单独的 FULLTEXT 索引。


全文搜索中会忽略某些单词:

  • 任何太短的单词都会被忽略。全文搜索找到的单词的默认最小长度为四个字符。
  • 停用词列表中的单词将被忽略。停用词是诸如“the”或“some”之类的词,它非常常见,以至于被认为具有零语义价值。有一个内置的停用词列表,但它可以被用户定义的列表覆盖。

默认停用词列表可以在 11.9.4 中查看。 MySQL 文档的全文停用词

What are you hoping to achieve, exactly?

To better understand — and perhaps illustrate — what you're asking for, let's discuss things in ExpressionEngine parlance, after all that's what you tagged your question with.

Using the Agile Records ExpressionEngine site theme, let's use two fields from the About channel — Body and Staff Member's Title:

Body
Custom Field: {about_body}
MySQL Column: field_id_4

Staff Member's Title
Custom Field: {about_staff_title}
MySQL Column: field_id_6

First, if you haven't already, you need to create a single FULLTEXT index that contains all of the columns you're searching on.

Using the two columns from above, execute the following SQL statement from phpMyAdmin or your favorite MySQL GUI Client:

CREATE FULLTEXT INDEX related_articles
    ON exp_channel_data (field_id_4, field_id_6);

You can verify the newly created INDEX with the following query:

SHOW INDEX FROM exp_channel_data;

To perform a natural language search for a string (keywords) against a text collection (one or more database columns), consider the following ... where Lorem and Manager are your keywords:

SELECT * FROM exp_channel_data
    WHERE MATCH (field_id_4, field_id_6)
    AGAINST ('Lorem Manager' IN NATURAL LANGUAGE MODE);

Which would return a result set like the following (simplified for readability):

+----------+-------------+------------------------+
| entry_id | field_id_4  | field_id_6             |
+----------+-------------+------------------------+
|        3 | Lorem ipsum |                        |
|        8 |             | Product Manager        |
|        4 |             | Co-Owner/Label Manager |
+----------+-------------+------------------------+

When using natural-language full-text searches, it is a requirement that the columns named in the MATCH() function be the same columns included in some FULLTEXT index in your table.

For instance, in the preceding example note that the columns named in the MATCH() function (field_id_4 and field_id_6) are the same as those named in the definition of the article table's FULLTEXT index.

If you wanted to search the columns separately, you would need to create separate FULLTEXT indexes for each column.


Some words are ignored in full-text searches:

  • Any word that is too short is ignored. The default minimum length of words that are found by full-text searches is four characters.
  • Words in the stopword list are ignored. A stopword is a word such as “the” or “some” that is so common that it is considered to have zero semantic value. There is a built-in stopword list, but it can be overwritten by a user-defined list.

The default stop word list can be viewed in 11.9.4. Full-Text Stopwords of the MySQL Documentation.

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