Rails 3 Sunspot 全文搜索使用 [英] Rails 3 Sunspot Fulltext Search Usage

查看:48
本文介绍了Rails 3 Sunspot 全文搜索使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我在我的应用程序中实现了 sunspot_rails gem,以利用强大的 Solr 搜索引擎.我最近在全文搜索中查看了 Ryan 的 railscast,我注意到他正在使用他的搜索查询中的其他参数,例如 "-" 表示不应包含在全文搜索中的内容.

So I've implemented the sunspot_rails gem into my application to utilize the powerful Solr search engine. I recently checked out Ryan's railscast on full-text searching and I noticed he was using additional parameters in his search queries such as "-" to denote something that should NOT be including in the full-text search.

直到现在我才听说过这个,我想知道是否有一个用户友好的使用指南,我和我的用户都可以参考以将我的搜索功能发挥到最大.

I never heard about this until now, I was wondering if there was a user-friendly usage guide somewhere both me and my users can reference to take my search functionality to it's maximum capability.

我认为理想情况下,我希望为我的搜索表单制作一个类似于 Github 降价备忘单的删节版,供用户快速参考.

I think ideally I would like to make an abridged version similar to Github's markdown cheat-sheet for my search forms that users can quickly reference.

推荐答案

Sunspot 使用 Solr 的 DisMax 查询解析器,它具有非常简单的查询语法.在大多数情况下,它旨在灵活解析用户创建的查询.

Sunspot uses Solr's DisMax Query Parser, which has a very simple query syntax. For the most part, it is intended to flexibly parse user-created queries.

DisMax 识别三个特殊字符:+-".来自文档:

DisMax recognizes three special characters: +, -, and ". From the documentation:

[DisMax] 旨在支持用户提供的原始输入字符串,无需特殊转义.'+''-' 字符被视为后续术语的强制"和禁止"修饰符.包含在平衡引号字符 '"' 中的文本被视为短语,任何包含奇数个引号字符的查询都会被评估为好像根本没有引号字符一样.

[DisMax] is designed to be support raw input strings provided by users with no special escaping. '+' and '-' characters are treated as "mandatory" and "prohibited" modifiers for the subsequent terms. Text wrapped in balanced quote characters '"' are treated as phrases, any query containing an odd number of quote characters is evaluated as if there were no quote characters at all.

还有其他一些幕后"选项可以调整匹配文档的相关性.例如,最小匹配"指定必须存在的可选"字段(即不以 -+ 为前缀)的数量或比例.以及用于增强特定字段中的术语匹配或彼此相近的术语匹配等的选项.

There are a few other "behind the scenes" options to tune the relevancy of matched documents. For example, "minimum match" specifies the number or proportion of "optional" fields (i.e., not prefixed with - or +) which must be present. As well as options to boost term matches in specific fields, or term matches within close proximity to each other, and so on.

在 Sunspot 中,这些都在 options 参数中公开给 fulltext 方法,或者作为提供给该方法的块中的方法.

In Sunspot, these are all exposed in the options parameter to the fulltext method, or as methods within a block supplied to that method.

这篇关于Rails 3 Sunspot 全文搜索使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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