picky 4.0.6 → 4.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -82,10 +82,13 @@ module Picky
82
82
  # Partializes the text and then adds each.
83
83
  #
84
84
  def add_partialized id, text, where = :unshift
85
- self.partial_strategy.each_partial text do |partial_text|
85
+ partialized text do |partial_text|
86
86
  add id, partial_text, where
87
87
  end
88
88
  end
89
+ def partialized text, &block
90
+ self.partial_strategy.each_partial text, &block
91
+ end
89
92
 
90
93
  # Builds the realtime mapping.
91
94
  #
@@ -5,6 +5,7 @@ module Picky
5
5
  each_delegate :remove,
6
6
  :add,
7
7
  :replace,
8
+ :replace_from,
8
9
  :clear_realtime,
9
10
  :build_realtime_mapping,
10
11
  :to => :categories
@@ -15,8 +15,7 @@ module Picky
15
15
  # given object.
16
16
  #
17
17
  def add object, where = :unshift
18
- tokens, _ = tokenizer.tokenize object.send(from)
19
- add_tokenized object.id, tokens, where
18
+ add_text object.id, object.send(from), where
20
19
  end
21
20
 
22
21
  # Removes the object's id, and then
@@ -26,6 +25,22 @@ module Picky
26
25
  remove object.id
27
26
  add object, where
28
27
  end
28
+
29
+ # Replaces just part of the indexed data.
30
+ #
31
+ # Note: Takes a hash as opposed to the add/replace method.
32
+ #
33
+ def replace_from hash
34
+ # TODO Decide on a format.
35
+ #
36
+ return unless text = hash[from] || hash[from.to_s]
37
+
38
+ id = hash[:id] || hash['id']
39
+ id = id.send key_format
40
+
41
+ remove id
42
+ add_text id, text
43
+ end
29
44
 
30
45
  # Add at the end.
31
46
  #
@@ -42,7 +57,9 @@ module Picky
42
57
  # For the given id, adds the list of
43
58
  # strings to the index for the given id.
44
59
  #
45
- def add_tokenized id, tokens, where = :unshift
60
+ def add_text id, text, where = :unshift
61
+ # text = text.to_sym if @symbols # TODO Symbols.
62
+ tokens, _ = tokenizer.tokenize text
46
63
  tokens.each { |text| add_tokenized_token id.send(key_format), text, where, false }
47
64
  end
48
65
 
@@ -7,6 +7,7 @@ module Picky
7
7
  delegate :remove, # aka "delete".
8
8
  :add, # aka "insert".
9
9
  :replace, # aka "insert or update". Thus, not called update.
10
+ :replace_from, # TODO Naming ok?
10
11
  :clear_realtime,
11
12
  :build_realtime_mapping,
12
13
  :to => :categories
@@ -149,27 +149,28 @@ module Picky
149
149
  @@split_qualifiers = ','
150
150
  def qualify
151
151
  @qualifiers, @text = (@text || EMPTY_STRING).split(@@split_qualifier_text, 2)
152
- @qualifiers, @text = if @text.blank?
153
- [nil, (@qualifiers || EMPTY_STRING)]
152
+ if @text.blank?
153
+ @text = @qualifiers || EMPTY_STRING
154
+ @qualifiers = nil
154
155
  else
155
- [@qualifiers.split(@@split_qualifiers), @text]
156
+ @qualifiers = @qualifiers.split @@split_qualifiers
156
157
  end
157
- # if @text.blank?
158
- # @qualifiers = nil
159
- # @text = @qualifiers || EMPTY_STRING
160
- # else
161
- # @qualifiers = @qualifiers.split @@split_qualifiers
162
- # end
163
158
  end
164
-
165
- # Internally, qualifiers are nil if there are none.
166
- # This returns an empty array in this case for a nicer API.
159
+
160
+ # Returns the qualifiers as an array.
161
+ #
162
+ # Example:
163
+ # token.qualifiers # => ['title', 'author']
164
+ # token.qualifiers # => []
165
+ #
166
+ # Note: Internally, qualifiers are nil if there are none.
167
167
  #
168
168
  def qualifiers
169
169
  @qualifiers || []
170
170
  end
171
171
 
172
- #
172
+ # Returns the token in the form
173
+ # ['original:Text', 'processedtext']
173
174
  #
174
175
  def to_result
175
176
  [@original, @text]
@@ -177,6 +178,8 @@ module Picky
177
178
 
178
179
  # Internal identifier.
179
180
  #
181
+ # Note: Used in many backends.
182
+ #
180
183
  def identifier
181
184
  "#{similar?? :similarity : :inverted}:#{@text}"
182
185
  end
@@ -0,0 +1,24 @@
1
+ module Picky
2
+ module Sinatra
3
+
4
+ module IndexActions
5
+
6
+ def self.extended base
7
+ base.post '/' do
8
+ index_name = params[:index]
9
+ index = Picky::Indexes[index_name.to_sym]
10
+ data = params[:data]
11
+ index.replace_from data if data
12
+ end
13
+ base.delete '/' do
14
+ index_name = params[:index]
15
+ index = Picky::Indexes[index_name.to_sym]
16
+ id = params[:data][:id]
17
+ index.remove id if id
18
+ end
19
+ end
20
+
21
+ end
22
+
23
+ end
24
+ end
data/lib/picky/sinatra.rb CHANGED
@@ -31,4 +31,7 @@ end
31
31
  #
32
32
  if private_methods.include? :get
33
33
  extend Picky::Sinatra
34
+ # Enable index actions.
35
+ #
36
+ require_relative 'sinatra/index_actions'
34
37
  end
@@ -139,7 +139,9 @@ describe Picky::Query::Token do
139
139
  describe 'qualify' do
140
140
  def self.it_should_qualify text, expected_result
141
141
  it "should extract the qualifier #{expected_result} from #{text}" do
142
- described_class.new(text).qualify.should == expected_result
142
+ token = described_class.new text
143
+ token.qualify
144
+ [token.instance_variable_get(:@qualifiers), token.text].should == expected_result
143
145
  end
144
146
  end
145
147
  it_should_qualify 'spec:qualifier', [['spec'], 'qualifier']
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: picky
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.6
4
+ version: 4.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-02 00:00:00.000000000 Z
12
+ date: 2012-01-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70313201158420 !ruby/object:Gem::Requirement
16
+ requirement: &70160585740240 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,21 +21,21 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70313201158420
24
+ version_requirements: *70160585740240
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: picky-client
27
- requirement: &70313201157320 !ruby/object:Gem::Requirement
27
+ requirement: &70160585738100 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
31
31
  - !ruby/object:Gem::Version
32
- version: 4.0.6
32
+ version: 4.0.7
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70313201157320
35
+ version_requirements: *70160585738100
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: text
38
- requirement: &70313201154620 !ruby/object:Gem::Requirement
38
+ requirement: &70160585737280 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70313201154620
46
+ version_requirements: *70160585737280
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: yajl-ruby
49
- requirement: &70313201153540 !ruby/object:Gem::Requirement
49
+ requirement: &70160585735700 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70313201153540
57
+ version_requirements: *70160585735700
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: activesupport
60
- requirement: &70313201152460 !ruby/object:Gem::Requirement
60
+ requirement: &70160585734980 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '3.0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *70313201152460
68
+ version_requirements: *70160585734980
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: procrastinate
71
- requirement: &70313201151140 !ruby/object:Gem::Requirement
71
+ requirement: &70160585749640 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0.4'
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *70313201151140
79
+ version_requirements: *70160585749640
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: rack_fast_escape
82
- requirement: &70313201150480 !ruby/object:Gem::Requirement
82
+ requirement: &70160585748580 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,7 +87,7 @@ dependencies:
87
87
  version: '0'
88
88
  type: :runtime
89
89
  prerelease: false
90
- version_requirements: *70313201150480
90
+ version_requirements: *70160585748580
91
91
  description: Fast Ruby semantic text search engine with comfortable single field interface.
92
92
  email: florian.hanke+picky@gmail.com
93
93
  executables:
@@ -214,6 +214,7 @@ files:
214
214
  - lib/picky/results.rb
215
215
  - lib/picky/scheduler.rb
216
216
  - lib/picky/search.rb
217
+ - lib/picky/sinatra/index_actions.rb
217
218
  - lib/picky/sinatra.rb
218
219
  - lib/picky/statistics.rb
219
220
  - lib/picky/tasks.rb