Fork me on GitHub

Picky

Getting Started

Need a search engine in a Ruby script and got 3 minutes?

gem install picky

and copy paste

#!/usr/bin/env ruby

require 'picky'

# Create an index which is saved into './index' when you
# run index.dump(). Note that :id is implied - every input
# object must supply an :id!
#
index = Picky::Index.new :people do
  category :age
  category :name
end

# Define a data input class. Any object that responds to
# :id, :age, :name can be added to the index.
#
Person = Struct.new :id, :age, :name

# Add some data objects to the index.
# IDs can be any unique string or integer.
#
index.add Person.new(1, 34, 'Florian is the author of picky')
index.add Person.new(2, 77, 'Floris is related to Florian')

# Create a search interface object.
#
people = Picky::Search.new index

# Do a search and remember the results.
#
results = people.search 'floris'

# Show the results.
#
p results.ids # => [2]

Have fun changing the code to suit your needs :)

Need a search engine in a Sinatra server & web frontend and got 10 minutes?

gem install picky-generators

This will also install the needed gems "picky" and "picky-client".

Other system requirements if it doesn't run straightaway.

Create a web server

The server generates a library example, which you can run right away.

# Generates a directory "app_name"
# with a new Picky default server project.
# Type "picky generate" to see other options.

picky generate server app_name
cd app_name
bundle install

1. Index the data

rake index

2. Start the server

rake start

3. Try a query

curl localhost:8080/books?query=test

Don't worry about the strange looking results! The next part (client) will take care of them.

If you're interested anyway: Results (Format & Structure)

The client

The client generates an example app for the "library" example backend, using Sinatra.

# Generates a directory "app_name"
# with a new Picky client Sinatra project.

picky generate client app_name
cd app_name
bundle install

1. Start the app server

unicorn -p 3000

2. Admire your work

Go to http://localhost:3000/ and try the examples.

Your own search

You're probably itching to change the example for your own data. How do you do this?

The server

In the server directory, just type

rake todo

and it will tell you where to change the server configuration.

The client

Go to http://localhost:3000/configure and the page will show you how to configure your app server.

That's it, congratulations! :)

System Requirements

I recommend chruby for installing and managing Ruby versions.

How does it all work together?

The big picture:

That's the basic setup. The things to remember are:

  1. The Picky server calculates IDs for a query.
  2. Your app server renders results for the resulting IDs.
  3. The Picky JS frontend offers help to the user.

Together they are like a small A-Team, something like "Action Search Squad Alpha"! «We've got the results and are heading back to base now, Sir!» Bam!

Note that you don't need a Picky client. You could just as well use the results in your Python/Java/PHP app server (If you happen to write a client for one of these, please let me know).

Need assistance?

Right here. I'm happy to help! If something doesn't work, send/gist me your app/application.rb and I'll look into it.

github (floere), twitter (hanke), mail (gmail)

There's a Wiki as well: Picky Wiki

Accompanying Video

If you don't have the time or leisure to do it yourself, watch this:

Note that the video was made with version 1.0.0.

In the latest version, instead of

picky project <server dir>
picky-client sinatra <client dir>

the following commands are now used:

picky generate unicorn_server <server dir>
picky generate sinatra_client <client dir>

A bit more wordy, but hopefully clearer what it does.

Logos and all images are CC Attribution licensed to Florian Hanke.