【问题标题】:sphinx search for partial keyword matchessphinx 搜索部分关键字匹配
【发布时间】:2012-04-24 13:11:58
【问题描述】:

Ruby on Rails -> ThinkingSphinx -> SphinxSearch -> Mysql

我想搜索titles 表。预期的用户关键字不会完全匹配,而是部分匹配。

search_key = "android samsung galaxy ace black phones"

搜索titles表,

标题(表格)

标识 |标题

1 |诺基亚 c6
2 |三星银河王牌
3 |三星 Galaxy ace y
4 |诺基亚 lumia 800
5 |三星蒙特
6 |三星银河笔记

案例 - 1:

Title.search search_key, :match_mode => :all

=>No results

评论:不好

案例-2:

Title.search search_key, :match_mode => :any

=>[samsung galaxy ace, samsung galaxy ace y, samsung monte, samsung galaxy note]

评论:好的,但不相关,用户只想要她在关键字中明确指定的“三星银河王牌”。为什么要显示其他三星手机?

案例-3:

Title.search 'search_key/3',:match_mode => :extended

=> samsung galaxy ace

评论:宾果游戏!,但硬编码。

问题:

现在,我应该知道有多少关键字会在titles 表中得到完全匹配。 (例如“android samsung galaxy ace black 手机”中的“samsung galaxy ace”的3)

我该如何解决这个问题?狮身人面像处理这个?如果不行怎么办?

【问题讨论】:

    标签: mysql full-text-search sphinx thinking-sphinx partial


    【解决方案1】:

    一种方法是将字数作为属性存储在 sphinx 索引中。

    sql_field_str2wordcount 是一个很好的方法 http://sphinxsearch.com/docs/current.html#conf-sql-field-str2wordcount

    然后您可以将其用作过滤器的基础

    $cl->setMatchMode(SPH_MATCH_EXTENDED);
    $cl->setRankingMode(SPH_RANK_WORDCOUNT);
    $cl->setSelect("*,IF(@weight=>titles,1,0) as myfilter");
    $cl->setFilter("myfilter",array(1));
    $cl->Query("\"$search_key\"/1",'Title');
    

    (抱歉,在thinking-sphinx中不知道具体怎么做。以上是PHP API语法)


    编辑,检查http://freelancing-god.github.com/ts/en/searching.htmlhttp://freelancing-god.github.com/ts/en/common_issues.html#or_attributes

    看起来可能有点像

    with_display = "*, IF(@weight=>titles,1,0) AS display"
    Title.search 'search_key/3',
      :match_mode => :extended,
      :rank_mode => :wordcount,
      :sphinx_select => with_display,
      :with          => {'display' => 1}
    

    【讨论】:

    • 忘记语法,你能解释一下这里发生了什么吗?
    • 使用每个标题中的单词数 - 存储为属性。然后将其与搜索中匹配的单词数进行比较。使用 wordcount 排名模式给你匹配的词数,它需要与单个标题中的词数相同。即对于“三星银河王牌”字数 - 所以对于该行,该行的字数需要为 3 或更多。
    • 对不起,让我们一步一步来。发生了什么是你的 setSelect?,什么是 @weight =>titles,1,0 ?
    • 它创建了一个虚拟属性,这是比较的结果(计算的行权重和存储的字数 - 在属性中)sphinxsearch.com/docs/current.html#comparison-functions
    • 我正在做一些研究。我一会儿就回来
    【解决方案2】:

    找到答案

    如果您安装 Sphinx 2.0.4-dev (rel20-r3193),这将有效。

    点击此链接,

    http://sphinxsearch.com/forum/view.html?id=9387

    先生。 Barry Hunter,非常感谢您的支持。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-11
      • 2015-05-05
      • 1970-01-01
      • 2023-04-03
      • 2014-05-09
      • 1970-01-01
      相关资源
      最近更新 更多