Sphinx 返回错误的搜索结果 [英] Sphinx returning bad search results

查看:40
本文介绍了Sphinx 返回错误的搜索结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Sphinx 和 Thinking Sphinx 插件.我已经使用以下代码(以及 rake thinking_sphinx:index 命令)为名为 Venue 的模型编制了索引

I am using Sphinx with the Thinking Sphinx plugin. I have indexed a model called Venue with the following code (and the rake thinking_sphinx:index command)

define_index do
    indexes :name
    indexes city
    indexes zip
end

我使用以下代码在控制器中获取结果:

I obtain the results in my controller with this code:

@venues = Venue.search params[:search]

我将它们呈现为 json.我遇到的问题是,当我点击这个网址时:

and I render them as json. The problem I have is that when I hit this URL:

http://localhost:3000/venue/list?search=Baltimo

我一无所获.但是当我点击这个网址时:

I get nothing. But when I hit this URL:

http://localhost:3000/venue/list?search=Baltimor

我得到了位于巴尔的摩市的所有场地.出于某种原因,一个角色会有所作为.从理论上讲,如果我只搜索一个字符 - 'b'

I get all Venues located in the city of Baltimore. For some reason that one character makes a difference. Theoretically, I should be getting all Venues in Baltimore if I just search with one character - 'b'

有人知道这里发生了什么吗?

Does anyone know what is going on here?

谢谢

推荐答案

除非您将 enable_star 设置为 1 并且将 min_prefix_lenmin_infix_len 设置为为 1 或更多,你不会得到 B 来匹配巴尔的摩(即使那样,我认为你需要搜索 B* 来获得匹配).

Unless you have enable_star set to 1 and min_prefix_len or min_infix_len set to 1 or more, you won't get B to match Baltimore (and even then, I think you need to search for B* to get the match).

这里发生的是,默认情况下,Thinking Sphinx 告诉 Sphinx 使用英语词干分析器,它允许将相似单词(按字符,而不是按含义)视为匹配,所以它把 巴尔的摩巴尔的摩在同一个篮子里.

What's happening here is that by default, Thinking Sphinx tells Sphinx to use an English stemmer, which allows for similar words (by characters, not by meaning) to be considered matches, so it puts Baltimor and Baltimore in the same basket.

如果你想匹配任何单词的任何部分,那么你需要在 config/sphinx.yml 中放入如下内容:

If you want to get any part of any word matched, then you need to put something like the following in config/sphinx.yml:

development:
  enable_star: 1
  min_infix_len: 1
test:
  enable_star: 1
  min_infix_len: 1
production
  enable_star: 1
  min_infix_len: 1

然后停止 Sphinx,重新索引并重新启动 Sphinx.完成此操作后,搜索 B* 应返回 Baltimore.

Then stop Sphinx, re-index, and restart Sphinx. Once you've done that, then searches for B* should return Baltimore.

希望这会有所帮助.

这篇关于Sphinx 返回错误的搜索结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆