我知道您可以通过设置agent.user_agent_alias ='Linux Mozilla'来使用一组预定义的别名,但是如果我想设置我自己的用户代理,因为我正在编写一个Web爬虫,并希望识别它,对于我正在索引的网站.就像Googlebot一样.
似乎有一个user_agent方法,但我似乎找不到任何关于它的功能的文档.
我正在将我的应用程序升级到Rails 4,现在得到了我的rails服务器,以及太阳黑子solr,经过大量的修补,运行后,我可以访问Solr管理页面.但是,当我尝试从我的rails开发应用程序访问solr进行搜索或索引时,我收到以下错误
RSolr::Error::Http (RSolr::Error::Http - 404 Not Found
Error: Not Found
Request Data: "fq=type%3AMatch&fq=date_in_utc_d%3A%7B2013%5C-11%5C-29T21%5C%3A00%5C%3A00Z+TO+%2A%7D&fq=approval__s%3AAPPROVED&sort=date_d+asc&q=london&fl=%2A+score&qf=caption_text%5E10+city_name_text%5E10+team_name_text%5E10+&defType=edismax&start=0&rows=30"
Backtrace: /Users/bashar/.rvm/gems/ruby-2.0.0-p353/gems/rsolr-1.0.9/lib/rsolr/client.rb:268:in `adapt_response'
/Users/bashar/.rvm/gems/ruby-2.0.0-p353/gems/rsolr-1.0.9/lib/rsolr/client.rb:175:in `execute'
/Users/bashar/.rvm/gems/ruby-2.0.0-p353/gems/rsolr-1.0.9/lib/rsolr/client.rb:161:in `send_and_receive'
/Users/bashar/.rvm/gems/ruby-2.0.0-p353/gems/sunspot_rails-2.1.0/lib/sunspot/rails/solr_instrumentation.rb:16:in `block in send_and_receive_with_as_instrumentation'
/Users/bashar/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.0.1/lib/active_support/notifications.rb:159:in `block in instrument'
/Users/bashar/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.0.1/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/Users/bashar/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.0.1/lib/active_support/notifications.rb:159:in `instrument'
/Users/bashar/.rvm/gems/ruby-2.0.0-p353/gems/sunspot_rails-2.1.0/lib/sunspot/rails/solr_instrumentation.rb:15:in `send_and_receive_with_as_instrumentation'
(eval):2:in `post'
/Users/bashar/.rvm/gems/ruby-2.0.0-p353/gems/sunspot-2.1.0/lib/sunspot/search/abstract_search.rb:45:in `execute'
/Users/bashar/.rvm/gems/ruby-2.0.0-p353/gems/sunspot-2.1.0/lib/sunspot/session.rb:59:in `search'):
<a href="txmt://open?url=file:///Users/bashar/rails-projects/myapp/app/models/match.rb&line=474&column=1">app/models/match.rb:474:in `upcoming_games'</a>
<a href="txmt://open?url=file:///Users/bashar/rails-projects/myapp/app/controllers/tickets_controller.rb&line=34&column=1">app/controllers/tickets_controller.rb:34:in `search'</a>
Rendered /Users/bashar/.rvm/gems/ruby-2.0.0-p353/gems/actionpack-4.0.1/lib/action_dispatch/middleware/templates/rescues/_source.erb (0.4ms)
Rendered /Users/bashar/.rvm/gems/ruby-2.0.0-p353/gems/actionpack-4.0.1/lib/action_dispatch/middleware/templates/rescues/_trace.erb (0.8ms)
Rendered /Users/bashar/.rvm/gems/ruby-2.0.0-p353/gems/actionpack-4.0.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (0.8ms)
Rendered /Users/bashar/.rvm/gems/ruby-2.0.0-p353/gems/actionpack-4.0.1/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (17.3ms)
Run Code Online (Sandbox Code Playgroud)
这是sunspot.yml文件.
production:
solr:
hostname: ENV['WEBSOLR_URL']
port: 80
log_level: WARNING
path: /solr/production
# read_timeout: 2
# open_timeout: 0.5 …
Run Code Online (Sandbox Code Playgroud) ruby-on-rails sunspot sunspot-rails sunspot-solr ruby-on-rails-4
这已被问了很多,但我仍然面临一些问题.
我收到日期并存储为日期.我需要查询大于和小于,所以我将其更改为时间,再次尝试,但我得到了奇怪的结果.
我这样做
Class.where(:event_date.gt => Time.parse(Date.today))
Run Code Online (Sandbox Code Playgroud)
而我正在创造旧纪录,20世纪40年代,60年代和其他人.我尝试通过在最后添加.utc来转换时间,仅与Date.today进行比较,但到目前为止还没有解决问题.这是Mongoid生成的选择器
selector: {:date_utc=>{"$gte"=>Sat Sep 10 21:00:00 UTC 2011}},
Run Code Online (Sandbox Code Playgroud)
我以"2011-09-11"格式收到日期并将其存储在时间字段中.尝试解析时间utc,没有运气.
任何的想法?我正在使用Mongoid 2.0.2.以后的版本似乎与我正在使用的其他扩展不兼容.
[UPDATE]
所以问题在于1970年之前的旧日期显然.我现在的问题是如何处理它们.
当尝试在Heroku上执行rake或console命令时,我不断收到此错误:
Error: EISDIR: illegal operation on a directory, read at Error (native)
at Object.fs.readSync (fs.js:725:19)
at tryReadSync (fs.js:480:20)
at Object.fs.readFileSync (fs.js:528:19)
at /Users/bashar/.local/share/heroku/cli/lib/node_modules/heroku-cli-util/lib/got.js:75:15
at Array.map (native)
at getCerts (/Users/bashar/.local/share/heroku/cli/lib/node_modules/heroku-cli-util/lib/got.js:72:20)
at addToOpts (/Users/bashar/.local/share/heroku/cli/lib/node_modules/heroku-cli-util/lib/got.js:85:15)
at got (/Users/bashar/.local/share/heroku/cli/lib/node_modules/heroku-cli-util/lib/got.js:104:27)
at request (/Users/bashar/.local/share/heroku/cli/lib/node_modules/heroku-cli-util/lib/rollbar.js:9:10)
Run Code Online (Sandbox Code Playgroud)
任何的想法?
使用CarrierWave和Amazon S3,我能够存储来自本地文件的图像,但是当我尝试从某个URL存储它们时,我得到'TypeError:无法将nil转换为String'
from /Users/bashar/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/carrierwave-0.5.8/lib/carrierwave/uploader/cache.rb:149:in `join'
from /Users/bashar/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/carrierwave-0.5.8/lib/carrierwave/uploader/cache.rb:149:in `cache_path'
from /Users/bashar/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/carrierwave-0.5.8/lib/carrierwave/uploader/cache.rb:121:in `block in cache!'
from /Users/bashar/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/carrierwave-0.5.8/lib/carrierwave/uploader/callbacks.rb:17:in `with_callbacks'
from /Users/bashar/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/carrierwave-0.5.8/lib/carrierwave/uploader/cache.rb:112:in `cache!'
from /Users/bashar/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/carrierwave-0.5.8/lib/carrierwave/uploader/store.rb:56:in `store!'
from (irb):5
from /Users/bashar/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/commands/console.rb:45:in `start'
from /Users/bashar/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/commands/console.rb:8:in `start'
from /Users/bashar/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/commands.rb:40:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Run Code Online (Sandbox Code Playgroud)
这是我正在尝试的代码
require 'open-uri'
image = "open(image_url)
@object.image.store!(file)
Run Code Online (Sandbox Code Playgroud)
显然@object拥有Uploader图像,它使用本地文件系统工作正常.我试着添加一个
def root Rails.root.join'public /'end
我的上传者也没有运气.
任何的想法?
我注意到以AND/OR/NOT示例('this AND')之类的逻辑运算符结尾的查询将导致错误.现在处理这个问题的最佳方法是什么?只是删除或逃避以其中一个结尾的所有查询?请注意,对于以这些单词之一开头的查询,也会发生这种情况.有时候,有效的名字会以这样的词结尾,比如Oregon OR.
mongoid ×2
carrierwave ×1
heroku ×1
mechanize ×1
mongodb ×1
ruby ×1
solr ×1
sunspot ×1
sunspot-solr ×1