【问题标题】:Thinking sphinx fuzzy search?思考狮身人面像模糊搜索?
【发布时间】:2011-05-19 09:51:07
【问题描述】:

我正在我的 rails 应用程序中实现 sphinx 搜索。
我想用模糊搜索。它应该搜索拼写错误,例如,如果输入搜索查询 charact*a*ristics,它应该搜索 charact*e*ristics。

我应该如何实现这个

【问题讨论】:

    标签: sphinx thinking-sphinx


    【解决方案1】:

    Sphinx 自然不会允许拼写错误 - 它不关心单词拼写是否正确,它只是对它们进行索引并匹配它们。

    有两种选择 - 要么使用thinking-sphinx-raspell 来捕获用户搜索时的拼写错误,并为他们提供使用改进的查询再次搜索的选择(就像 Google 所做的那样);或者也许使用 soundex 或 metaphone 形态,以便单词以一种说明它们发音的方式被索引。在this page 上搜索词干,您会找到相关部分。也请阅读Sphinx's documentation 了解此事。

    我不知道这两个选项有多可靠 - 就个人而言,我会选择 #1。

    【讨论】:

    • 感谢 pat,我曾想过使用 raspell,但不符合我的要求。我正在阅读电子邮件内容并搜索通过电子邮件订购的可能产品名称。我无法向用户建议更正的选项。使用 raspell 时,它会将一些缩写名称替换为不相关的替代名称,例如将 led(LED) 替换为 lid。也尝试过 soundex 和 metaphone,它对我来说改善了结果,但不准确。
    【解决方案2】:

    默认情况下,Sphinx 不注意使用星号字符进行通配符搜索。不过,您可以打开它:

    development:
      enable_star: true
      # ... repeat for other environments
    

    参见http://pat.github.io/thinking-sphinx/advanced_config.html 通配符/星号语法部分。

    【讨论】:

      【解决方案3】:

      是的,Sphinx 通常总是使用扩展匹配模式。

      有以下匹配模式可供选择:

      SPH_MATCH_ALL, matches all query words (default mode);
      SPH_MATCH_ANY, matches any of the query words;
      SPH_MATCH_PHRASE, matches query as a phrase, requiring perfect match;
      SPH_MATCH_BOOLEAN, matches query as a boolean expression (see Section 5.2, “Boolean query syntax”);
      SPH_MATCH_EXTENDED, matches query as an expression in Sphinx internal query language (see Section 5.3, “Extended query syntax”);
      SPH_MATCH_EXTENDED2, an alias for SPH_MATCH_EXTENDED;
      SPH_MATCH_FULLSCAN, matches query, forcibly using the "full scan" mode as below. NB, any query terms will be ignored, such that filters, filter-ranges and grouping will still be applied, but no text-matching.
      

      SPH_MATCH_EXTENDED2 在 0.9.8 和 0.9.9 开发周期中使用,当时正在重写内部匹配引擎(为了增加功能和更好的性能)。到 0.9.9 版本,旧版本已被删除,SPH_MATCH_EXTENDED 和 SPH_MATCH_EXTENDED2 现在只是别名。

      enable_star

      在搜索前缀/中缀索引时启用星型语法(或通配符语法)。 > 可选,默认为 0(不使用通配符语法),与 0.9.7 兼容。 >已知值为 0 和 1。

      例如,假设索引是用中缀构建的,并且 enable_star 为 1。搜索应该如下工作:

      "abcdef" query will match only those documents that contain the exact "abcdef" word in them.
      "abc*" query will match those documents that contain any words starting with "abc" (including the documents which contain the exact "abc" word only);
      "*cde*" query will match those documents that contain any words which have "cde" characters in any part of the word (including the documents which contain the exact "cde" word only).
      "*def" query will match those documents that contain any words ending with "def" (including the documents that contain the exact "def" word only).
      

      例子:

      enable_star = 1

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-07-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多