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 # => 
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.
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_namecd app_name bundle install
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 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
unicorn -p 3000
Go to http://localhost:3000/ and try the examples.
You're probably itching to change the example for your own data. How do you do this?
In the server directory, just type
and it will tell you where to change the server configuration.
Go to http://localhost:3000/configure and the page will show you how to configure your app server.
That's it, congratulations! :)
I recommend chruby for installing and managing Ruby versions.
The big picture:
That's the basic setup. The things to remember are:
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).
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.
There's a Wiki as well: Picky Wiki
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.