简体   繁体   English

Ruby on Rails全文搜索

[英]Ruby on Rails Full Text Search

How can i search full text with sentence and search any word matched or different configuration 我如何用句子搜索全文并搜索匹配或不同配置的任何单词

example: 例:

"professor john smith" is searching in model title “约翰·史密斯教授”正在搜索模特儿标题

it have to display result which matched the "proffessor john smith", "professor john" ", "proffesson smith" 必须显示与“约翰·史密斯教授”,“约翰·约翰教授”,“约翰·史密斯教授”相匹配的结果

There are lots of fulltext search technologies supports rails. 有很多全文搜索技术支持rails。 elasticsearch and solar search ar eone of them elasticsearch和solar search都是其中之一

Rails cast about integrating solar search is here 关于整合太阳能搜索的Rails 在这里

There are some technologies compatible with rails. 有一些与滑轨兼容的技术。 For example sunspot, as @scottxu wrote, or elasticsearch, as @knotito said. 例如@scottxu所写的黑子,或@knotito所描述的elasticsearch。 Good solution also - sphinx (fast and lite) and thinking_sphinx gem. 好的解决方案- 狮身人面像 (快速和精简)和think_sphinx gem。 If you use postgresql as database, and you do not want use external solutions - you can choose pg_search gem, that emplements fulltext search with pg technologies only. 如果您将postgresql用作数据库,并且不想使用外部解决方案-您可以选择pg_search gem,它仅支持使用pg技术进行全文搜索。 I prefer elasticsearch, but it requires JVM, and some people don't like this. 我更喜欢elasticsearch,但是它需要JVM,有些人不喜欢这样。

updated: 更新:

how to use pg_search: First, you should add pg_search to gemfile, make bundle install , and add to your model something like: 如何使用pg_search:首先,您应该将pg_search添加到gemfile,进行bundle install ,然后将以下内容添加到模型中:

include PgSearch
pg_search_scope :search_by_title, :against => :title

if you didn't do it before. 如果您以前没有做过。

After, you can try to test it in rails console: Professor.search_by_title('professor smith') 之后,您可以尝试在Rails控制台中对其进行测试:Professor.search_by_title('professor smith')

For fulltext searches you can use Elasticsearch 对于全文搜索,您可以使用Elasticsearch

To implement that you can follow this railscast 要实现这一点,您可以按照以下说明进行操作

you can use sunspot 你可以使用黑子

description: Sunspot is a Ruby library for expressive, powerful interaction with the Solr search engine. 描述:Sunspot是一个Ruby库,用于与Solr搜索引擎进行富有表现力的强大交互。 Sunspot is built on top of the RSolr library, which provides a low-level interface for Solr interaction; Sunspot建立在RSolr库的顶部,该库为Solr交互提供了一个低级接口。 Sunspot provides a simple, intuitive, expressive DSL backed by powerful features for indexing objects and searching for them. Sunspot提供了简单,直观,富有表现力的DSL,并以强大的功能为后盾,可为对象建立索引并对其进行搜索。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM