Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 无法将印象派模型添加到Solr_Ruby_Solr_Ruby On Rails 3.2_Impressionist - Fatal编程技术网

Ruby 无法将印象派模型添加到Solr

Ruby 无法将印象派模型添加到Solr,ruby,solr,ruby-on-rails-3.2,impressionist,Ruby,Solr,Ruby On Rails 3.2,Impressionist,为了跟踪我添加的独特视图。由于流量增加,印象表将以更快的速度增长。当我以后想要显示连续周/月之间的比较时,这将导致问题 所以我想把impression的模型与solr链接起来 为了实现这一点,我首先在app/models/impression.rb文件夹下创建了一个名为impression的模型 class Impression < ActiveRecord::Base attr_accessible :user_id, :ip_address, :action_name, :c

为了跟踪我添加的独特视图。由于流量增加,印象表将以更快的速度增长。当我以后想要显示连续周/月之间的比较时,这将导致问题

所以我想把impression的模型与solr链接起来

为了实现这一点,我首先在
app/models/impression.rb
文件夹下创建了一个名为impression的模型

class Impression < ActiveRecord::Base

    attr_accessible :user_id, :ip_address, :action_name, :controller_name, :impressionable_type, :impressionable_id, :view_name, :session_hash, :message, :request_hash, :referrer

    searchable :ignore_attribute_changes_of => [ :updated_at] do
        text :message, :boost=> 2.0
        text :referrer
        text :ip_address
        integer :user_id
        time :created_at
        time :updated_at       
        string :message
        string :view_name
        string :ip_address
        string :impressionable_type 
        string :controller_name
        string :action_name
        string :session_hash
        string :request_hash
        integer :id
        integer :impressionable_id   
      end
end
接下来,我尝试使用solr查询
Impression
model

search = Sunspot.search Impression do
      with(:impressionable_type).equal_to('Blogpost')
      with(:impressionable_id).equal_to(1)
    end.total
    puts "total results #{search || 0}"
search
上述代码不断抛出此错误:

undefined method `field' for nil:NilClass
    from /home/xyz/.rvm/gems/ruby-2.1.0/gems/sunspot-2.1.0/lib/sunspot/dsl/standard_query.rb:112:in `with'
    from /home/xyz/.rvm/gems/ruby-2.1.0/gems/sunspot-2.1.0/lib/sunspot/util.rb:241:in `__proxy_method__'
    from /home/xyz/.rvm/gems/ruby-2.1.0/gems/sunspot-2.1.0/lib/sunspot/util.rb:236:in `method_missing'
from (irb):8:in `block in irb_binding'
    from /home/xyz/.rvm/gems/ruby-2.1.0/gems/sunspot-2.1.0/lib/sunspot/util.rb:208:in `instance_eval'
    from /home/xyz/.rvm/gems/ruby-2.1.0/gems/sunspot-2.1.0/lib/sunspot/util.rb:208:in `instance_eval_with_context'
    from /home/xyz/.rvm/gems/ruby-2.1.0/gems/sunspot-2.1.0/lib/sunspot/util.rb:86:in `instance_eval_or_call'
    from /home/xyz/.rvm/gems/ruby-2.1.0/gems/sunspot-2.1.0/lib/sunspot/search/abstract_search.rb:202:in `build'
    from /home/xyz/.rvm/gems/ruby-2.1.0/gems/sunspot-2.1.0/lib/sunspot/session.rb:50:in `new_search'
    from /home/xyz/.rvm/gems/ruby-2.1.0/gems/sunspot-2.1.0/lib/sunspot/session.rb:58:in `search'
    from /home/xyz/.rvm/gems/ruby-2.1.0/gems/sunspot-2.1.0/lib/sunspot/session_proxy/abstract_session_proxy.rb:11:in `search'
    from /home/xyz/.rvm/gems/ruby-2.1.0/gems/sunspot-queue-0.10.2/lib/sunspot/queue/session_proxy.rb:62:in `search'
    from /home/xyz/.rvm/gems/ruby-2.1.0/gems/sunspot-2.1.0/lib/sunspot.rb:345:in `search'
    from (irb):8
    from /home/xyz/.rvm/gems/ruby-2.1.0/gems/railties-3.2.14/lib/rails/commands/console.rb:47:in `start'
    from /home/xyz/.rvm/gems/ruby-2.1.0/gems/railties-3.2.14/lib/rails/commands/console.rb:8:in `start'
    from /home/xyz/.rvm/gems/ruby-2.1.0/gems/railties-3.2.14/lib/rails/commands.rb:41:in `<top (required)>'
    from script/rails:6:in `require'
nil:NilClass的未定义方法“field” from/home/xyz/.rvm/gems/ruby-2.1.0/gems/sunspot-2.1.0/lib/sunspot/dsl/standard_query.rb:112:in'with' from/home/xyz/.rvm/gems/ruby-2.1.0/gems/sunspot-2.1.0/lib/sunspot/util.rb:241:在“代理”方法中 from/home/xyz/.rvm/gems/ruby-2.1.0/gems/sunspot-2.1.0/lib/sunspot/util.rb:236:in'method_missing' from(irb):8:in`block in irb_binding' from/home/xyz/.rvm/gems/ruby-2.1.0/gems/sunspot-2.1.0/lib/sunspot/util.rb:208:in'instance_eval' from/home/xyz/.rvm/gems/ruby-2.1.0/gems/sunspot-2.1.0/lib/sunspot/util.rb:208:in`instance_eval_with_context' from/home/xyz/.rvm/gems/ruby-2.1.0/gems/sunspot-2.1.0/lib/sunspot/util.rb:86:in'instance_eval_或_call' from/home/xyz/.rvm/gems/ruby-2.1.0/gems/sunspot-2.1.0/lib/sunspot/search/abstract_search.rb:202:在“构建”中 from/home/xyz/.rvm/gems/ruby-2.1.0/gems/sunspot-2.1.0/lib/sunspot/session.rb:50:在“新搜索”中 from/home/xyz/.rvm/gems/ruby-2.1.0/gems/sunspot-2.1.0/lib/sunspot/session.rb:58:在“搜索”中 from/home/xyz/.rvm/gems/ruby-2.1.0/gems/sunsspot-2.1.0/lib/sunsspot/session\u proxy/abstract\u session\u proxy.rb:11:在“搜索”中 from/home/xyz/.rvm/gems/ruby-2.1.0/gems/sunspot-queue-0.10.2/lib/sunspot/queue/session_proxy.rb:62:在“搜索”中 from/home/xyz/.rvm/gems/ruby-2.1.0/gems/sunspot-2.1.0/lib/sunspot.rb:345:在“搜索”中 来自(irb):8 from/home/xyz/.rvm/gems/ruby-2.1.0/gems/railties-3.2.14/lib/rails/commands/console.rb:47:in'start' 从/home/xyz/.rvm/gems/ruby-2.1.0/gems/railties-3.2.14/lib/rails/commands/console.rb:8:in“开始” from/home/xyz/.rvm/gems/ruby-2.1.0/gems/railties-3.2.14/lib/rails/commands.rb:41:in`' 来自脚本/rails:6:in'require'
有人能告诉我如何创建一个Impression模型,以便与solr一起使用吗?

通过在
config/initializers/impressive_patch.rb
下添加相同的模型定义,解决了这个问题:

class Impression < ActiveRecord::Base

    attr_accessible :user_id, :ip_address, :action_name, :controller_name, :impressionable_type, :impressionable_id, :view_name, :session_hash, :message, :request_hash, :referrer

    searchable :ignore_attribute_changes_of => [ :updated_at] do
        text :message, :boost=> 2.0
        text :referrer
        text :ip_address
        integer :user_id
        time :created_at
        time :updated_at       
        string :message
        string :view_name
        string :ip_address
        string :impressionable_type 
        string :controller_name
        string :action_name
        string :session_hash
        string :request_hash
        integer :id
        integer :impressionable_id   
      end
end
类印象[:更新时间]do
text:message,:boost=>2.0
文本:推荐人
文本:ip地址
整数:用户id
时间:创建于
时间:更新于
字符串:消息
字符串:视图名称
字符串:ip_地址
字符串:易受影响的类型
字符串:控制器名称
字符串:操作名称
字符串:会话\u哈希
字符串:请求\u散列
整数:id
整数:易受影响的\u id
结束
结束
我能够在这个文件中定义我自己的类和实例方法

class Impression < ActiveRecord::Base

    attr_accessible :user_id, :ip_address, :action_name, :controller_name, :impressionable_type, :impressionable_id, :view_name, :session_hash, :message, :request_hash, :referrer

    searchable :ignore_attribute_changes_of => [ :updated_at] do
        text :message, :boost=> 2.0
        text :referrer
        text :ip_address
        integer :user_id
        time :created_at
        time :updated_at       
        string :message
        string :view_name
        string :ip_address
        string :impressionable_type 
        string :controller_name
        string :action_name
        string :session_hash
        string :request_hash
        integer :id
        integer :impressionable_id   
      end
end