知识点
相关文章
更多最近更新
更多sunspot mongo search 步骤和注意事项
2019-03-27 01:21|来源: 网路
前引:sunspot 类似thiking_sphinx的一个搜索的gem ,它是基于Solr搜索! (它支持的rails 版本是3.0以上)
我做的一个测试项目步骤和注意事项!
1、添加它的gem
gem 'sunspot_rails'
gem 'sunspot_solr'
如果bundle install 报错误,就这样写
gem 'sunspot_rails', :git => 'https://github.com/sunspot/sunspot.git', :ref => '79175ea'
gem 'sunspot_solr',:git => 'https://github.com/sunspot/sunspot', :ref => '79175ea'
用mongo数据库,引入 gem 'sunspot_mongoid'(当然链接mongo库的gem 也要引入)
2,添加你的 model
把需要搜索的字段这样来定义: searchable do
text :name
end
这个地方貌似可以声明自动生成索引,searchable :auto_index => true, :auto_remove => true do
text :name
end
3,生成索引,启动 sunspot 建议你先用sunspot-solr start这个命令看看,有没有报错!如果有报错那就把这个gem加入gem 'escape','0.0.4'
bundle exec rake sunspot:solr:reindex
bundle exec sunspot-solr start -p 8983
4、应该可以搜索了,mongo的不能用search函数 要用TestMongo.solr_search { fulltext 'h' } ,这个问题我也没搞明白!希望高手call me!thanks
当然你的系统要安装有jdk 噢 而且版本是 1.5以上! https://github.com/sunspot/sunspot 这个是gem 的位置
转自:http://my.oschina.net/qinjker/blog/71047
相关问答
更多-
搜索solr和太阳黑子(Search solr and sunspot)[2022-02-07]
您需要在Solr schema.xml对其进行配置,以计算文本字段的N-gram。 这是一个可能的例子:你快到了。 哈希语法是指您将最小匹配作为参数传递给fulltext 。 Article.search do fulltext params[:q], :minimum_match => 1 end 在块中,您需要方法调用。 Article.search do fulltext params[:q] do minimum_match 1 end end You're almost there. The hash syntax is when you're passing minimum ...更清楚的是,在adapters.rb(sunspot / lib / sunspot / adapters.rb)的顶部,添加以下行: require 'forwardable' module Sunspot # # Sunspot works by saving references to the primary key (or natural ID) of To be even more clear, at the top of adapters.rb (sunspot/lib/s ...如何在rails应用程序中使用Sunspot和Solr返回搜索结果?(How to return search results with Sunspot and Solr in rails app?)[2021-11-14]
使用获取搜索结果 @result = @search.results 看看这个railscasts教程 Get the search result using @result = @search.results Take a look at this railscasts tutorial它应该完全相同... AFAIK Solr不能直接使用数据库,而是提供REST API来存储,索引和搜索文档。 It should be exactly the same... AFAIK Solr doesn't work with database directly but rather provides REST API to store, index and search documents.如何使用Sunspot / Solr搜索has_many关联?(How to search in has_many association using Sunspot/Solr?)[2022-03-13]
这很好,问题是STI。 我有一个覆盖用户块的运动员块。 This works fine, the problem was STI. I had an Athlete block that was overriding the User block.已解决“组”选项 s = Step.search do group :route_id order_by_geodist(:coordinates, lat, lng) end s.group(:route_id).groups.each do |g| logger.info g.value logger.info g.results[0].inspect end Resolved with the "group" option s = Step.search do ...弄清楚了。 我的应用程序的schema.xml文件未触及websolr实例,该实例具有自己的schema.xml(可通过“高级配置”选项卡进行编辑)。 在那里做出改变,现在一切都按预期工作。 真棒。 Figured it out. My app's schema.xml file didn't touch the websolr instance, which has its own schema.xml (editable through the "advanced configuration" tab) ...只是为了澄清,除了这个问题的明显答案(添加:multiple => true to searchable block - 你不能使用这样的字段进行排序!),人们必须意识到solr!= sunspot: solr是一个搜索引擎(使用Apache的Lucene) sunspot是一个非常好写的DSL(特别是当与那些巨大的xml配置文件相比 - java遗产)在solr之上,暴露了大部分的solr选项(甚至所有,我不确定) 所以基本上,如果你想为solr调整一些答案,你应该尝试在太阳黑子的DSL中“缠绕”它。 T ...问题在于您在控制器中进行搜索的方式。 你说在理想世界中你想从选择元素中选择制造商: <%= simple_form_for :search, url: vehicles_path , :method => :get do |f| %> <%= select_tag :manufacturer, options_from_collection_for_select(Manufacturer.all, :id, :name) %> <%= submit_tag "Search", :name => nil ...