picky 4.21.0 → 4.21.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 07e373957d9f7d673d29aa262102788d6947cee8
4
- data.tar.gz: 85ef2b296887de1cdceaff60c488e07260eb8358
3
+ metadata.gz: 6c8689ff998ff025e835e1a5e6661ce766d51246
4
+ data.tar.gz: ae0fe1a7cfbd7bbf511fd049249d462bb683d955
5
5
  SHA512:
6
- metadata.gz: a215df05ec60deedab57995a1ab45d241229ef1d9de5758410dc16992bc3ba51f3bd892899947d39730cdf9c189c3a9f3fe7e93b18054470a3e4273f3ac8ec62
7
- data.tar.gz: 5b92b5355a5aa033e0e78079b5a5f3cf4c55d14bf6f9eb0806b74cd014a0ad4b35f7168f50f66b27dfb46c438fd2006bcb42fa05f7c7435802099fdd932c92eb
6
+ metadata.gz: 602df847adb8be592eb798b261d41a22a530b09e8ea8a3b081a438b2153efef6320293a931e705a064e63b88a8b198fae891754999cd24da90d3923728cb2dbf
7
+ data.tar.gz: 1a98cf615c82128a6a107d4ec38ed747d5fc5a251318e167136cce36fb625ca814bacad6e15f60515e5e78781493378fd3dc53d5dff9e2e830829234b0f1c65d
data/lib/picky/bundle.rb CHANGED
@@ -43,7 +43,7 @@ module Picky
43
43
 
44
44
  forward :[], :[]=, :to => :configuration
45
45
  forward :index_directory, :to => :category
46
-
46
+
47
47
  # TODO Move the strategies into options.
48
48
  #
49
49
  def initialize name, category, weight_strategy, partial_strategy, similarity_strategy, options = {}
@@ -103,7 +103,7 @@ module Picky
103
103
  def empty
104
104
  on_all_indexes_call :empty
105
105
  end
106
-
106
+
107
107
  # Extracted to avoid duplicate code.
108
108
  #
109
109
  def on_all_indexes_call method_name
@@ -163,7 +163,7 @@ module Picky
163
163
  def index_path type = nil
164
164
  ::File.join index_directory, "#{category.name}_#{name}#{ "_#{type}" if type }"
165
165
  end
166
-
166
+
167
167
  def to_tree_s indent = 0, &block
168
168
  s = <<-TREE
169
169
  #{' ' * indent}#{self.class.name.gsub('Picky::','')}(#{name})
@@ -73,7 +73,17 @@ module Picky
73
73
  def key_format?
74
74
  key_format
75
75
  end
76
-
76
+
77
+ # Return the key format.
78
+ #
79
+ # If no key_format is defined on the category
80
+ # and the source has no key format, ask
81
+ # the index for one.
82
+ #
83
+ def id
84
+ @id ||= @index.id
85
+ end
86
+
77
87
  def static?
78
88
  @index.static? # || @static
79
89
  end
@@ -83,7 +93,7 @@ module Picky
83
93
  def from
84
94
  @from || name
85
95
  end
86
-
96
+
87
97
  # Return an appropriate source.
88
98
  #
89
99
  # If we have no explicit source, we'll check the index for one.
@@ -1,7 +1,7 @@
1
1
  module Picky
2
2
 
3
3
  class Category
4
-
4
+
5
5
  class Picky::IdNotGivenException < StandardError; end
6
6
 
7
7
  # Removes an indexed object with the
@@ -20,9 +20,9 @@ module Picky
20
20
  #
21
21
  def add object, where = :unshift
22
22
  if from.respond_to? :call
23
- add_text object.id, from.call(object), where
23
+ add_text object.send(id), from.call(object), where
24
24
  else
25
- add_text object.id, object.send(from), where
25
+ add_text object.send(id), object.send(from), where
26
26
  end
27
27
  end
28
28
 
@@ -30,20 +30,20 @@ module Picky
30
30
  # adds it again.
31
31
  #
32
32
  def replace object, where = :unshift
33
- remove object.id
33
+ remove object.send id
34
34
  add object, where
35
35
  end
36
-
36
+
37
37
  # Replaces just part of the indexed data.
38
38
  #
39
39
  # Note: Takes a hash as opposed to the add/replace method.
40
40
  #
41
41
  def replace_from hash #, id = (hash[:id] || hash['id'] || raise(IdNotGivenException.new)).send(key_format)
42
42
  return unless text = hash[from] || hash[from.to_s]
43
-
43
+
44
44
  raise IdNotGivenException.new unless id = hash[:id] || hash['id']
45
45
  id = id.send key_format if key_format?
46
-
46
+
47
47
  remove id
48
48
  add_text id, text
49
49
  end
@@ -71,13 +71,13 @@ module Picky
71
71
  else
72
72
  tokens = text_or_tokens
73
73
  end
74
-
74
+
75
75
  format = key_format?
76
76
  tokens.each { |text| add_tokenized_token id, text, where, format }
77
77
  rescue NoMethodError => e
78
78
  show_informative_add_text_error_message_for e
79
79
  end
80
-
80
+
81
81
  def show_informative_add_text_error_message_for e
82
82
  if e.name == :each
83
83
  raise %Q{#{e.message}. You probably set tokenize: false on category "#{name}". It will need an Enumerator of previously tokenized tokens.}
@@ -90,7 +90,7 @@ module Picky
90
90
  #
91
91
  def add_tokenized_token id, text, where = :unshift, format = true, static = false
92
92
  return unless text
93
-
93
+
94
94
  id = id.send key_format if format
95
95
  # text = text.to_sym if @symbols # SYMBOLS.
96
96
  id.freeze
@@ -6,14 +6,14 @@ module Picky
6
6
  module Indexing
7
7
 
8
8
  include Measuring
9
-
9
+
10
10
  # Runs the block and logs a few infos regarding the time it took.
11
11
  #
12
12
  def timed_indexing scheduler, &block
13
13
  Picky.logger.info "Picky is indexing using #{scheduler.fork? ? 'multiple processes' : 'a single process'}: "
14
14
  Picky.logger.info " Done in #{timed(&block).round}s.\n"
15
15
  end
16
-
16
+
17
17
  # Indexing works the same way, always:
18
18
  # * Prepare the scheduler.
19
19
  # * Cache the scheduler.
data/lib/picky/index.rb CHANGED
@@ -126,7 +126,7 @@ module Picky
126
126
 
127
127
  instance_eval(&Proc.new) if block_given?
128
128
  end
129
-
129
+
130
130
  # TODO Doc.
131
131
  #
132
132
  def static
@@ -149,7 +149,7 @@ module Picky
149
149
  @backend ||= Backends::Memory.new
150
150
  end
151
151
  end
152
-
152
+
153
153
  # The directory used by this index.
154
154
  #
155
155
  # Note: Used @directory ||=, but needs to be dynamic.
@@ -157,7 +157,7 @@ module Picky
157
157
  def directory
158
158
  ::File.join(Picky.root, 'index', PICKY_ENVIRONMENT, name.to_s)
159
159
  end
160
-
160
+
161
161
  # Restrict categories to the given ones.
162
162
  #
163
163
  # Functionally equivalent as if indexes didn't
@@ -380,7 +380,7 @@ INDEX
380
380
  ].compact
381
381
  "#{self.class}(#{s.join(', ')})"
382
382
  end
383
-
383
+
384
384
  # Displays the structure as a tree.
385
385
  #
386
386
  def to_tree_s indent = 0
@@ -89,6 +89,17 @@ module Picky
89
89
  @source.respond_to?(:call) ? @source.call : @source
90
90
  end
91
91
 
92
+ # API method.
93
+ #
94
+ # Defines the name of the ID method to use on the indexed object.
95
+ #
96
+ # === Parameters
97
+ # * name: Method name of the ID.
98
+ #
99
+ def id name = nil
100
+ @id_name = name || @id_name || :id
101
+ end
102
+
92
103
  # Define a key_format on the index.
93
104
  #
94
105
  # Parameter is a method name to use on the key (e.g. :to_i, :to_s, :strip, :split).
@@ -58,15 +58,17 @@ module Picky
58
58
  def index_flush objects, file, category, cache, tokenizer
59
59
  comma = ?,
60
60
  newline = ?\n
61
-
61
+
62
62
  # Optimized, therefore duplicate code.
63
63
  #
64
+ id = category.id
65
+ from = category.from
64
66
  objects.each do |object|
65
- tokens = object.send category.from
67
+ tokens = object.send from
66
68
  tokens, _ = tokenizer.tokenize tokens if tokenizer # Note: Originals not needed. TODO Optimize?
67
69
  tokens.each do |token_text|
68
70
  next unless token_text
69
- cache << object.id << comma << token_text << newline
71
+ cache << object.send(id) << comma << token_text << newline
70
72
  end
71
73
  end
72
74
 
@@ -0,0 +1,66 @@
1
+ # encoding: utf-8
2
+ #
3
+ require 'spec_helper'
4
+
5
+ describe "id option" do
6
+
7
+ it 'can be given a different id (in-ruby based)' do
8
+ data = Picky::Index.new :id do
9
+ id :number
10
+ category :text
11
+ end
12
+
13
+ require 'ostruct'
14
+
15
+ thing = OpenStruct.new number: 1, text: "ohai"
16
+ other = OpenStruct.new number: 2, text: "ohai kthxbye"
17
+
18
+ data.add thing
19
+ data.add other
20
+
21
+ try = Picky::Search.new data
22
+
23
+ try.search("text:kthxbye").ids.should == [2]
24
+ end
25
+
26
+ it 'can be given a different id (source based)' do
27
+ require 'ostruct'
28
+
29
+ things = []
30
+ things << OpenStruct.new(number: 1, text: "ohai")
31
+ things << OpenStruct.new(number: 2, text: "ohai kthxbye")
32
+
33
+ data = Picky::Index.new :id do
34
+ source { things }
35
+
36
+ key_format :to_i
37
+ id :number # TODO :format => :to_i
38
+ category :text
39
+ end
40
+
41
+ data.index
42
+
43
+ try = Picky::Search.new data
44
+
45
+ try.search("text:kthxbye").ids.should == [2]
46
+ end
47
+
48
+ it 'default is id' do
49
+ index = Picky::Index.new :id do
50
+ category :text
51
+ end
52
+
53
+ require 'ostruct'
54
+
55
+ thing = OpenStruct.new id: 1, text: "ohai"
56
+ other = OpenStruct.new id: 2, text: "ohai kthxbye"
57
+
58
+ index.add thing
59
+ index.add other
60
+
61
+ try = Picky::Search.new index
62
+
63
+ try.search("text:kthxbye").ids.should == [2]
64
+ end
65
+
66
+ end
@@ -126,27 +126,23 @@ describe 'Search#terminate_early' do
126
126
  try.search('hello', 1, 20).allocations.map(&:count).should == [6, 6, 6, 6]
127
127
  try.search('hello', 1, 24).allocations.map(&:count).should == [6, 6, 6, 6]
128
128
 
129
- try.search('hello', 1, 0).to_hash.should == {
130
- :allocations => [
129
+ result_hash = try.search('hello', 1, 0).to_hash
130
+ result_hash[:allocations].should == [
131
131
  [:terminate_early, 1.792, 6, [[:text1, "hello", "hello"]], [6]],
132
132
  [:terminate_early, 1.792, 6, [[:text2, "hello", "hello"]], []]
133
- ],
134
- :offset => 0,
135
- :duration => anything,
136
- :total => 12
137
- }
138
-
139
- try.search('hello', 1, 12).to_hash.should == {
140
- :allocations => [
133
+ ]
134
+ result_hash[:offset].should == 0
135
+ result_hash[:total].should == 12
136
+
137
+ result_hash = try.search('hello', 1, 12).to_hash
138
+ result_hash[:allocations].should == [
141
139
  [:terminate_early, 1.792, 6, [[:text1, "hello", "hello"]], []],
142
140
  [:terminate_early, 1.792, 6, [[:text2, "hello", "hello"]], []],
143
141
  [:terminate_early, 1.792, 6, [[:text3, "hello", "hello"]], [6]],
144
142
  [:terminate_early, 1.792, 6, [[:text4, "hello", "hello"]], []]
145
- ],
146
- :offset => 12,
147
- :duration => anything,
148
- :total => 24
149
- }
143
+ ]
144
+ result_hash[:offset].should == 12
145
+ result_hash[:total].should == 24
150
146
 
151
147
  GC.start
152
148
 
@@ -4,7 +4,7 @@ require 'spec_helper'
4
4
 
5
5
  # We need to load the CLI file explicitly as the CLI is not loaded with the Loader (not needed in the server, only for script runs).
6
6
  #
7
- require_relative '../../../auxiliary/picky/cli'
7
+ require_relative '../../../tools/picky/cli'
8
8
 
9
9
  describe Picky::CLI do
10
10
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: picky
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.21.0
4
+ version: 4.21.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Hanke
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-01 00:00:00.000000000 Z
11
+ date: 2014-05-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -243,6 +243,7 @@ files:
243
243
  - spec/functional/exact_first_spec.rb
244
244
  - spec/functional/facets_spec.rb
245
245
  - spec/functional/from_spec.rb
246
+ - spec/functional/id_spec.rb
246
247
  - spec/functional/ignore_allocations_spec.rb
247
248
  - spec/functional/ignore_spec.rb
248
249
  - spec/functional/max_allocations_spec.rb
@@ -397,7 +398,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
397
398
  version: '0'
398
399
  requirements: []
399
400
  rubyforge_project: http://rubyforge.org/projects/picky
400
- rubygems_version: 2.2.0
401
+ rubygems_version: 2.2.2
401
402
  signing_key:
402
403
  specification_version: 4
403
404
  summary: 'Picky: Semantic Search Engine. Clever Interface. Good Tools.'
@@ -421,6 +422,7 @@ test_files:
421
422
  - spec/functional/exact_first_spec.rb
422
423
  - spec/functional/facets_spec.rb
423
424
  - spec/functional/from_spec.rb
425
+ - spec/functional/id_spec.rb
424
426
  - spec/functional/ignore_allocations_spec.rb
425
427
  - spec/functional/ignore_spec.rb
426
428
  - spec/functional/max_allocations_spec.rb
@@ -553,4 +555,3 @@ test_files:
553
555
  - spec/lib/tokenizer_spec.rb
554
556
  - spec/performant_spec.rb
555
557
  - spec/tools/picky/cli_spec.rb
556
- has_rdoc: