!!! %html{ :lang => 'en' } %head %link{ :href => "stylesheets/application.css", :media => "screen", :rel => "stylesheet", :type => "text/css" }/ %link{ :href => "stylesheets/picky.css", :media => "screen", :rel => "stylesheet", :type => "text/css" }/ %script{ :src => 'javascripts/jquery-1.5.0.min.js', :type => 'text/javascript' } %script{ :src => 'javascripts/history.min.js', :type => 'text/javascript' } %script{ :src => 'javascripts/history.adapter.jquery.min.js', :type => 'text/javascript' } %script{ :src => 'javascripts/picky.min.js', :type => 'text/javascript' } %body %hgroup / Replace these headers with your code %img{ :class => 'picky', :src => "images/picky.png"}/ %h1 Picky %h2 Scaffold: A great start into your %em fantastic search engine! ☛ %a{ :href => "http://florianhanke.com/picky" } Picky Homepage .content = Picky::Helper.cached_interface %section %h1 Examples: %p %a{:href => "", :onclick => "pickyClient.insert('alan');"} alan finds Alan in the title, and Alans who wrote books. The title is ranked higher due to weighing. %p %a{:href => "", :onclick => "pickyClient.insert('title:women');"} title:women finds "women*" just in titles. %p %a{:href => "", :onclick => "pickyClient.insert('pinchn~');"} pinchn~ finds the similar "pynchon". %p %a{:href => "", :onclick => "pickyClient.insert('title:lyterature~');"} title:lyterature~ finds similar titles. %p %a{:href => "", :onclick => "pickyClient.insert('sp');"} sp finds "sp*" in multiple categories. Choose the one you're looking for. %p %a{:href => "", :onclick => "pickyClient.insert('soc* p');"} soc* p means "find something that starts with soc, and another thing starting with p". %section %h1 Already made it this far? You're good! %p I think you're ready for configuring me for your own purposes. %h2 Configuring the Picky client. %p There are two places where you configure the Picky client: %ol %li %a{ :href => '#controller' } In the controller. (client to Picky server) %li %a{ :href => '#view' } In the view. (javascript client interface) %h2#controller Controller %p Open the file %strong app.rb and take a peek inside. %p First you need both a client instance for a %strong full or a %strong live search depending on what you need (Full gets results with IDs, Live without and is used for updating the counter). %p In the example, I called it %strong BookSearch \. %code %pre :preserve BookSearch = Picky::Client.new host: 'localhost', port: 8080, path: '/books' %p Both clients offer the options: %dl %dt %strong host %dd The Picky search server host. %dt %strong port %dd The Picky search server port (see unicorn.rb in the server). %dt %strong path %dd The Picky search path (see app.rb in the server). %p Then, use these Client instances in your actions. For example like this: %code %pre :preserve get '/search/full' do results = BookSearch.search params[:query], :ids => params[:ids], :offset => params[:offset] results.extend Picky::Convenience results.populate_with Book do |book| book.to_s end ActiveSupport::JSON.encode results end %p This part gets a %strong hash with the results: %code %pre :preserve results = BookSearch.search params[:query], :ids => params[:ids], :offset => params[:offset] %p This part takes the %strong hash and extends it with a few useful and convenient methods: %code %pre results.extend Picky::Convenience %p One of these methods is the %strong populate_with method which takes a %strong model as parameter, and then gets the corresponding %strong model instances for each id in the result. %code %pre :preserve results.populate_with Book do |book| book.to_s end The %strong book.to_s simulates rendering a book. You can do whatever with the book instance if you just return a rendered thing that's supposed to be shown in the front end. %p If you don't want to render in the controller, you can do so in a view. In the controller just call %code %pre results.populate_with Book and then render the books in a view using: %code %pre :preserve results.entries do |book| render book # or book.to_s, or however you like to render the book. end %p At the end, encode the hash in JSON: %code %pre ActiveSupport::JSON.encode results That's it for the controller. %p All the steps in one: %code %pre :preserve BookSearch = Picky::Client.new host: 'localhost', port: 8080, path: '/books' get '/search/full' do results = BookSearch.search params[:query], ids: params[:ids], offset: params[:offset] results.extend Picky::Convenience results.populate_with Book do |book| book.to_s end ActiveSupport::JSON.encode results end %h2#view View %p The view is even easier. Just add the line %code %pre :preserve = Picky::Helper.cached_interface if you use just one language, or %code %pre :preserve = Picky::Helper.interface button: 'search', no_results: 'No results!', more: 'more' if you use multiple languages. (You'd use the options %code %pre :preserve button: t(:'search.button'), no_results: t(:'search.no_results'), more: t(:'search.more') of course, with proper i18n) The same options can be used for %strong #cached_interface but they will be cached, so you can only set them once and then reused. %p You're almost finished. Take a look at the file %strong views/search.haml where you'll find javascript at the end. It looks something like this: %code %pre :preserve :javascript pickyClient = new PickyClient({ // A full query displays the rendered results. // full: '/search/full', // etc. Just take a look at the possible javascript client options in that file. %p %strong Good luck my friend! %em *waves several stubby pink tentacles* %footer Website design by %a{ :href => 'http://twitter.com/thijs' } Thijs van der Vossen of %a{ :href => 'http://fngtps.com' } Fingertips with modifications by = succeed('.') do %a{ :href => 'http://twitter.com/hanke' } Florian Hanke :javascript $(window).load(function() { pickyClient = new PickyClient({ // A full query displays the rendered results. // full: '/search/full', // fullResults: 100, // Optional. Amount of ids to search for, default 20. // A live query just updates the count. // live: '/search/live', // liveResults: 0, // Optional. Amount of ids to search for, default 0. // showResultsLimit: 100, // Optional. Default is 10. // Wrap each li group (like author-title, or title-isbn etc.) of results // in this element. // Optional. Default is '