简体   繁体   English

如何在MySql的全索引搜索中传递选择语句值?

[英]How to pass select statement values inside the full index search in mySql?

I would like to pass select body from articles result-set instead of database as a keyword inside the AGAINST parameter list. 我想将select body from articles结果集中的select body from articles而不是database作为关键字传递给AGAINST参数列表内的关键字。 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. 我已经创建了FULLTEXT索引,并且我的表是ISAM格式。 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. 由于一切都必须是动态的,因此我无法在AGAINST('Lorem Manager')传递关键字,因为在访问下一篇新闻时我们不知道关键字是什么,因此我嵌入了select语句以拉标题和身体。 I am getting result but somehow my stop keywords are not recognized. 我得到结果,但是不知何故我的stop关键字无法识别。

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. 为了更好地理解( 也许可以说明 )您的要求, 让我们用ExpressionEngine术语讨论一下,毕竟这就是您标记问题的目的。

Using the Agile Records ExpressionEngine site theme, let's use two fields from the About channel — Body and Staff Member's Title: 使用Agile Records ExpressionEngine网站主题,让我们使用About频道中的两个字段-Body和Staff Member's Title:

Body 身体
Custom Field: {about_body} 自定义字段: {about_body}
MySQL Column: field_id_4 MySQL栏: field_id_4

Staff Member's Title 职员职称
Custom Field: {about_staff_title} 自定义字段: {about_staff_title}
MySQL Column: field_id_6 MySQL栏: 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. 首先,如果尚未创建 ,则需要创建一个FULLTEXT索引 ,其中包含要搜索的所有列。

Using the two columns from above, execute the following SQL statement from phpMyAdmin or your favorite MySQL GUI Client: 使用上面的两列,从phpMyAdmin或您喜欢的MySQL GUI客户端执行以下SQL语句:

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: 您可以使用以下查询来验证新创建的INDEX:

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

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. 当使用自然语言全文搜索时,要求MATCH()函数中命名的列必须与表中某些FULLTEXT索引中包含的列相同。

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. 例如,在前面的示例中,注意在MATCH()函数中命名的列( field_id_4field_id_6 )与在商品表的FULLTEXT索引的定义中命名的列相同。

If you wanted to search the columns separately , you would need to create separate FULLTEXT indexes for each column. 如果你想单独搜索栏,你就需要为每个列创建FULLTEXT索引。


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. 停用词是一个非常普遍的词,例如“ the”或“ some”,以至于它被认为具有零语义值。 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. 默认停用词列表可以在11.9.4中查看 Full-Text Stopwords of the MySQL Documentation. MySQL文档的全文停用词

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM