picky 2.0.0.pre1 → 2.0.0.pre2

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,9 +3,7 @@
3
3
 
4
4
  # Analyzes indexes (index bundles, actually).
5
5
  #
6
- # Can be output using to_s.
7
- #
8
- class Analyzer
6
+ class Analyzer # :nodoc:all
9
7
 
10
8
  attr_reader :analysis, :comments
11
9
 
@@ -21,6 +21,12 @@ module Index
21
21
  # * result_identifier: Use if you'd like a different identifier/name in the results than the name of the index.
22
22
  # * after_indexing: As of this writing only used in the db source. Executes the given after_indexing as SQL after the indexing process.
23
23
  #
24
+ # Example:
25
+ # my_index = Index::Memory.new(:my_index, some_source) do
26
+ # define_category :bla
27
+ # end
28
+ #
29
+ #
24
30
  def initialize name, source, options = {}
25
31
  check name, source
26
32
 
@@ -31,6 +37,10 @@ module Index
31
37
  # Centralized registry.
32
38
  #
33
39
  Indexes.register self
40
+
41
+ #
42
+ #
43
+ instance_eval(&Proc.new) if block_given?
34
44
  end
35
45
  #
36
46
  # Since this is an API, we fail hard quickly.
@@ -1,4 +1,4 @@
1
- module Indexed
1
+ module Indexed # :nodoc:all
2
2
 
3
3
  # Registers the indexes held at runtime, for queries.
4
4
  #
@@ -1,4 +1,4 @@
1
- module Indexing
1
+ module Indexing # :nodoc:all
2
2
 
3
3
  # Registers the indexes held at index time, for indexing.
4
4
  #
@@ -0,0 +1,2 @@
1
+ module Internals # :nodoc:all
2
+ end
data/lib/picky/loader.rb CHANGED
@@ -88,6 +88,8 @@ module Loader # :nodoc:all
88
88
  # (Not for the user)
89
89
  #
90
90
  def self.load_framework_internals
91
+ load_relative 'internals'
92
+
91
93
  # Load compiled C code.
92
94
  #
93
95
  load_internals 'ext/maybe_compile'
@@ -275,6 +277,7 @@ module Loader # :nodoc:all
275
277
  # Search.
276
278
  #
277
279
  load_relative 'search'
280
+ load_relative 'query'
278
281
  #
279
282
  # load_relative 'query/solr'
280
283
 
@@ -0,0 +1,2 @@
1
+ module Query # :nodoc:all
2
+ end
data/lib/picky/results.rb CHANGED
@@ -1,93 +1,89 @@
1
- module Internals
1
+ # This is the internal results object. Usually, to_marshal, or to_json
2
+ # is called on it to get a string for the answer.
3
+ #
4
+ class Results
2
5
 
3
- # This is the internal results object. Usually, to_marshal, or to_json
4
- # is called on it to get a string for the answer.
6
+ # Duration is set externally by the query.
5
7
  #
6
- class Results
8
+ attr_writer :duration
9
+ attr_reader :allocations, :offset, :amount
7
10
 
8
- # Duration is set externally by the query.
9
- #
10
- attr_writer :duration
11
- attr_reader :allocations, :offset, :amount
12
-
13
- # Takes instances of Query::Allocations as param.
14
- #
15
- def initialize amount = 0, offset = 0, allocations = Query::Allocations.new
16
- @offset = offset
17
- @amount = amount
18
- @allocations = allocations
19
- end
20
- # Create new results and calculate the ids.
21
- #
22
- def self.from amount, offset, allocations
23
- results = new amount, offset, allocations
24
- results.prepare!
25
- results
26
- end
27
-
28
- # Returns a hash with the allocations, offset, duration and total.
29
- #
30
- def serialize
31
- { allocations: allocations.to_result,
32
- offset: offset,
33
- duration: duration,
34
- total: total }
35
- end
36
- # The default format is json.
37
- #
38
- def to_response options = {}
39
- to_json options
40
- end
41
- # Convert to json format.
42
- #
43
- def to_json options = {}
44
- serialize.to_json options
45
- end
11
+ # Takes instances of Query::Allocations as param.
12
+ #
13
+ def initialize amount = 0, offset = 0, allocations = Internals::Query::Allocations.new
14
+ @offset = offset
15
+ @amount = amount
16
+ @allocations = allocations
17
+ end
18
+ # Create new results and calculate the ids.
19
+ #
20
+ def self.from amount, offset, allocations
21
+ results = new amount, offset, allocations
22
+ results.prepare!
23
+ results
24
+ end
46
25
 
47
- # This starts the actual processing.
48
- #
49
- # Without this, the allocations are not processed,
50
- # and no ids are calculated.
51
- #
52
- def prepare!
53
- allocations.process! amount, offset
54
- end
26
+ # Returns a hash with the allocations, offset, duration and total.
27
+ #
28
+ def serialize
29
+ { allocations: allocations.to_result,
30
+ offset: offset,
31
+ duration: duration,
32
+ total: total }
33
+ end
34
+ # The default format is json.
35
+ #
36
+ def to_response options = {}
37
+ to_json options
38
+ end
39
+ # Convert to json format.
40
+ #
41
+ def to_json options = {}
42
+ serialize.to_json options
43
+ end
55
44
 
56
- # Duration default is 0.
57
- #
58
- def duration
59
- @duration || 0
60
- end
61
- # The total results. Delegates to the allocations.
62
- #
63
- # Caches.
64
- #
65
- def total
66
- @total || @total = allocations.total || 0
67
- end
45
+ # This starts the actual processing.
46
+ #
47
+ # Without this, the allocations are not processed,
48
+ # and no ids are calculated.
49
+ #
50
+ def prepare!
51
+ allocations.process! amount, offset
52
+ end
68
53
 
69
- # Convenience methods.
70
- #
54
+ # Duration default is 0.
55
+ #
56
+ def duration
57
+ @duration || 0
58
+ end
59
+ # The total results. Delegates to the allocations.
60
+ #
61
+ # Caches.
62
+ #
63
+ def total
64
+ @total || @total = allocations.total || 0
65
+ end
71
66
 
72
- # Delegates to allocations.
73
- #
74
- def ids amount = 20
75
- allocations.ids amount
76
- end
67
+ # Convenience methods.
68
+ #
77
69
 
78
- # Human readable log.
79
- #
80
- def to_log query
81
- "#{log_type}|#{Time.now.to_s(:db)}|#{'%8f' % duration}|#{'%-50s' % query}|#{'%8d' % total}|#{'%4d' % offset}|#{'%2d' % allocations.size}|"
82
- end
83
- # The first character in the blog designates what type of query it is.
84
- #
85
- # No calculated ids means: No results.
86
- #
87
- def log_type
88
- amount.zero?? :'.' : :'>'
89
- end
70
+ # Delegates to allocations.
71
+ #
72
+ def ids amount = 20
73
+ allocations.ids amount
74
+ end
90
75
 
76
+ # Human readable log.
77
+ #
78
+ def to_log query
79
+ "#{log_type}|#{Time.now.to_s(:db)}|#{'%8f' % duration}|#{'%-50s' % query}|#{'%8d' % total}|#{'%4d' % offset}|#{'%2d' % allocations.size}|"
80
+ end
81
+ # The first character in the blog designates what type of query it is.
82
+ #
83
+ # No calculated ids means: No results.
84
+ #
85
+ def log_type
86
+ amount.zero?? :'.' : :'>'
91
87
  end
92
88
 
93
89
  end
data/lib/picky/search.rb CHANGED
@@ -99,7 +99,7 @@ class Search
99
99
  # Note: Internal method, use #search_with_text.
100
100
  #
101
101
  def execute tokens, ids, offset
102
- Internals::Results.from ids, offset, sorted_allocations(tokens)
102
+ Results.from ids, offset, sorted_allocations(tokens)
103
103
  end
104
104
 
105
105
  # Delegates the tokenizing to the query tokenizer.
@@ -1,12 +1,9 @@
1
1
  # encoding: utf-8
2
2
  #
3
3
 
4
- # Gathers different statistics
5
- # when methods are called.
4
+ # Gathers various statistics.
6
5
  #
7
- # Can be output using to_s.
8
- #
9
- class Statistics
6
+ class Statistics # :nodoc:all
10
7
 
11
8
  def self.instance
12
9
  @statistics ||= new
data/lib/tasks/try.rake CHANGED
@@ -6,7 +6,7 @@ namespace :try do
6
6
  task :index, [:text, :index, :category] => :application do |_, options|
7
7
  text, index, category = options.text, options.index, options.category
8
8
 
9
- tokenizer = index && category ? Indexes.find(index, category).tokenizer : Internals::Tokenizers::Index.default
9
+ tokenizer = category ? Indexes.find(index, category).tokenizer : Internals::Tokenizers::Index.default
10
10
 
11
11
  puts "\"#{text}\" is saved in the index as #{tokenizer.tokenize(text.dup).to_a}"
12
12
  end
@@ -22,6 +22,9 @@ namespace :try do
22
22
  task :both, [:text, :index, :category] => :application do |_, options|
23
23
  text, index, category = options.text, options.index, options.category
24
24
 
25
+ puts
26
+ fail "\x1b[31mrake try needs a text to try indexing and query preparation\x1b[m, e.g. rake 'try[yourtext]'." unless text
27
+
25
28
  Rake::Task[:"try:index"].invoke text, index, category
26
29
  Rake::Task[:"try:query"].invoke text
27
30
  end
@@ -47,10 +47,11 @@ describe Application do
47
47
  books_index.define_category :isbn,
48
48
  partial: Partial::None.new # Partially searching on an ISBN makes not much sense.
49
49
 
50
- geo_index = Index::Memory.new :geo, Sources::CSV.new(:location, :north, :east, file: 'data/ch.csv', col_sep: ',')
51
- geo_index.define_category :location
52
- geo_index.define_ranged_category(:north1, 1, precision: 3, from: :north)
53
- .define_ranged_category(:east1, 1, precision: 3, from: :east)
50
+ geo_index = Index::Memory.new :geo, Sources::CSV.new(:location, :north, :east, file: 'data/ch.csv', col_sep: ',') do
51
+ category :location
52
+ ranged_category :north1, 1, precision: 3, from: :north
53
+ ranged_category :east1, 1, precision: 3, from: :east
54
+ end
54
55
 
55
56
  rack_adapter.stub! :exclaim # Stopping it from exclaiming.
56
57
 
@@ -102,7 +102,7 @@ describe Internals::FrontendAdapters::Rack do
102
102
  env = rack_defaults_for '/searches/some_route?query=some_query'
103
103
 
104
104
  search = stub :search
105
- search.should_receive(:search_with_text).once.with(anything, 20, 0).and_return(Internals::Results.new)
105
+ search.should_receive(:search_with_text).once.with(anything, 20, 0).and_return(Results.new)
106
106
  Search.stub! :new => search
107
107
 
108
108
  @rack_adapter.route '/searches/some_route' => Search.new(:some_index, :some_other_index)
@@ -114,7 +114,7 @@ describe Internals::FrontendAdapters::Rack do
114
114
  env = rack_defaults_for '/searches/some_route?query=some_query&type=some_type'
115
115
 
116
116
  search = stub :search
117
- search.should_receive(:search_with_text).once.with(anything, 20, 0).and_return(Internals::Results.new)
117
+ search.should_receive(:search_with_text).once.with(anything, 20, 0).and_return(Results.new)
118
118
  Search.stub! :new => search
119
119
 
120
120
  @rack_adapter.route '/searches/some_route' => Search.new(:some_index, :some_other_index), :query => { :type => :some_type }
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Internals::Results do
3
+ describe Results do
4
4
 
5
5
  describe "from" do
6
6
  before(:each) do
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: picky
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: 6
5
- version: 2.0.0.pre1
5
+ version: 2.0.0.pre2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Florian Hanke
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-03-18 00:00:00 +01:00
13
+ date: 2011-03-21 00:00:00 +01:00
14
14
  default_executable: picky
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -127,9 +127,11 @@ files:
127
127
  - lib/picky/internals/tokenizers/base.rb
128
128
  - lib/picky/internals/tokenizers/index.rb
129
129
  - lib/picky/internals/tokenizers/query.rb
130
+ - lib/picky/internals.rb
130
131
  - lib/picky/loader.rb
131
132
  - lib/picky/loggers/search.rb
132
133
  - lib/picky/query/solr.rb
134
+ - lib/picky/query.rb
133
135
  - lib/picky/rack/harakiri.rb
134
136
  - lib/picky/results.rb
135
137
  - lib/picky/search.rb