picky 0.0.8 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/bin/picky CHANGED
@@ -5,7 +5,7 @@ begin
5
5
  require 'picky/generator'
6
6
  rescue LoadError => e
7
7
  require 'rubygems'
8
- picky_path = File.expand_path('../../lib', __FILE__)
8
+ picky_path = File.expand_path '../../lib', __FILE__
9
9
  $:.unshift(picky_path) if File.directory?(picky_path) && !$:.include?(picky_path)
10
10
  require 'picky/generator'
11
11
  end
data/lib/deployment.rb CHANGED
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), 'constants'))
1
+ require File.expand_path '../constants', __FILE__
2
2
 
3
3
  module Picky
4
4
  module Capistrano
@@ -49,7 +49,7 @@ module Picky
49
49
 
50
50
  def initialize name, *args
51
51
  @name = name
52
- @prototype_project_basedir = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'prototype_project'))
52
+ @prototype_project_basedir = File.expand_path '../../../prototype_project', __FILE__
53
53
  end
54
54
 
55
55
  #
@@ -134,7 +134,7 @@ module Picky
134
134
  #
135
135
  #
136
136
  def target_directory
137
- File.expand_path File.join(Dir.pwd, name)
137
+ File.expand_path name, Dir.pwd
138
138
  end
139
139
 
140
140
  def created entry
@@ -2,44 +2,18 @@
2
2
  #
3
3
  module Helpers
4
4
  module Measuring
5
-
6
- def log_performance(name, performed_on = '', &block)
7
- time_begin = Time.now.to_f
8
-
9
- lambda(&block).call
10
-
11
- duration = Time.now.to_f - time_begin
12
-
13
- # PerformanceLog.info("#{'%30s' % name}: #{'%2.10f' % duration} #{performed_on}")
14
- duration
15
- end
16
-
5
+
17
6
  # Returns a duration in seconds.
18
7
  #
19
8
  def timed(*args, &block)
20
9
  block_to_be_measured = lambda(&block)
21
-
10
+
22
11
  time_begin = Time.now.to_f
23
-
12
+
24
13
  block_to_be_measured.call(*args)
25
-
14
+
26
15
  Time.now.to_f - time_begin
27
16
  end
28
-
29
- def profiled_html(mode = :cpu_time, &block)
30
- require 'ruby-prof'
31
-
32
- RubyProf.measure_mode = "RubyProf::#{mode.to_s.upcase}".constantize
33
-
34
- result = RubyProf.profile &block
35
-
36
- printer = RubyProf::GraphHtmlPrinter.new(result)
37
- File.open('log/profiler.html', 'w') do |f|
38
- printer.print(f)
39
- end
40
-
41
- system 'open log/profiler.html'
42
- end
43
-
17
+
44
18
  end
45
19
  end
@@ -1,6 +1 @@
1
- # TODO Remove as soon as gem compiling is ok.
2
- #
3
- # Dir.chdir File.join(File.dirname(__FILE__), '../ext/ruby19') do
4
- # %x{ ruby extconf.rb && make }
5
- # end
6
- require File.expand_path(File.join(File.dirname(__FILE__), '../ext/ruby19/performant'))
1
+ require File.expand_path '../../ext/ruby19/performant', __FILE__
data/lib/picky/loader.rb CHANGED
@@ -100,7 +100,6 @@ module Loader
100
100
  load_relative 'helpers/gc'
101
101
  load_relative 'helpers/cache'
102
102
  load_relative 'helpers/measuring'
103
- load_relative 'helpers/search'
104
103
 
105
104
  # Signal handling
106
105
  #
@@ -19,6 +19,7 @@ module Query
19
19
  # Expand the combinations.
20
20
  #
21
21
  possible_combinations = tokens.possible_combinations_in index
22
+
22
23
  # Optimization for ignoring tokens that allocate to nothing and
23
24
  # can be ignored.
24
25
  # For example in a context search, where "florian" is not
@@ -26,39 +27,39 @@ module Query
26
27
  #
27
28
  possible_combinations.compact!
28
29
  expanded_combinations = expand_combinations_from possible_combinations
29
-
30
+
30
31
  # TODO Rewrite.
31
32
  #
32
33
  # expanded_combinations.map! { |expanded_combination| Combinations.new(index, expanded_combination) }
33
-
34
- if expanded_combinations.empty?
35
- previous_allocations
36
- else
37
- # The recombination part, where
38
- # [
39
- # [a,a,b,b,c,c]
40
- # [d,e,d,e,d,e]
41
- # ]
42
- # becomes
43
- # [
44
- # [a,d],
45
- # [a,e],
46
- # [b,d],
47
- # [b,e],
48
- # [c,d],
49
- # [c,e]
50
- # ]
51
- #
52
- expanded_combinations = expanded_combinations.shift.zip(*expanded_combinations)
53
-
54
- # Wrap into a real combination.
55
- #
56
- expanded_combinations.map! { |expanded_combination| Combinations.new(index, expanded_combination) }
57
-
58
- # Add the possible allocations to the ones we already have.
59
- #
60
- previous_allocations + expanded_combinations.map(&:pack_into_allocation)
61
- end
34
+
35
+ #
36
+ #
37
+ next previous_allocations if expanded_combinations.empty?
38
+
39
+ # The recombination part, where
40
+ # [
41
+ # [a,a,b,b,c,c]
42
+ # [d,e,d,e,d,e]
43
+ # ]
44
+ # becomes
45
+ # [
46
+ # [a,d],
47
+ # [a,e],
48
+ # [b,d],
49
+ # [b,e],
50
+ # [c,d],
51
+ # [c,e]
52
+ # ]
53
+ #
54
+ expanded_combinations = expanded_combinations.shift.zip(*expanded_combinations)
55
+
56
+ # Wrap into a real combination.
57
+ #
58
+ expanded_combinations.map! { |expanded_combination| Combinations.new(index, expanded_combination) }
59
+
60
+ # Add the possible allocations to the ones we already have.
61
+ #
62
+ previous_allocations + expanded_combinations.map(&:pack_into_allocation)
62
63
  end)
63
64
  end
64
65
 
@@ -123,11 +123,7 @@ module Sources
123
123
  def harvest_statement_with_offset type, field, offset
124
124
  statement = harvest_statement type, field
125
125
 
126
- if statement.include? 'WHERE'
127
- statement += ' AND'
128
- else
129
- statement += ' WHERE'
130
- end
126
+ statement += statement.include?('WHERE') ? ' AND' : ' WHERE'
131
127
 
132
128
  "#{statement} st.id > #{offset} LIMIT #{chunksize}"
133
129
  end
data/lib/picky-tasks.rb CHANGED
@@ -1,4 +1,4 @@
1
- all_rake_files = File.expand_path File.join(File.dirname(__FILE__), 'tasks', '*.rake')
1
+ all_rake_files = File.expand_path '../tasks/*.rake', __FILE__
2
2
 
3
3
  Dir[all_rake_files].each do |rakefile|
4
4
  next if rakefile =~ /spec\.rake$/
data/lib/picky.rb CHANGED
@@ -1,16 +1,14 @@
1
1
  # Require the constants.
2
2
  #
3
- # TODO Move to app?
4
- #
5
- require File.expand_path(File.join(File.dirname(__FILE__), 'constants'))
3
+ require File.expand_path '../constants', __FILE__
6
4
 
7
5
  # Library bundling.
8
6
  #
9
- require File.expand_path(File.join(File.dirname(__FILE__), 'bundling'))
7
+ require File.expand_path '../bundling', __FILE__
10
8
 
11
9
  # Loader which handles framework and app loading.
12
10
  #
13
- require File.expand_path(File.join(File.dirname(__FILE__), 'picky', 'loader'))
11
+ require File.expand_path '../picky/loader', __FILE__
14
12
 
15
13
  # Load the framework
16
14
  #
@@ -1,4 +1,4 @@
1
1
  desc "Loads the framework."
2
2
  task :framework do
3
- require File.expand_path(File.join(File.dirname(__FILE__), '..', 'picky'))
3
+ require File.expand_path '../../picky', __FILE__
4
4
  end
@@ -34,10 +34,13 @@ class PickySearch < Application # The App Constant needs to be identical in appl
34
34
  stopwords(/\b(and|the|of|it|in|for)\b/)
35
35
  split_text_on(/[\s\/\-\,\&]+/)
36
36
 
37
+ # The example defines two queries that use the same index(es).
38
+ #
39
+ # A Full query returns ids, combinations, and counts.
40
+ # A Live query does return all that Full returns, without ids.
41
+ #
37
42
  route %r{^/books/full}, Query::Full.new(Indexes[:books])
38
43
  route %r{^/books/live}, Query::Live.new(Indexes[:books])
39
-
40
- root 200
41
44
  end
42
45
 
43
46
  end
@@ -1,7 +1,7 @@
1
1
  # Standard logging.
2
2
  #
3
3
  require 'logger'
4
- PickyLog = Loggers::Search.new ::Logger.new(File.expand_path(File.join(PICKY_ROOT, 'log/search.log')))
4
+ PickyLog = 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.
@@ -16,7 +16,7 @@ require 'picky'
16
16
  #
17
17
  Loader.load_application
18
18
 
19
- # Load the data. This loads data from cache files e.g. "some_index/*_index.dump" into constant Indexes::SomeIndex.
19
+ # Load the data. This loads data from cache files e.g. "some_index/*_index.dump" into Indexes[:some_index]
20
20
  #
21
21
  Indexes.load_from_cache
22
22
 
@@ -14,13 +14,13 @@ end
14
14
  libs = " -r irb/completion"
15
15
  libs << %( -r "picky" )
16
16
 
17
- ENV['PICKY_ENV'] = case ARGV.first
18
- when "p"; "production"
19
- when "d"; "development"
20
- when "t"; "test"
21
- else
22
- ARGV.first || ENV['PICKY_ENV'] || 'development'
23
- end
17
+ mapping = {
18
+ 'p' => 'production',
19
+ 'd' => 'development',
20
+ 't' => 'test'
21
+ }
22
+ given_env = ARGV.first
23
+ ENV['PICKY_ENV'] = mapping[given_env] || given_env || ENV['PICKY_ENV'] || 'development'
24
24
 
25
25
  puts "Use \x1b[1;30mLoader.load_application\x1b[m to load app."
26
26
  puts "Use \x1b[1;30mIndexes.load_from_cache\x1b[m after that to load indexes."
@@ -56,6 +56,12 @@ describe Picky::Generator do
56
56
  end
57
57
  end
58
58
 
59
+ describe "prototype_project_basedir" do
60
+ it "should be the right basedir" do
61
+ @generator.prototype_project_basedir.should == File.expand_path('../../../prototype_project', __FILE__)
62
+ end
63
+ end
64
+
59
65
  describe "generate" do
60
66
  it "should do things in order" do
61
67
  @generator.should_receive(:create_target_directory).once.ordered
@@ -109,7 +115,7 @@ describe Picky::Generator do
109
115
  it "should return the right filename" do
110
116
  @generator.stub! :target_directory => 'some_target_directory'
111
117
 
112
- test_filename = File.expand_path File.join(@generator.prototype_project_basedir, '/some/file/name')
118
+ test_filename = File.expand_path 'some/file/name', @generator.prototype_project_basedir
113
119
 
114
120
  @generator.target_filename_for(test_filename).should == 'some_target_directory/some/file/name'
115
121
  end
@@ -126,7 +132,7 @@ describe Picky::Generator do
126
132
 
127
133
  describe "target_directory" do
128
134
  it "should return the right dir name" do
129
- @generator.target_directory.should == File.expand_path(File.join(__FILE__, '..', '..', '..', 'some_name'))
135
+ @generator.target_directory.should == File.expand_path('../../../some_name', __FILE__)
130
136
  end
131
137
  end
132
138
 
@@ -2,17 +2,11 @@ require 'spec_helper'
2
2
 
3
3
  describe Helpers::Measuring do
4
4
  include Helpers::Measuring
5
-
5
+
6
6
  describe "#timed" do
7
7
  it "should return some duration" do
8
8
  timed { 1 + 3 }.should_not be_nil
9
9
  end
10
10
  end
11
-
12
- describe "#log_performance" do
13
- it "should log" do
14
- log_performance('hello') { 10000*10000 }
15
- end
16
- end
17
-
11
+
18
12
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 8
9
- version: 0.0.8
8
+ - 9
9
+ version: 0.0.9
10
10
  platform: ruby
11
11
  authors:
12
12
  - Florian Hanke
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-10-04 00:00:00 +02:00
17
+ date: 2010-10-09 00:00:00 +02:00
18
18
  default_executable: picky
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -73,7 +73,6 @@ files:
73
73
  - lib/picky/helpers/cache.rb
74
74
  - lib/picky/helpers/gc.rb
75
75
  - lib/picky/helpers/measuring.rb
76
- - lib/picky/helpers/search.rb
77
76
  - lib/picky/index/bundle.rb
78
77
  - lib/picky/index/category.rb
79
78
  - lib/picky/index/combined.rb
@@ -88,7 +87,6 @@ files:
88
87
  - lib/picky/initializers/mysql.rb
89
88
  - lib/picky/loader.rb
90
89
  - lib/picky/loggers/search.rb
91
- - lib/picky/performant/array.rb
92
90
  - lib/picky/query/allocation.rb
93
91
  - lib/picky/query/allocations.rb
94
92
  - lib/picky/query/base.rb
@@ -162,7 +160,6 @@ files:
162
160
  - spec/lib/helpers/cache_spec.rb
163
161
  - spec/lib/helpers/gc_spec.rb
164
162
  - spec/lib/helpers/measuring_spec.rb
165
- - spec/lib/helpers/search_spec.rb
166
163
  - spec/lib/index/bundle_partial_generation_speed_spec.rb
167
164
  - spec/lib/index/bundle_spec.rb
168
165
  - spec/lib/index/category_spec.rb
@@ -170,7 +167,6 @@ files:
170
167
  - spec/lib/indexers/field_spec.rb
171
168
  - spec/lib/loader_spec.rb
172
169
  - spec/lib/loggers/search_spec.rb
173
- - spec/lib/performant/array_spec.rb
174
170
  - spec/lib/query/allocation_spec.rb
175
171
  - spec/lib/query/allocations_spec.rb
176
172
  - spec/lib/query/base_spec.rb
@@ -247,7 +243,6 @@ test_files:
247
243
  - spec/lib/helpers/cache_spec.rb
248
244
  - spec/lib/helpers/gc_spec.rb
249
245
  - spec/lib/helpers/measuring_spec.rb
250
- - spec/lib/helpers/search_spec.rb
251
246
  - spec/lib/index/bundle_partial_generation_speed_spec.rb
252
247
  - spec/lib/index/bundle_spec.rb
253
248
  - spec/lib/index/category_spec.rb
@@ -255,7 +250,6 @@ test_files:
255
250
  - spec/lib/indexers/field_spec.rb
256
251
  - spec/lib/loader_spec.rb
257
252
  - spec/lib/loggers/search_spec.rb
258
- - spec/lib/performant/array_spec.rb
259
253
  - spec/lib/query/allocation_spec.rb
260
254
  - spec/lib/query/allocations_spec.rb
261
255
  - spec/lib/query/base_spec.rb
@@ -1,27 +0,0 @@
1
- module Helpers
2
- module Search
3
-
4
- def status_class_for(results_count)
5
- case results_count
6
- when (51..100)
7
- :lots
8
- when (26..50)
9
- :many
10
- when (16..25)
11
- :several
12
- when (8..15)
13
- :some
14
- when (2..7)
15
- :few
16
- when 1
17
- :one
18
- when 0
19
- :none
20
- else
21
- :too_many
22
- end
23
- end
24
-
25
- end
26
-
27
- end
@@ -1,23 +0,0 @@
1
- module Performant
2
- # This class will be enriched with c-methods
3
- #
4
- class Array
5
-
6
- # Chooses a good algorithm for intersecting arrays.
7
- #
8
- # Note: The sort order will be changed.
9
- #
10
- def self.intersect array_of_arrays
11
- array_of_arrays.sort! { |a, b| a.size <=> b.size }
12
-
13
- if (array_of_arrays.sum(&:size) < 20_000)
14
- Performant::Array.brute_force_intersect array_of_arrays
15
- else
16
- array_of_arrays.inject([]) do |total, elements|
17
- total.empty? ? elements : elements & total
18
- end
19
- end
20
- end
21
-
22
- end
23
- end
@@ -1,50 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'Helpers::Search' do
4
- include Helpers::Search
5
-
6
- def self.it_should_return_class_for(klass, x)
7
- it "should return class #{klass} for #{x} items" do
8
- status_class_for(x).should == klass
9
- end
10
- end
11
-
12
- describe "search_status_class_for" do
13
- it_should_return_class_for :none, 0
14
- it_should_return_class_for :one, 1
15
- it_should_return_class_for :few, 2
16
- it_should_return_class_for :few, 3
17
- it_should_return_class_for :few, 4
18
- it_should_return_class_for :few, 5
19
- it_should_return_class_for :few, 6
20
- it_should_return_class_for :few, 7
21
- it_should_return_class_for :some, 8
22
- it_should_return_class_for :some, 9
23
- it_should_return_class_for :some, 10
24
- it_should_return_class_for :some, 11
25
- it_should_return_class_for :some, 12
26
- it_should_return_class_for :some, 13
27
- it_should_return_class_for :some, 14
28
- it_should_return_class_for :some, 15
29
- it_should_return_class_for :several, 16
30
- it_should_return_class_for :several, 17
31
- it_should_return_class_for :several, 18
32
- it_should_return_class_for :several, 19
33
- it_should_return_class_for :several, 20
34
- it_should_return_class_for :several, 21
35
- it_should_return_class_for :several, 22
36
- it_should_return_class_for :several, 23
37
- it_should_return_class_for :several, 24
38
- it_should_return_class_for :several, 25
39
- it_should_return_class_for :many, 26
40
- it_should_return_class_for :many, 27
41
- it_should_return_class_for :many, 28
42
- it_should_return_class_for :many, 29
43
- # etc.
44
- it_should_return_class_for :lots, 51
45
- # etc.
46
- it_should_return_class_for :too_many, 101
47
- # etc.
48
- end
49
-
50
- end
@@ -1,13 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'performant array' do
4
-
5
- # describe "brute_force_intersect" do
6
- # it "should intersect correctly" do
7
- # arys = [[3,4], [1,2,3,4], [3,4,5,8,9]]
8
- #
9
- # Performant::Array.brute_force_intersect(arys.sort_by(&:size)).should == [3,4]
10
- # end
11
- # end
12
-
13
- end