Searching with Picky: In the Terminal

ruby / picky / gems

This is a post in the Picky series on its workings. If you haven’t tried it yet, do so in the Getting Started section. It’s quick and painless :)

This post is about a fun little experimental toy I’ve been working on: picky search <url>.


rake search is picky search from 2.2.0 on.

picky search <url>?

Yes. While working on a server, I sometimes want to see if the search engine works correctly directly in the terminal (normally I use tests, but sometimes I need that quick look).

How do I use it?

See this short video (it’s best to full-screen it):

  1. Start a Picky server.
  2. Then type picky search /some/url (where /some/url is a path – or url if not on this server – you’ve defined using route in app/application.rb).
  3. Then, just type away.

The result id count will update as you type.

When pressing enter, the top 20 result ids will appear next to your search text.

If you want to exit, just Ctrl-C. That’s it.

Note that you need the picky-client & highline gem installed. But Picky will tell you so if you haven’t.

How does it work?

I use the highline gem (by @JEG2) to get single characters (using the appropriately named get_character) from the user and then move the cursor around using \e[#{amount}D (left) and \e[#{amount}C (right), print ing to the STDOUT and flush ing it a lot.

If there is a gem which makes it easy to position objects in the terminal which update it (by being used in a visitor pattern or however), I’d like to hear about it!


So we’ve seen

  1. how you run a search directly in the terminal.

Hope you learnt something new!

Next Picky Data Sources: Next Steps