picky 4.8.0 → 4.8.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/picky/category.rb +1 -0
- data/spec/functional/reloading_spec.rb +39 -0
- data/spec/functional/sorting_spec.rb +60 -0
- metadata +8 -4
data/lib/picky/category.rb
CHANGED
@@ -0,0 +1,39 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe "Realtime Indexing" do
|
6
|
+
|
7
|
+
Book = Struct.new(:id, :title, :author)
|
8
|
+
|
9
|
+
context 'default index' do
|
10
|
+
let(:index) do
|
11
|
+
Picky::Index.new(:books) do
|
12
|
+
category :title
|
13
|
+
category :author, similarity: Picky::Generators::Similarity::DoubleMetaphone.new(3)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
let(:books) { Picky::Search.new index }
|
17
|
+
|
18
|
+
before(:each) do
|
19
|
+
index.add Book.new(1, "Title", "Author")
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'dumping and loading' do
|
23
|
+
it "doesn't find books anymore after dumping and loading and updating" do
|
24
|
+
index.replace Book.new(2, "Title New", "Author New")
|
25
|
+
|
26
|
+
books.search("title").ids.should == [2, 1]
|
27
|
+
|
28
|
+
index.dump
|
29
|
+
index.load
|
30
|
+
index.build_realtime_mapping
|
31
|
+
|
32
|
+
index.replace Book.new(2, "Blah New", "Author New")
|
33
|
+
|
34
|
+
books.search("title").ids.should == [1]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
require 'ostruct'
|
6
|
+
|
7
|
+
describe "special sorting" do
|
8
|
+
|
9
|
+
before(:each) do
|
10
|
+
Picky::Indexes.clear_indexes
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'returns exact results first' do
|
14
|
+
data = Picky::Index.new :sorted do
|
15
|
+
category :first, partial: Picky::Partial::Substring.new(from: 1)
|
16
|
+
category :last, partial: Picky::Partial::Substring.new(from: 1)
|
17
|
+
end
|
18
|
+
|
19
|
+
SortedThing = Struct.new :id, :first, :last
|
20
|
+
|
21
|
+
things = []
|
22
|
+
things << SortedThing.new(1, 'Abracadabra', 'Mirgel')
|
23
|
+
things << SortedThing.new(2, 'Abraham', 'Minder')
|
24
|
+
things << SortedThing.new(3, 'Azzie', 'Mueller')
|
25
|
+
|
26
|
+
sorted_by_first = things.sort_by &:first
|
27
|
+
sorted_by_last = things.sort_by &:last
|
28
|
+
|
29
|
+
# We give each index a differently sorted source.
|
30
|
+
#
|
31
|
+
data[:first].source = sorted_by_first
|
32
|
+
data[:last].source = sorted_by_last
|
33
|
+
|
34
|
+
data.index
|
35
|
+
|
36
|
+
try = Picky::Search.new data
|
37
|
+
|
38
|
+
# The category in which more results
|
39
|
+
# are found determines the sort order.
|
40
|
+
#
|
41
|
+
|
42
|
+
# If there is the same number of results,
|
43
|
+
# the category of the last word determines
|
44
|
+
# the order.
|
45
|
+
#
|
46
|
+
try.search('a').ids.should == [1,2,3]
|
47
|
+
try.search('m').ids.should == [2,1,3]
|
48
|
+
try.search('a* m').ids.should == [2,1,3]
|
49
|
+
try.search('m* a').ids.should == [1,2,3]
|
50
|
+
|
51
|
+
# If one category has more "results",
|
52
|
+
# it is chosen for ordering.
|
53
|
+
#
|
54
|
+
try.search('m* ab').ids.should == [2,1]
|
55
|
+
try.search('ab* m').ids.should == [2,1]
|
56
|
+
try.search('mi* a').ids.should == [1,2]
|
57
|
+
try.search('a* mi').ids.should == [1,2]
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
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.8.
|
4
|
+
version: 4.8.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -34,7 +34,7 @@ dependencies:
|
|
34
34
|
requirements:
|
35
35
|
- - ~>
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version: 4.8.
|
37
|
+
version: 4.8.1
|
38
38
|
type: :development
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -42,7 +42,7 @@ dependencies:
|
|
42
42
|
requirements:
|
43
43
|
- - ~>
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version: 4.8.
|
45
|
+
version: 4.8.1
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
47
|
name: text
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
@@ -299,7 +299,9 @@ files:
|
|
299
299
|
- spec/functional/only_spec.rb
|
300
300
|
- spec/functional/realtime_spec.rb
|
301
301
|
- spec/functional/regression_spec.rb
|
302
|
+
- spec/functional/reloading_spec.rb
|
302
303
|
- spec/functional/remap_qualifiers_spec.rb
|
304
|
+
- spec/functional/sorting_spec.rb
|
303
305
|
- spec/functional/speed_spec.rb
|
304
306
|
- spec/functional/stemming_spec.rb
|
305
307
|
- spec/functional/terminate_early_spec.rb
|
@@ -458,7 +460,9 @@ test_files:
|
|
458
460
|
- spec/functional/only_spec.rb
|
459
461
|
- spec/functional/realtime_spec.rb
|
460
462
|
- spec/functional/regression_spec.rb
|
463
|
+
- spec/functional/reloading_spec.rb
|
461
464
|
- spec/functional/remap_qualifiers_spec.rb
|
465
|
+
- spec/functional/sorting_spec.rb
|
462
466
|
- spec/functional/speed_spec.rb
|
463
467
|
- spec/functional/stemming_spec.rb
|
464
468
|
- spec/functional/terminate_early_spec.rb
|