狮身人面像搜索部分关键字匹配

编程入门 行业动态 更新时间:2024-10-27 20:38:31
本文介绍了狮身人面像搜索部分关键字匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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

search_key =android samsung galaxy ace black手机

根据标题表搜索

titles(table) id | title

1 |诺基亚c6 2 |三星galaxy ace 3 | samsung galaxy ace y 4 |诺基亚Lumia 800 5 |三星蒙特 - 6 |三星Galaxy Note

case - 1:

> Title.search search_key,:match_mode => :全部 =>无结果

评论:坏

情况-2:

Title.search search_key,:match_mode => :任何 => [$ s $ / pre $ $ b

评论:好,但并不相关,用户只需要明确指定关键字中的samsung galaxy ace。为什么要显示其他三星手机?

$ b

p $ p> Title.search'search_key / 3',:match_mode => :延长 => samsung galaxy ace

评论:Bingo !,但硬编码。 b 问题:

现在,我应该知道有多少个关键字会在标题表。 (例如,在android三星银河王牌黑手机中的三星银河王牌3)

我该如何解决这个问题?。狮身人面像处理这个?如果不是该做什么?

解决方案

一种方法是将sphinx索引中的wordcount作为属性存储。

sql_field_str2wordcount是一个很好的方法来做到这一点 sphinxsearch/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->查询(\$ search_key \/ 1,标题);

(对不起,不知道如何在思维上做到这一点-sphinx particully。以上是PHP API语法)

编辑,检查 freelancing-god.github/ts/en/searching.html 和 freelancing-god.github/ts/en/common_issues.html#or_attributes

看起来可能类似于

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

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

I want to search the titles table. The expected user keyword will not be an exact match, it will be a partial match.

search_key = "android samsung galaxy ace black phones"

Searching against the titles table,

titles(table)

id | titles

1 | nokia c6 2 | samsung galaxy ace 3 | samsung galaxy ace y 4 | nokia lumia 800 5 | samsung monte 6 | samsung galaxy note

case - 1 :

Title.search search_key, :match_mode => :all =>No results

Comment: Bad

case -2 :

Title.search search_key, :match_mode => :any =>[samsung galaxy ace, samsung galaxy ace y, samsung monte, samsung galaxy note]

Comment: OK, but not relevant, the user wanted only "samsung galaxy ace" which she specified in her keywords explicitly. Why show other samsung mobiles ?

case -3 :

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

Comment: Bingo!, but hard coded.

Question:

Now, I should know how many number of keywords will get an exact match in the titles table. (For example, its 3 for "samsung galaxy ace" in "android samsung galaxy ace black phones")

How do I go around this?. Sphinx handles this?. If not what to do ?

解决方案

One way is to store a wordcount in the sphinx index as attribute.

sql_field_str2wordcount is a good way to do this sphinxsearch/docs/current.html#conf-sql-field-str2wordcount

You can then use it as a basis of a filter

$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');

(Sorry, dont know how to do this in thinking-sphinx particully. The above is the PHP API syntax)

Edit, checking freelancing-god.github/ts/en/searching.html and freelancing-god.github/ts/en/common_issues.html#or_attributes

looks like might be something like

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}

更多推荐

狮身人面像搜索部分关键字匹配

本文发布于:2023-11-24 15:26:43,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:狮身人面像   关键字

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!