Picky 2.0

ruby / picky / gems

In my previous post, I talked about what bothers me in Picky’s API, and did a few 2.0 prerelease versions with the improvements.

After quite a bit of feedback, Picky 2.0 is released! :)

So, what’s in it for you and what do you need to change in your 1.x version to use the spankingly new gem?

What has changed?

Only four things. 2.0’s change list is short but sweet.

Index definitions

We’ve added a nice new possibility to define categories on an index. The blocky initializer. So where you had

index = Index::Memory.new(:name, source)
index.define_category :a
index.define_category :b
index.define_category :c

you now can write

index = Index::Memory.new(:name, source) do
  category :a
  category :b
  category :c

This helps keeping everything together a bit more tightly. Also, smoother skin by not having to type as much ;)

The old style still works, but is totally shunned by veteran Pickiers. Be the hippest Pickier in town by using the blocky initializer style. You know you want it.

Query::Full/Live → Search

The double definitions, Query::Full and Query::Live are no more. Good riddance!

Instead, you simply use Search. So instead of

class MyBeooootifulPickySearch < Application

  route %r{^/books/full} => Query::Full.new(some_index),
        %r{^/books/live} => Query::Live.new(some_index)


you use

class MyBeooootifulPickySearch < Application

  route %r{^/books} => Search.new(some_index)


It says “Route this URL to that search with these indexes and options”. Much more understandable and sexier! :)

To discern whether it is a full (with result ids) or live (without result ids) search, you pass e.g. curl an ids query parameter:

$ curl 'localhost:8080/books?query=meow&ids=15&offset=0'

Defaults are 20 ids and 0 offset.

Similarity::Phonetic → Similarity::DoubleMetaphone

We’ve renamed Similarity::Phonetic to Similarity::DoubleMetaphone. It’s still the same algorithm. See the double metaphone.

Also, we’ve added two default implementations, Similarity::Metaphone and Similarity::Soundex for your similarity pleasure :)

Since Picky is normally used by programmers, DoubleMetaphone is much clearer for what it actually does than Phonetic – it’s a bit of a mouthful, I admit.

Picky will tell you if you still use the old Phonetic definition in your app/application.rb, so you don’t need to learn this by heart.

Picky::Client::Full/Live (in a client) → Picky::Client

The Picky client in your application needs a few changes. Only a single client is needed anymore. So instead of

FullBooksSearch = Picky::Client::Full.new ...
LiveBooksSearch = Picky::Client::Live.new ...

you use

BooksSearch = Picky::Client.new ...

Then in your e.g. controller actions passing what amount of ids you need

BooksSearch.search params[:query], :ids => params[:ids], :offset => params[:offset]

or directly, using :ids => 20 or however you like it.


Leading up to 2.0, we’ve removed the hashbangs in the JS client history, added rake stats and rake analyze. See more in the repo’s top level history.textile.


So we’ve seen

  1. that Picky is two-dot-oh-soooome!
  2. what you’d need to change to be 2.0 compatible.

Hope you learnt something new :)

Btw, protip: Generate a client and server using picky generate and see how everything is defined in 2.0 and compare.

Comments and feedback, as usual, are appreciated.

Next On Searching