Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

more_like_this resulting in exception #148

Open
dipth opened this Issue · 2 comments

2 participants

@dipth

I'm trying to get more_like_this to work, but I'm getting this error:

undefined method `more_like_this_fields' for nil:NilClass

Here is my searchable config:

searchable do
  integer :id
  text :title, :boost => 5, :more_like_this => true
  boolean :hidden
  integer :site_id
end

Here is my call to more_like_this:

@posts = Sunspot.more_like_this(post) do
  fields :title
  with(:site_id, post.site.id)
  with(:hidden, false)
end

Here's a full trace:

activesupport (3.0.9) lib/active_support/whiny_nil.rb:48:in `method_missing'
sunspot (1.3.0) lib/sunspot/dsl/more_like_this_query.rb:12:in `fields'
sunspot (1.3.0) lib/sunspot/dsl/more_like_this_query.rb:11:in `each'
sunspot (1.3.0) lib/sunspot/dsl/more_like_this_query.rb:11:in `fields'
sunspot (1.3.0) lib/sunspot/util.rb:241:in `__send__'
sunspot (1.3.0) lib/sunspot/util.rb:241:in `__proxy_method__'
sunspot (1.3.0) lib/sunspot/util.rb:236:in `method_missing'
app/cells/related_posts_cell.rb:67:in `by_likenes'
sunspot (1.3.0) lib/sunspot/util.rb:208:in `instance_eval'
sunspot (1.3.0) lib/sunspot/util.rb:208:in `instance_eval_with_context'
sunspot (1.3.0) lib/sunspot/util.rb:86:in `instance_eval_or_call'
sunspot (1.3.0) lib/sunspot/search/abstract_search.rb:210:in `build'
sunspot (1.3.0) lib/sunspot/session.rb:73:in `new_more_like_this'
sunspot (1.3.0) lib/sunspot/session.rb:81:in `more_like_this'
sunspot (1.3.0) lib/sunspot/session_proxy/abstract_session_proxy.rb:11:in `more_like_this'
sunspot (1.3.0) lib/sunspot.rb:381:in `more_like_this'
app/cells/related_posts_cell.rb:66:in `by_likenes'
actionpack (3.0.9) lib/abstract_controller/base.rb:150:in `send_action'
actionpack (3.0.9) lib/abstract_controller/base.rb:150:in `process_action'
actionpack (3.0.9) lib/abstract_controller/callbacks.rb:18:in `process_action'
activesupport (3.0.9) lib/active_support/callbacks.rb:431:in `_run__1998484214__process_action__1837307674__callbacks'
activesupport (3.0.9) lib/active_support/callbacks.rb:410:in `send'
activesupport (3.0.9) lib/active_support/callbacks.rb:410:in `_run_process_action_callbacks'
activesupport (3.0.9) lib/active_support/callbacks.rb:94:in `send'
activesupport (3.0.9) lib/active_support/callbacks.rb:94:in `run_callbacks'
actionpack (3.0.9) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.0.9) lib/abstract_controller/base.rb:119:in `process'
actionpack (3.0.9) lib/abstract_controller/rendering.rb:41:in `process'
cells (3.6.2) lib/cell/rails.rb:30:in `render_state'
cells (3.6.2) lib/cell/caching.rb:88:in `render_state'
cells (3.6.2) lib/cell.rb:21:in `render_cell_for'
cells (3.6.2) lib/cells/rails.rb:53:in `render_cell'
app/views/posts/show.html.erb:85:in `_app_views_posts_show_html_erb___910203779_2174137360_0'
actionpack (3.0.9) lib/action_view/helpers/capture_helper.rb:40:in `capture'
actionpack (3.0.9) lib/action_view/helpers/capture_helper.rb:172:in `with_output_buffer'
actionpack (3.0.9) lib/action_view/helpers/capture_helper.rb:40:in `capture'
actionpack (3.0.9) lib/action_view/helpers/capture_helper.rb:137:in `content_for'
app/views/posts/show.html.erb:55:in `_app_views_posts_show_html_erb___910203779_2174137360_0'
actionpack (3.0.9) lib/action_view/template.rb:135:in `send'
actionpack (3.0.9) lib/action_view/template.rb:135:in `render'
activesupport (3.0.9) lib/active_support/notifications.rb:54:in `instrument'
actionpack (3.0.9) lib/action_view/template.rb:127:in `render'
actionpack (3.0.9) lib/action_view/render/rendering.rb:59:in `_render_template'
activesupport (3.0.9) lib/active_support/notifications.rb:52:in `instrument'
activesupport (3.0.9) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.0.9) lib/active_support/notifications.rb:52:in `instrument'
actionpack (3.0.9) lib/action_view/render/rendering.rb:56:in `_render_template'
actionpack (3.0.9) lib/action_view/render/rendering.rb:26:in `render'
actionpack (3.0.9) lib/abstract_controller/rendering.rb:115:in `_render_template'
actionpack (3.0.9) lib/abstract_controller/rendering.rb:109:in `render_to_body'
actionpack (3.0.9) lib/action_controller/metal/renderers.rb:47:in `render_to_body'
actionpack (3.0.9) lib/action_controller/metal/compatibility.rb:55:in `render_to_body'
actionpack (3.0.9) lib/abstract_controller/rendering.rb:102:in `render_to_string'
actionpack (3.0.9) lib/abstract_controller/rendering.rb:93:in `render'
actionpack (3.0.9) lib/action_controller/metal/rendering.rb:17:in `render'
actionpack (3.0.9) lib/action_controller/metal/instrumentation.rb:40:in `render'
activesupport (3.0.9) lib/active_support/core_ext/benchmark.rb:5:in `ms'
/Users/thomas/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/benchmark.rb:308:in `realtime'
activesupport (3.0.9) lib/active_support/core_ext/benchmark.rb:5:in `ms'
actionpack (3.0.9) lib/action_controller/metal/instrumentation.rb:40:in `render'
actionpack (3.0.9) lib/action_controller/metal/instrumentation.rb:78:in `cleanup_view_runtime'
activerecord (3.0.9) lib/active_record/railties/controller_runtime.rb:15:in `cleanup_view_runtime'
sunspot_rails (1.3.0) lib/sunspot/rails/railties/controller_runtime.rb:15:in `cleanup_view_runtime'
actionpack (3.0.9) lib/action_controller/metal/instrumentation.rb:39:in `render'
actionpack (3.0.9) lib/action_controller/metal/implicit_render.rb:10:in `default_render'
actionpack (3.0.9) lib/action_controller/metal/implicit_render.rb:5:in `send_action'
actionpack (3.0.9) lib/abstract_controller/base.rb:150:in `process_action'
actionpack (3.0.9) lib/action_controller/metal/rendering.rb:11:in `process_action'
actionpack (3.0.9) lib/abstract_controller/callbacks.rb:18:in `process_action'
activesupport (3.0.9) lib/active_support/callbacks.rb:451:in `_run__84203013__process_action__453433196__callbacks'
activesupport (3.0.9) lib/active_support/callbacks.rb:410:in `send'
activesupport (3.0.9) lib/active_support/callbacks.rb:410:in `_run_process_action_callbacks'
activesupport (3.0.9) lib/active_support/callbacks.rb:94:in `send'
activesupport (3.0.9) lib/active_support/callbacks.rb:94:in `run_callbacks'
actionpack (3.0.9) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.0.9) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
activesupport (3.0.9) lib/active_support/notifications.rb:52:in `instrument'
activesupport (3.0.9) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.0.9) lib/active_support/notifications.rb:52:in `instrument'
actionpack (3.0.9) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.0.9) lib/action_controller/metal/rescue.rb:17:in `process_action'
actionpack (3.0.9) lib/abstract_controller/base.rb:119:in `process'
actionpack (3.0.9) lib/abstract_controller/rendering.rb:41:in `process'
actionpack (3.0.9) lib/action_controller/metal.rb:138:in `dispatch'
actionpack (3.0.9) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.0.9) lib/action_controller/metal.rb:178:in `action'
actionpack (3.0.9) lib/action_dispatch/routing/route_set.rb:62:in `call'
actionpack (3.0.9) lib/action_dispatch/routing/route_set.rb:62:in `dispatch'
actionpack (3.0.9) lib/action_dispatch/routing/route_set.rb:27:in `call'
rack-mount (0.6.14) lib/rack/mount/route_set.rb:148:in `call'
rack-mount (0.6.14) lib/rack/mount/code_generation.rb:93:in `recognize'
rack-mount (0.6.14) lib/rack/mount/code_generation.rb:859:in `optimized_each'
rack-mount (0.6.14) lib/rack/mount/code_generation.rb:92:in `recognize'
rack-mount (0.6.14) lib/rack/mount/route_set.rb:139:in `call'
actionpack (3.0.9) lib/action_dispatch/routing/route_set.rb:493:in `call'
omniauth (1.0.0) lib/omniauth/strategy.rb:168:in `call!'
omniauth (1.0.0) lib/omniauth/strategy.rb:148:in `call'
omniauth (1.0.0) lib/omniauth/builder.rb:30:in `call'
warden (1.0.5) lib/warden/manager.rb:35:in `call'
warden (1.0.5) lib/warden/manager.rb:34:in `catch'
warden (1.0.5) lib/warden/manager.rb:34:in `call'
actionpack (3.0.9) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
actionpack (3.0.9) lib/action_dispatch/middleware/head.rb:14:in `call'
rack (1.2.4) lib/rack/methodoverride.rb:24:in `call'
actionpack (3.0.9) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.0.9) lib/action_dispatch/middleware/flash.rb:182:in `call'
actionpack (3.0.9) lib/action_dispatch/middleware/session/abstract_store.rb:149:in `call'
actionpack (3.0.9) lib/action_dispatch/middleware/cookies.rb:302:in `call'
activerecord (3.0.9) lib/active_record/query_cache.rb:32:in `call'
activerecord (3.0.9) lib/active_record/connection_adapters/abstract/query_cache.rb:28:in `cache'
activerecord (3.0.9) lib/active_record/query_cache.rb:12:in `cache'
activerecord (3.0.9) lib/active_record/query_cache.rb:31:in `call'
activerecord (3.0.9) lib/active_record/connection_adapters/abstract/connection_pool.rb:354:in `call'
actionpack (3.0.9) lib/action_dispatch/middleware/callbacks.rb:46:in `call'
activesupport (3.0.9) lib/active_support/callbacks.rb:416:in `_run_call_callbacks'
actionpack (3.0.9) lib/action_dispatch/middleware/callbacks.rb:44:in `call'
rack (1.2.4) lib/rack/sendfile.rb:106:in `call'
actionpack (3.0.9) lib/action_dispatch/middleware/remote_ip.rb:48:in `call'
actionpack (3.0.9) lib/action_dispatch/middleware/show_exceptions.rb:47:in `call'
railties (3.0.9) lib/rails/rack/logger.rb:13:in `call'
rack (1.2.4) lib/rack/runtime.rb:17:in `call'
activesupport (3.0.9) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.2.4) lib/rack/lock.rb:11:in `call'
rack (1.2.4) lib/rack/lock.rb:11:in `synchronize'
rack (1.2.4) lib/rack/lock.rb:11:in `call'
actionpack (3.0.9) lib/action_dispatch/middleware/static.rb:30:in `call'
railties (3.0.9) lib/rails/application.rb:168:in `call'
railties (3.0.9) lib/rails/application.rb:77:in `send'
railties (3.0.9) lib/rails/application.rb:77:in `method_missing'
/Users/thomas/Library/Application Support/Pow/Versions/0.3.1/node_modules/nack/lib/nack/server.rb:146:in `handle'
/Users/thomas/Library/Application Support/Pow/Versions/0.3.1/node_modules/nack/lib/nack/server.rb:99:in `start'
/Users/thomas/Library/Application Support/Pow/Versions/0.3.1/node_modules/nack/lib/nack/server.rb:86:in `each'
/Users/thomas/Library/Application Support/Pow/Versions/0.3.1/node_modules/nack/lib/nack/server.rb:86:in `start'
/Users/thomas/Library/Application Support/Pow/Versions/0.3.1/node_modules/nack/lib/nack/server.rb:66:in `loop'
/Users/thomas/Library/Application Support/Pow/Versions/0.3.1/node_modules/nack/lib/nack/server.rb:66:in `start'
/Users/thomas/Library/Application Support/Pow/Versions/0.3.1/node_modules/nack/lib/nack/server.rb:13:in `run'
/Users/thomas/Library/Application Support/Pow/Versions/0.3.1/node_modules/nack/bin/nack_worker:4
@dipth

I'm using sunspot_rails 1.3.0

@JamesChevalier

I'm having similar trouble - the problem I'm having is a bit different in that it's only occurring when I pass more than one object through more_like_this, but the error it presents is extremely similar. Here's how my more_like_this call is a bit different from yours:

mlt_results = Sunspot.more_like_this(@article, Article, Video, Event) do
  fields :title
end

Here's the error that I get (again, slightly different from yours):
undefined method 'more_like_this_fields' for #<Sunspot::CompositeSetup:0x10e98d5a0>

I've been poking around trying to find the cause. I'm not certain, but I think the issue has something to do with the composite_setup.rb file.

The lib/sunspot/composite_setup.rb only has a def all_more_like_this_fields block ... it does not have a def more_like_this_fields block (see line 115 of composite_setup.rb).

If you check out line 156 of sunspot/lib/sunspot/setup.rb, you'll see that there's a def more_like_this_fields block. This handles the situation where one object is provided. If more than one object is provided, then sunspot can't handle it.

To get around the issue, I separated my more_like_this calls out, and then concatenated each of the separate results - like this:

mlt_articles = Sunspot.more_like_this(@article, Article) do
  fields :title
  with(:published_at).greater_than(1.months.ago)
end

mlt_videos = Sunspot.more_like_this(@article, Video) do
  fields :title
  with(:published_at).greater_than(1.months.ago)
end

@results = (mlt_articles + mlt_videos).sort! { |a,b| a.published_at <=> b.published_at }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.