all-in-one with rails/rack?

Showing 1-4 of 4 messages
all-in-one with rails/rack? David Lowenfels 6/21/12 4:13 PM
I do think picky will be nicer for my search needs than postgres full-text , as I want to build a custom index and be able to change sort order on the fly in various ways.

I am using heroku with a new rails project, and it would be nice not to have to mess with a separate server.

I see that you can make an all-in-one for a sinatra app, is this possible with Rails, i.e. mount a rack app in the routes or use metal?

Thanks,
-D
Re: all-in-one with rails/rack? Picky / Florian Hanke 6/21/12 6:26 PM
Hi David,

I'd not even mount a rack app (except if you want to).

Picky is pretty much just POROs, so I'd look at the index or the search very much like model objects. Sinatra is just the thing connecting these to the outside HTTP world.

So the way I'd suggest:
- Put the index in a separate file, and require it (and its definition) on startup, perhaps in an initializer? Save the index in a constant, e.g. BooksIndex or similar. https://github.com/floere/picky/blob/master/generators/prototypes/all_in_one/sinatra/app.rb#L45-57
- Similarly with the search: https://github.com/floere/picky/blob/master/generators/prototypes/all_in_one/sinatra/app.rb#L67-75, also use a constant, e.g. BooksSearch.
- Then, in specific actions (perhaps in a separate controller, called SearchController?), call search and prepare results etc.: https://github.com/floere/picky/blob/master/generators/prototypes/all_in_one/sinatra/app.rb#L99-124
(This depends on how and where you want to search – maybe you call it from the standard Picky interface, maybe you call it from inside another Rails action)

Sorry there isn't a 1-2-3 setup, but I found that such a thing will often move people in the wrong direction, and it takes more time to recognize that and clean it up than to design and think about it before.

One thing: You'd like to change sort order on the fly. Now, in Picky I made the conscious design decision to not include a sorter in the process (time consuming, therefore faster – also, in most cases, developers only need a single sort order). That means the order in which the items are in the index will be the order they are returned as results. That means the order of items per index are fixed. You'd have to have multiple indexes, each with a different sort order, and call them depending on which sort order you want. This is very fast, of course, but the price to pay is space. If you still decide to go ahead with it, don't hesitate to ask the list for help regarding how to do the choosing of the right sort order, ie. index. I suggest just trying it :) Also, remember that you can create the indexes in a nice [:order1, :order2, :order3].each do ... end interation, and don't have to copy paste.
On a positive note: Picky certainly is crazily customizable :)

All the best, hope it serves you well!
   Florian
Re: all-in-one with rails/rack? Picky / Florian Hanke 6/21/12 6:27 PM
P.S: If you need help with setting up Picky/Rails, don't hesitate to ask either. The one thing to remember: Picky runs inside a single script, wholly without Sinatra, Rails, DRb etc. – but then that means you can put it inside any container you want, which I like.
Re: all-in-one with rails/rack? Picky / Florian Hanke 6/30/12 9:36 PM
Hi David,

Just wanted to follow up: Did you succeed, or did you end up not using it?

Cheers,
   Florian