picky-generators 2.7.0 → 3.0.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. data/lib/picky-generators/generators/selector.rb +11 -5
  2. data/lib/picky-generators/generators/server/sinatra.rb +41 -0
  3. data/lib/picky-generators.rb +1 -0
  4. data/prototypes/server/empty_unicorn/app/application.rb +1 -1
  5. data/prototypes/server/shared_unicorn/Gemfile +2 -2
  6. data/prototypes/server/shared_unicorn/Rakefile +1 -1
  7. data/prototypes/server/shared_unicorn/app/logging.rb +3 -3
  8. data/prototypes/server/shared_unicorn/config.ru +2 -2
  9. data/prototypes/server/shared_unicorn/{unicorn.ru → unicorn.rb} +1 -1
  10. data/prototypes/server/sinatra/Gemfile +28 -0
  11. data/prototypes/server/sinatra/Rakefile +6 -0
  12. data/prototypes/server/sinatra/app.rb +48 -0
  13. data/prototypes/server/sinatra/config.ru +14 -0
  14. data/prototypes/server/sinatra/data/development/library.csv +540 -0
  15. data/prototypes/server/sinatra/data/production/library.csv +540 -0
  16. data/prototypes/server/sinatra/data/test/library.csv +540 -0
  17. data/prototypes/server/sinatra/log/README +0 -0
  18. data/prototypes/server/sinatra/log/unicorn.stderr.log +98 -0
  19. data/prototypes/server/sinatra/log/unicorn.stdout.log +62 -0
  20. data/prototypes/server/sinatra/spec/integration_spec.rb +28 -0
  21. data/prototypes/server/sinatra/spec/spec_helper.rb +5 -0
  22. data/prototypes/server/sinatra/tmp/pids/README +1 -0
  23. data/prototypes/server/sinatra/unicorn.rb +17 -0
  24. data/prototypes/server/unicorn/Rakefile +1 -1
  25. data/prototypes/server/unicorn/app/application.rb +7 -2
  26. data/prototypes/server/unicorn/spec/integration_spec.rb +2 -2
  27. data/prototypes/server/unicorn/spec/spec_helper.rb +2 -2
  28. data/spec/lib/picky-generators/generators/selector_spec.rb +3 -1
  29. data/spec/lib/picky-generators/generators/server/sinatra_spec.rb +35 -0
  30. metadata +25 -8
@@ -1,18 +1,24 @@
1
1
  module Picky
2
-
2
+
3
3
  module Generators
4
4
 
5
5
  # Selects the right generator.
6
6
  #
7
7
  class Selector
8
-
8
+
9
9
  attr_reader :types
10
10
 
11
+ # TODO All-in-one-server.
12
+ #
11
13
  def initialize
12
14
  @types = {
13
15
  :sinatra_client => [Client::Sinatra, :sinatra_client_name],
16
+ :client => [Client::Sinatra, :client_name],
17
+
14
18
  :unicorn_server => [Server::Unicorn, :unicorn_server_name],
15
- :empty_unicorn_server => [Server::EmptyUnicorn, :empty_unicorn_server_name]
19
+ :empty_unicorn_server => [Server::EmptyUnicorn, :empty_unicorn_server_name],
20
+ :sinatra_server => [Server::Sinatra, :sinatra_server_name],
21
+ :server => [Server::Sinatra, :server_name]
16
22
  }
17
23
  end
18
24
 
@@ -41,7 +47,7 @@ module Picky
41
47
  klass.new *args
42
48
  end
43
49
  end
44
-
50
+
45
51
  end
46
-
52
+
47
53
  end
@@ -0,0 +1,41 @@
1
+ module Picky
2
+
3
+ module Generators
4
+
5
+ module Server
6
+
7
+ # Generates a new Picky Sinatra/Unicorn Server Example.
8
+ #
9
+ # Example:
10
+ # > picky-generate sinatra_server my_lovely_unicorn
11
+ #
12
+ class Sinatra < Picky::Generators::Base
13
+
14
+ def initialize identifier, name, *args
15
+ super identifier, name, 'server/sinatra', *args
16
+ end
17
+
18
+ #
19
+ #
20
+ def generate
21
+ exclaim "Setting up Picky Sinatra Server \"#{name}\"."
22
+ create_target_directory
23
+ copy_all_files expand_prototype_path('server/sinatra')
24
+ exclaim "\"#{name}\" is a great project name! Have fun :)\n"
25
+ exclaim ""
26
+ exclaim "Next steps:"
27
+ exclaim "1. cd #{name}"
28
+ exclaim "2. bundle install"
29
+ exclaim "3. rake index"
30
+ exclaim "4. unicorn -c unicorn.rb"
31
+ exclaim "5. rake todo # (optional) shows you where Picky needs input from you"
32
+ exclaim " # if you want to define your own search."
33
+ end
34
+
35
+ end
36
+
37
+ end
38
+
39
+ end
40
+
41
+ end
@@ -4,5 +4,6 @@ require File.expand_path '../picky-generators/generators/base', __FILE__
4
4
  require File.expand_path '../picky-generators/generators/client/sinatra', __FILE__
5
5
  require File.expand_path '../picky-generators/generators/server/unicorn', __FILE__
6
6
  require File.expand_path '../picky-generators/generators/server/empty_unicorn', __FILE__
7
+ require File.expand_path '../picky-generators/generators/server/sinatra', __FILE__
7
8
 
8
9
  require File.expand_path '../picky-generators/generators/selector', __FILE__
@@ -3,7 +3,7 @@
3
3
  # Check the Wiki http://github.com/floere/picky/wiki for more options.
4
4
  # Ask me or the google group if you have questions or specific requests.
5
5
  #
6
- class PickySearch < Application
6
+ class PickySearch < Picky::Application
7
7
 
8
8
  # TODO Your search configuration here.
9
9
 
@@ -2,7 +2,7 @@ source :gemcutter
2
2
 
3
3
  # Gems required by Picky.
4
4
  #
5
- gem 'picky', '~> 2.0'
5
+ gem 'picky', '3.0.0.pre1'
6
6
  gem 'rake'
7
7
  gem 'bundler'
8
8
  gem 'rack', '~> 1.2.2'
@@ -30,6 +30,6 @@ gem 'mysql'
30
30
  # Integration testing needs the client.
31
31
  #
32
32
  group :test do
33
+ gem 'picky-client', '3.0.0.pre1'
33
34
  gem 'rspec'
34
- gem 'picky-client'
35
35
  end
@@ -1 +1 @@
1
- require 'picky-tasks'
1
+ require 'picky/tasks'
@@ -1,7 +1,7 @@
1
1
  # Standard logging.
2
2
  #
3
3
  require 'logger'
4
- PickyLog = Loggers::Search.new ::Logger.new(File.expand_path('log/search.log', PICKY_ROOT))
4
+ PickyLog = Picky::Loggers::Search.new ::Logger.new(File.expand_path('log/search.log', PICKY_ROOT))
5
5
 
6
6
  # Example with using the syslog logger.
7
7
  # Falling back to the standard log if it isn't available.
@@ -11,10 +11,10 @@ PickyLog = Loggers::Search.new ::Logger.new(File.expand_path('log/search.log', P
11
11
  # begin
12
12
  # log_program_name = 'search/query'
13
13
  # logger = SyslogLogger.new log_program_name
14
- # PickyLog = Loggers::Search.new logger
14
+ # PickyLog = Picky::Loggers::Search.new logger
15
15
  # puts "Logging on syslog #{log_program_name}."
16
16
  # rescue StandardError
17
17
  # puts "Could not connect to the syslog, using the normal log."
18
18
  # require 'logger'
19
- # PickyLog = Loggers::Search.new ::Logger.new(File.join(PICKY_ROOT, 'log/search.log'))
19
+ # PickyLog = Picky::Loggers::Search.new ::Logger.new(File.join(PICKY_ROOT, 'log/search.log'))
20
20
  # end
@@ -14,11 +14,11 @@ require 'picky'
14
14
  #
15
15
  # (in that order).
16
16
  #
17
- Loader.load_application
17
+ Picky::Loader.load_application
18
18
 
19
19
  # Load the indexes into the memory.
20
20
  #
21
- Indexes.load_from_cache
21
+ Picky::Indexes.reload
22
22
 
23
23
  # TODO Decide if you want to use the Unicorn killing trick. (Good with large data sets)
24
24
  #
@@ -4,7 +4,7 @@ preload_app true
4
4
  stderr_path 'log/unicorn.stderr.log'
5
5
  stdout_path 'log/unicorn.stdout.log'
6
6
  timeout 10
7
- worker_processes 2
7
+ worker_processes 3
8
8
 
9
9
  # TODO Decide if you want to use the Unicorn killing trick. (Good with large data sets)
10
10
  #
@@ -0,0 +1,28 @@
1
+ source :gemcutter
2
+
3
+ # Gems required by Picky.
4
+ #
5
+ gem 'picky', '3.0.0.pre1'
6
+ gem 'bundler'
7
+ gem 'rake'
8
+ gem 'rack'
9
+ gem 'rack_fast_escape', '2009.06.24' # Optional.
10
+ gem 'text'
11
+ gem 'yajl-ruby', :require => 'yajl'
12
+
13
+ # Should be optional, but isn't yet.
14
+ #
15
+ gem 'activesupport', '~> 3.0', :require => 'active_support/core_ext'
16
+ gem 'activerecord', '~> 3.0', :require => 'active_record'
17
+
18
+ # Required by your project.
19
+ #
20
+ gem 'sinatra'
21
+ gem 'unicorn'
22
+ gem 'mysql' # Project specific.
23
+ gem 'redis' # Project specific.
24
+
25
+ group :test do
26
+ gem 'picky-client', '3.0.0.pre1'
27
+ gem 'rspec'
28
+ end
@@ -0,0 +1,6 @@
1
+ require 'picky/tasks'
2
+
3
+ require 'rspec'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new :spec
@@ -0,0 +1,48 @@
1
+ require 'sinatra/base'
2
+ require 'picky'
3
+
4
+ class BookSearch < Sinatra::Application
5
+
6
+ # We do this so we don't have to type
7
+ # Picky:: in front of everything.
8
+ #
9
+ include Picky
10
+
11
+ # Define an index.
12
+ #
13
+ books_index = Indexes::Memory.new :books do
14
+ source Sources::CSV.new(:title, :author, :year, file: "data/#{PICKY_ENVIRONMENT}/library.csv")
15
+ indexing removes_characters: /[^a-zA-Z0-9\s\/\-\_\:\"\&\.]/i,
16
+ stopwords: /\b(and|the|of|it|in|for)\b/i,
17
+ splits_text_on: /[\s\/\-\_\:\"\&\/]/
18
+ category :title,
19
+ similarity: Similarity::DoubleMetaphone.new(3),
20
+ partial: Partial::Substring.new(from: 1) # Default is from: -3.
21
+ category :author, partial: Partial::Substring.new(from: 1)
22
+ category :year, partial: Partial::None.new
23
+ end
24
+
25
+ # Index and load on USR1 signal.
26
+ #
27
+ Signal.trap('USR1') do
28
+ books_index.reindex # kill -USR1 <pid>
29
+ end
30
+
31
+ # Define a search over the books index.
32
+ #
33
+ search = Search.new(books_index) do
34
+ searching removes_characters: /[^a-zA-Z0-9\s\/\-\_\&\.\"\~\*\:\,]/i, # Picky needs control chars *"~:, to pass through.
35
+ stopwords: /\b(and|the|of|it|in|for)\b/i,
36
+ splits_text_on: /[\s\/\-\&]+/,
37
+ substitutes_characters_with: CharacterSubstituters::WestEuropean.new # Normalizes special user input, Ä -> Ae, ñ -> n etc.
38
+ boost [:title, :author] => +3, [:title] => +1
39
+ end
40
+
41
+ # Route /books to the books search.
42
+ #
43
+ get '/books' do
44
+ results = search.search_with_text params[:query], params[:ids] || 20, params[:offset] || 0
45
+ results.to_json
46
+ end
47
+
48
+ end
@@ -0,0 +1,14 @@
1
+ require File.expand_path '../app', __FILE__
2
+
3
+ # Load all indexes.
4
+ #
5
+ Picky::Indexes.reload
6
+
7
+ # Use Harakiri middleware to kill unicorn child after X requests.
8
+ #
9
+ # See http://vimeo.com/12614970 for more info.
10
+ #
11
+ # Rack::Harakiri.after = 1000
12
+ # use Rack::Harakiri
13
+
14
+ run BookSearch.new