Compatibility with Rails 4.0.0.beta and reliance on ActiveSupport 3.0

65 views
Skip to first unread message

rfichoke

unread,
Aug 11, 2012, 1:44:10 PM8/11/12
to picky...@googlegroups.com
I've just started looking at Picky, and it seems like a good solution to my search problems in an application I'm writing.  I'm working with Rails 4.0.0.beta from Git, and when I added Picky to my Gemfile, it complained about a conflicting requirement for ActiveSupport ~3.0.  How much of Picky is dependent on ActiveSupport?  Is there already a plan in place for supporting Rails 4?

Picky / Florian Hanke

unread,
Aug 11, 2012, 4:31:19 PM8/11/12
to picky...@googlegroups.com
Hi,

I updated the latest version 4.6.2 to be more lax regarding activesupport requirements (~> 3). Can you try again?
Picky does not support Rails per se – and I usually recommend running it as a separate server, to keep concerns nicely separated (-> caching is easier, restarting app is not coupled, etc.).

Does that help?

Cheers,
   Florian

rfichoke

unread,
Aug 11, 2012, 10:17:38 PM8/11/12
to picky...@googlegroups.com
Bundler is still complaining about the incompatibility, which I don't get.  But at least I can start Rails with picky-client in my Gemfile now.  Strange.

Florian R. Hanke

unread,
Aug 11, 2012, 10:27:43 PM8/11/12
to picky...@googlegroups.com
What does it say exactly?

rfichoke

unread,
Aug 11, 2012, 11:16:20 PM8/11/12
to picky...@googlegroups.com
Bundler could not find compatible versions for gem "activesupport":
  In Gemfile:
    picky-client (= 4.6.2) ruby depends on
      activesupport (~> 3) ruby

    rails (>= 0) ruby depends on
      activesupport (4.0.0.beta)

By the way, I've got "extend Picky::Client::ActiveRecord.new(...)" in my Rails model, but I'm confused as to how to set up the Sinatra server.  Even though I have the Rails model set up to update the Index after updates and deletes, I still need to set up the Index first in Sinatra, which has no knowledge of my Rails app.  What should the "source" be?  Or is there some way of telling the Sinatra server to set up an index, search, and route remotely?

There are examples of some of this on the web, but they're all wildly different and mostly seem to be out of date.

Florian R. Hanke

unread,
Aug 12, 2012, 1:11:02 AM8/12/12
to picky...@googlegroups.com
On Sunday, 12. August 2012 at 13:16, rfichoke wrote:
Bundler could not find compatible versions for gem "activesupport":
  In Gemfile:
    picky-client (= 4.6.2) ruby depends on
      activesupport (~> 3) ruby

    rails (>= 0) ruby depends on
      activesupport (4.0.0.beta)
It seems as if the "spermy operator" wasn't consistent. Thanks for the info. I updated the latest version (4.6.3) to use ">= 3.0". 
By the way, I've got "extend Picky::Client::ActiveRecord.new(...)" in my Rails model, but I'm confused as to how to set up the Sinatra server.  Even though I have the Rails model set up to update the Index after updates and deletes, I still need to set up the Index first in Sinatra, which has no knowledge of my Rails app.
I'm not perfectly sure what your setup is. You have a Rails app, and a separate Picky/Sinatra server? 
What should the "source" be?
You don't have to give it a source, you can exclusively fill it via external interface (the IndexActions).
Or is there some way of telling the Sinatra server to set up an index, search, and route remotely?
Sadly, not yet, and I am not sure I want to go there. Stuffing search etc. all into models seems too unfocused to me.
There are examples of some of this on the web, but they're all wildly different and mostly seem to be out of date.
Which example are you using?

rfichoke

unread,
Aug 13, 2012, 3:45:49 PM8/13/12
to picky...@googlegroups.com
On Sunday, August 12, 2012 1:11:02 AM UTC-4, Picky / Florian Hanke wrote:

It seems as if the "spermy operator" wasn't consistent. Thanks for the info. I updated the latest version (4.6.3) to use ">= 3.0".

Works great.  Thanks!
By the way, I've got "extend Picky::Client::ActiveRecord.new(...)" in my Rails model, but I'm confused as to how to set up the Sinatra server.  Even though I have the Rails model set up to update the Index after updates and deletes, I still need to set up the Index first in Sinatra, which has no knowledge of my Rails app.
I'm not perfectly sure what your setup is. You have a Rails app, and a separate Picky/Sinatra server?

Yes.  Here's what I've got so far.  I have a Sinatra server running Picky:

class SearchEngine < Sinatra::Application
  sessions_index = Picky::Index.new(:sessions) do
  end

  sessions = Picky::Search.new(sessions_index)

  get '/sessions' do
    results = sessions.search(params[:query], params[:ids] || 20, params[:offset] || 0)
    AppLogger.info results
    results.to_json
  end
end

I didn't use a source here, so I'm not sure how to populate the Index initially when I run the Sinatra application.  I suppose I can connect to the SQL database and add all of the rows to the Index when I start the Picky server.  But then I'll lose the ability to use transient attributes from my Rails models and it will make it somewhat difficult to make changes to things like joined columns in the future.

I also can't add any categories, or the server fails to start because the index is missing:

~/.rvm/gems/ruby-1.9.3-p194/gems/picky-4.6.3/lib/picky/backends/memory/json.rb:20:in `initialize': No such file or directory - ~/session_search_server/index/development/sessions/counter_party_exact_inverted.memory.json (Errno::ENOENT)

I get the same thing when I try to run rake index.

On the Rails side, I can initialize a Picky client:

SearchServer = Picky::Client.new(
  :host => 'localhost',
  :port => 8080,
  :path => '/sessions'
)

Then in my Rails model, I can use the Client to search.  But it's just the initial Index population (and setting up categories to draw from my model) that I'm having trouble doing.

Florian Hanke

unread,
Aug 14, 2012, 12:26:14 AM8/14/12
to picky...@googlegroups.com
On 13/08/2012, at 22:45, rfichoke <rfic...@gmail.com> wrote:

On Sunday, August 12, 2012 1:11:02 AM UTC-4, Picky / Florian Hanke wrote:

It seems as if the "spermy operator" wasn't consistent. Thanks for the info. I updated the latest version (4.6.3) to use ">= 3.0".

Works great.  Thanks!

My pleasure. Thanks for the testing!

By the way, I've got "extend Picky::Client::ActiveRecord.new(...)" in my Rails model, but I'm confused as to how to set up the Sinatra server.  Even though I have the Rails model set up to update the Index after updates and deletes, I still need to set up the Index first in Sinatra, which has no knowledge of my Rails app.
I'm not perfectly sure what your setup is. You have a Rails app, and a separate Picky/Sinatra server?

Yes.  Here's what I've got so far.  I have a Sinatra server running Picky:

class SearchEngine < Sinatra::Application
  sessions_index = Picky::Index.new(:sessions) do
  end

  sessions = Picky::Search.new(sessions_index)

  get '/sessions' do
    results = sessions.search(params[:query], params[:ids] || 20, params[:offset] || 0)
    AppLogger.info results
    results.to_json
  end
end

I didn't use a source here, so I'm not sure how to populate the Index initially when I run the Sinatra application.  I suppose I can connect to the SQL database and add all of the rows to the Index when I start the Picky server.  But then I'll lose the ability to use transient attributes from my Rails models and it will make it somewhat difficult to make changes to things like joined columns in the future.

2 points:
- It's probably sorely underdocumented, but: Picky currently runs in 2 different modes, static and dynamic. If you go static, give it a source, and use rake index, or index.reindex etc, ie. not dynamically adding items. You probably want to use the dynamic index, where you add items from the rails app, but also want to preserve the index as described in the 2 links I sent you, using index.dump on exit, and index.reload on restart. However:
- the second point, which is a problem in every separate-from-rails-but-uses-the-model thing: Shared models. This is the main reason most "things" stuff everything into the poor overloaded Rails models. I could do this too, but...
The thing is, stuffing the search definitions into the Rails models is not a good fit.

So here's what I recommend: Keep the data and the index definition separate. How?
Have a Rails model with the Picky "remote client link" (sorry, I need to find a name for this), defining what attributes to index. This includes aggregated data etc. (It's basically method names Picky uses to put together a hash: { attribute: "data", aggregated_method: "aggregated data", etc. }
then, Picky sends that data back to the server. In the index you define categories that match up to the keys in the hash, so attribute, and aggregated_method. Then, you define how you'd like the data that comes from the hash indexed, as usual using category :attribute, ...

I also can't add any categories, or the server fails to start because the index is missing:

~/.rvm/gems/ruby-1.9.3-p194/gems/picky-4.6.3/lib/picky/backends/memory/json.rb:20:in `initialize': No such file or directory - ~/session_search_server/index/development/sessions/counter_party_exact_inverted.memory.json (Errno::ENOENT)

I get the same thing when I try to run rake index.

On the Rails side, I can initialize a Picky client:

SearchServer = Picky::Client.new(
  :host => 'localhost',
  :port => 8080,
  :path => '/sessions'
)

Then in my Rails model, I can use the Client to search.  But it's just the initial Index population (and setting up categories to draw from my model) that I'm having trouble doing.

I hope the above helps. It seems to me I should write up a nice recipe for Rails on how to do this.

When in doubt, read the source code - Picky is very small, especially the code you're using :)

Cheers,
   Florian
Reply all
Reply to author
Forward
0 new messages