• <legend id='MbNI7'><style id='MbNI7'><dir id='MbNI7'><q id='MbNI7'></q></dir></style></legend>
    • <bdo id='MbNI7'></bdo><ul id='MbNI7'></ul>
    <tfoot id='MbNI7'></tfoot>

      <small id='MbNI7'></small><noframes id='MbNI7'>

    1. <i id='MbNI7'><tr id='MbNI7'><dt id='MbNI7'><q id='MbNI7'><span id='MbNI7'><b id='MbNI7'><form id='MbNI7'><ins id='MbNI7'></ins><ul id='MbNI7'></ul><sub id='MbNI7'></sub></form><legend id='MbNI7'></legend><bdo id='MbNI7'><pre id='MbNI7'><center id='MbNI7'></center></pre></bdo></b><th id='MbNI7'></th></span></q></dt></tr></i><div id='MbNI7'><tfoot id='MbNI7'></tfoot><dl id='MbNI7'><fieldset id='MbNI7'></fieldset></dl></div>

        如何操作 MySQL 全文搜索相关性以使一个字段比另一个字段更“有价值"?

        时间:2023-06-02
        <legend id='afkzR'><style id='afkzR'><dir id='afkzR'><q id='afkzR'></q></dir></style></legend>
        <tfoot id='afkzR'></tfoot>

            <bdo id='afkzR'></bdo><ul id='afkzR'></ul>

            <small id='afkzR'></small><noframes id='afkzR'>

            1. <i id='afkzR'><tr id='afkzR'><dt id='afkzR'><q id='afkzR'><span id='afkzR'><b id='afkzR'><form id='afkzR'><ins id='afkzR'></ins><ul id='afkzR'></ul><sub id='afkzR'></sub></form><legend id='afkzR'></legend><bdo id='afkzR'><pre id='afkzR'><center id='afkzR'></center></pre></bdo></b><th id='afkzR'></th></span></q></dt></tr></i><div id='afkzR'><tfoot id='afkzR'></tfoot><dl id='afkzR'><fieldset id='afkzR'></fieldset></dl></div>

                    <tbody id='afkzR'></tbody>
                  本文介绍了如何操作 MySQL 全文搜索相关性以使一个字段比另一个字段更“有价值"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  假设我有两列,关键字和内容.我在两者之间都有全文索引.我希望关键字中包含 foo 的行比内容中包含 foo 的行具有更高的相关性.我需要做什么才能使 MySQL 将关键字中的匹配项加权高于内容中的匹配项?

                  Suppose I have two columns, keywords and content. I have a fulltext index across both. I want a row with foo in the keywords to have more relevance than a row with foo in the content. What do I need to do to cause MySQL to weight the matches in keywords higher than those in content?

                  我正在使用匹配"语法.

                  I'm using the "match against" syntax.

                  解决方案:

                  能够以下列方式完成这项工作:

                  Was able to make this work in the following manner:

                  SELECT *, 
                  CASE when Keywords like '%watermelon%' then 1 else 0 END as keywordmatch, 
                  CASE when Content like '%watermelon%' then 1 else 0 END as contentmatch,
                  MATCH (Title, Keywords, Content) AGAINST ('watermelon') AS relevance 
                  FROM about_data  
                  WHERE MATCH(Title, Keywords, Content) AGAINST ('watermelon' IN BOOLEAN MODE) 
                  HAVING relevance > 0  
                  ORDER by keywordmatch desc, contentmatch desc, relevance desc 
                  

                  推荐答案

                  实际上,使用 case 语句来制作一对标志可能是更好的解决方案:

                  Actually, using a case statement to make a pair of flags might be a better solution:

                  select 
                  ...
                  , case when keyword like '%' + @input + '%' then 1 else 0 end as keywordmatch
                  , case when content like '%' + @input + '%' then 1 else 0 end as contentmatch
                  -- or whatever check you use for the matching
                  from 
                     ... 
                     and here the rest of your usual matching query
                     ... 
                  order by keywordmatch desc, contentmatch desc
                  

                  同样,只有当所有关键字匹配的排名都高于所有纯内容匹配时.我还假设关键字和内容都匹配是最高排名.

                  Again, this is only if all keyword matches rank higher than all the content-only matches. I also made the assumption that a match in both keyword and content is the highest rank.

                  这篇关于如何操作 MySQL 全文搜索相关性以使一个字段比另一个字段更“有价值"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:MySQL 安装:错误:无法构建 gem 本机扩展 下一篇:通过 SSH 隧道的 MySQL 连接 - 如何指定其他 MySQL 服务器?

                  相关文章

                      <bdo id='q0iH2'></bdo><ul id='q0iH2'></ul>
                  1. <i id='q0iH2'><tr id='q0iH2'><dt id='q0iH2'><q id='q0iH2'><span id='q0iH2'><b id='q0iH2'><form id='q0iH2'><ins id='q0iH2'></ins><ul id='q0iH2'></ul><sub id='q0iH2'></sub></form><legend id='q0iH2'></legend><bdo id='q0iH2'><pre id='q0iH2'><center id='q0iH2'></center></pre></bdo></b><th id='q0iH2'></th></span></q></dt></tr></i><div id='q0iH2'><tfoot id='q0iH2'></tfoot><dl id='q0iH2'><fieldset id='q0iH2'></fieldset></dl></div>
                    <legend id='q0iH2'><style id='q0iH2'><dir id='q0iH2'><q id='q0iH2'></q></dir></style></legend>

                    <tfoot id='q0iH2'></tfoot>

                    <small id='q0iH2'></small><noframes id='q0iH2'>