首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >仅选择至少X字匹配的全文

仅选择至少X字匹配的全文
EN

Stack Overflow用户
提问于 2020-08-31 01:03:21
回答 2查看 61关注 0票数 1
代码语言:javascript
复制
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个要返回的全文匹配。

我该怎么做?

编辑一个答案建议如下。我得到了一个错误,“不正确的反对论点”。

代码语言:javascript
复制
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
EN

回答 2

Stack Overflow用户

发布于 2020-08-31 01:12:17

我不确定是否有一个简单的方法来做你想做的事。您可能需要将值枚举为行,然后使用关联子查询计算匹配的计数:

代码语言:javascript
复制
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的最新版本中:

代码语言:javascript
复制
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)
    ) >= ?
票数 3
EN

Stack Overflow用户

发布于 2020-08-31 01:25:04

一种方法是使用match获取一组初始文档。然后再加上其他逻辑:

代码语言:javascript
复制
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;

注意:这不是完全相同的逻辑,因为它只是寻找字符串。如果您想要更精确的逻辑,您可以使用正则表达式,但这可能不是必要的。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63663543

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档