SELECT source, id
FROM memory_row
WHERE memory_id =10
AND MATCH(source)
AGAINST ('girl*, appears*, cool*, pragmatic*, things*, first*, glance*, actually*, warm*,
trusting*, created*, Design*, Children*, Togetsu*, existed*, solely*, activate*, Strings*,
experienced*, emotional*, damage*, young*, from*, experiments*, conducted*, her*, cruel*,
researchers*, sent*, Randall*, family*, treatment*, after*, sealing*, memories*, small*, world*,
older*, adoptive*, sister*, Naomi*')上面的查询返回只有几个单词匹配的结果。我只想返回的结果,其中至少包含X的条件,是匹配的。在上面的例子中,这个数字可以是10,这意味着该列必须包含至少10个要返回的全文匹配。
我该怎么做?
编辑一个答案建议如下。我得到了一个错误,“不正确的反对论点”。
select m.*
from memory_row m
where
memory_id = 10
and (
select count(*)
from (
select 'girl*' word
union all select 'appears*'
union all select 'actually*'
union all select 'girl*'
union all select 'cool*'
union all select 'pragmatic*'
union all select 'things*'
union all select 'first*'
union all select 'glance*'
union all select 'actually*'
) w
where match(m.source) against(w.word)
) >= 5发布于 2020-08-31 01:12:17
我不确定是否有一个简单的方法来做你想做的事。您可能需要将值枚举为行,然后使用关联子查询计算匹配的计数:
select m.*
from memory_row m
where
memory_id = 10
and (
select count(*)
from (
select 'girl*' word
union all select 'appears*'
...
) w
where match(m.source) against(w.word)
) >= ?其中,质量管理标记表示应该匹配的最小行数。
或者,在MySQL的最新版本中:
select m.*
from memory_row m
where
memory_id = 10
and (
select count(*)
from (values row('girl*'), row('appears*'), ...) w(word)
where match(m.source) against(w.word)
) >= ?发布于 2020-08-31 01:25:04
一种方法是使用match获取一组初始文档。然后再加上其他逻辑:
SELECT mr.*
FROM (SELECT source, id
FROM memory_row
WHERE memory_id = 10 AND
MATCH(source) AGAINST ('girl*, appears*, cool*, pragmatic*, things*, first*, glance*, actually*, warm*,
trusting*, created*, Design*, Children*, Togetsu*, existed*, solely*, activate*, Strings*,
experienced*, emotional*, damage*, young*, from*, experiments*, conducted*, her*, cruel*,
researchers*, sent*, Randall*, family*, treatment*, after*, sealing*, memories*, small*, world*,
older*, adoptive*, sister*, Naomi*')
) mr
WHERE ( (source like '%girl%') +
(source like '%actually%') +
. . .
) >= 10;注意:这不是完全相同的逻辑,因为它只是寻找字符串。如果您想要更精确的逻辑,您可以使用正则表达式,但这可能不是必要的。
https://stackoverflow.com/questions/63663543
复制相似问题