picky 3.0.1 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/picky/application.rb +12 -12
- data/lib/picky/backends/backend.rb +17 -0
- data/lib/picky/{backend → backends}/file/basic.rb +1 -1
- data/lib/picky/{backend → backends}/file/json.rb +1 -1
- data/lib/picky/{backend → backends}/file/marshal.rb +1 -1
- data/lib/picky/{backend → backends}/file/text.rb +1 -1
- data/lib/picky/backends/memory.rb +53 -0
- data/lib/picky/{backend → backends}/redis/basic.rb +9 -14
- data/lib/picky/backends/redis/float_hash.rb +26 -0
- data/lib/picky/{backend → backends}/redis/list_hash.rb +7 -11
- data/lib/picky/{backend → backends}/redis/string_hash.rb +7 -11
- data/lib/picky/backends/redis.rb +87 -0
- data/lib/picky/bundle.rb +107 -11
- data/lib/picky/category.rb +5 -5
- data/lib/picky/index.rb +329 -0
- data/lib/picky/index_indexed.rb +31 -0
- data/lib/picky/index_indexing.rb +161 -0
- data/lib/picky/indexed/bundle.rb +112 -0
- data/lib/picky/indexed/wrappers/exact_first.rb +1 -1
- data/lib/picky/indexers/parallel.rb +2 -1
- data/lib/picky/indexers/serial.rb +2 -1
- data/lib/picky/indexes_indexing.rb +1 -1
- data/lib/picky/indexing/bundle.rb +188 -0
- data/lib/picky/indexing/wrappers/category/location.rb +1 -1
- data/lib/picky/interfaces/live_parameters.rb +8 -8
- data/lib/picky/loader.rb +24 -38
- data/lib/picky/migrations/from_30_to_31.rb +61 -0
- data/lib/picky/query/allocation.rb +10 -5
- data/lib/picky/query/combinations.rb +70 -0
- data/lib/picky/query/indexes.rb +8 -7
- data/lib/picky/query/indexes_check.rb +47 -0
- data/lib/picky/query/token.rb +16 -29
- data/lib/picky/query/tokens.rb +4 -20
- data/lib/picky/search.rb +51 -58
- data/lib/picky/tokenizer.rb +231 -0
- data/lib/picky/tokenizers/location.rb +1 -1
- data/lib/tasks/try.rake +4 -12
- data/lib/tasks/try.rb +37 -0
- data/spec/lib/application_spec.rb +5 -5
- data/spec/lib/{backend → backends}/file/basic_spec.rb +2 -2
- data/spec/lib/{backend → backends}/file/json_spec.rb +2 -2
- data/spec/lib/{backend → backends}/file/marshal_spec.rb +2 -2
- data/spec/lib/{backend → backends}/file/text_spec.rb +1 -1
- data/spec/lib/backends/memory_spec.rb +77 -0
- data/spec/lib/{backend → backends}/redis/basic_spec.rb +19 -21
- data/spec/lib/backends/redis/float_hash_spec.rb +38 -0
- data/spec/lib/backends/redis/list_hash_spec.rb +27 -0
- data/spec/lib/backends/redis/string_hash_spec.rb +38 -0
- data/spec/lib/backends/redis_spec.rb +79 -0
- data/spec/lib/categories_indexed_spec.rb +3 -3
- data/spec/lib/category_indexed_spec.rb +6 -6
- data/spec/lib/category_indexing_spec.rb +1 -1
- data/spec/lib/category_spec.rb +1 -1
- data/spec/lib/frontend_adapters/rack_spec.rb +2 -2
- data/spec/lib/{indexes/index_indexed_spec.rb → index_indexed_spec.rb} +1 -1
- data/spec/lib/{indexes/index_indexing_spec.rb → index_indexing_spec.rb} +1 -1
- data/spec/lib/{indexes/index_spec.rb → index_spec.rb} +1 -1
- data/spec/lib/indexed/{bundle/memory_spec.rb → memory_spec.rb} +18 -18
- data/spec/lib/indexed/wrappers/exact_first_spec.rb +2 -2
- data/spec/lib/indexing/{bundle/memory_partial_generation_speed_spec.rb → bundle_partial_generation_speed_spec.rb} +3 -3
- data/spec/lib/indexing/bundle_spec.rb +302 -0
- data/spec/lib/query/allocation_spec.rb +21 -11
- data/spec/lib/query/combination_spec.rb +2 -2
- data/spec/lib/query/{combinations/base_spec.rb → combinations_spec.rb} +1 -1
- data/spec/lib/query/indexes_check_spec.rb +25 -0
- data/spec/lib/query/indexes_spec.rb +5 -1
- data/spec/lib/query/token_spec.rb +18 -20
- data/spec/lib/query/tokens_spec.rb +14 -65
- data/spec/lib/search_spec.rb +36 -37
- data/spec/lib/tasks/try_spec.rb +51 -0
- data/spec/lib/{tokenizers/base_spec.rb → tokenizer_spec.rb} +15 -44
- metadata +64 -81
- data/lib/picky/backend/base.rb +0 -121
- data/lib/picky/backend/files.rb +0 -28
- data/lib/picky/backend/redis.rb +0 -44
- data/lib/picky/indexed/bundle/base.rb +0 -47
- data/lib/picky/indexed/bundle/memory.rb +0 -88
- data/lib/picky/indexed/bundle/redis.rb +0 -91
- data/lib/picky/indexes/index.rb +0 -328
- data/lib/picky/indexes/index_indexed.rb +0 -35
- data/lib/picky/indexes/index_indexing.rb +0 -165
- data/lib/picky/indexes/memory.rb +0 -20
- data/lib/picky/indexes/redis.rb +0 -20
- data/lib/picky/indexing/bundle/base.rb +0 -242
- data/lib/picky/indexing/bundle/memory.rb +0 -26
- data/lib/picky/indexing/bundle/redis.rb +0 -26
- data/lib/picky/query/combinations/base.rb +0 -74
- data/lib/picky/query/combinations/memory.rb +0 -52
- data/lib/picky/query/combinations/redis.rb +0 -90
- data/lib/picky/query.rb +0 -6
- data/lib/picky/tokenizers/base.rb +0 -231
- data/lib/picky/tokenizers/index.rb +0 -34
- data/lib/picky/tokenizers/query.rb +0 -61
- data/spec/lib/backend/files_spec.rb +0 -189
- data/spec/lib/backend/redis/list_hash_spec.rb +0 -40
- data/spec/lib/backend/redis/string_hash_spec.rb +0 -47
- data/spec/lib/backend/redis_spec.rb +0 -170
- data/spec/lib/indexed/bundle/redis_spec.rb +0 -41
- data/spec/lib/indexes/redis_spec.rb +0 -15
- data/spec/lib/indexing/bundle/base_spec.rb +0 -38
- data/spec/lib/indexing/bundle/memory_spec.rb +0 -287
- data/spec/lib/indexing/bundle/redis_spec.rb +0 -283
- data/spec/lib/query/combinations/memory_spec.rb +0 -158
- data/spec/lib/query/combinations/redis_spec.rb +0 -172
- data/spec/lib/tokenizers/index_spec.rb +0 -69
- data/spec/lib/tokenizers/query_spec.rb +0 -121
@@ -1,121 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
describe Picky::Tokenizers::Query do
|
5
|
-
|
6
|
-
let(:tokenizer) { described_class.new }
|
7
|
-
|
8
|
-
describe "default*" do
|
9
|
-
before(:all) do
|
10
|
-
@old = described_class.default
|
11
|
-
end
|
12
|
-
after(:all) do
|
13
|
-
described_class.default = @old
|
14
|
-
end
|
15
|
-
it "has a reader" do
|
16
|
-
lambda { described_class.default }.should_not raise_error
|
17
|
-
end
|
18
|
-
it "returns by default a new Index" do
|
19
|
-
described_class.default.should be_kind_of(described_class)
|
20
|
-
end
|
21
|
-
it "has a writer" do
|
22
|
-
lambda { described_class.default = :bla }.should_not raise_error
|
23
|
-
end
|
24
|
-
it "returns what has been written, if something has been written" do
|
25
|
-
described_class.default = :some_default
|
26
|
-
|
27
|
-
described_class.default.should == :some_default
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe "maximum_tokens" do
|
32
|
-
it "should be set to 5 by default" do
|
33
|
-
tokenizer.maximum_tokens.should == 5
|
34
|
-
end
|
35
|
-
it "should be settable" do
|
36
|
-
described_class.new(maximum_tokens: 3).maximum_tokens.should == 3
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
describe 'preprocess' do
|
41
|
-
it 'should call methods in order' do
|
42
|
-
text = stub :text
|
43
|
-
|
44
|
-
tokenizer.should_receive(:substitute_characters).once.with(text).and_return text
|
45
|
-
tokenizer.should_receive(:remove_illegals).once.ordered.with text
|
46
|
-
tokenizer.should_receive(:remove_non_single_stopwords).once.ordered.with text
|
47
|
-
|
48
|
-
tokenizer.preprocess text
|
49
|
-
end
|
50
|
-
it 'should return the text unchanged by default' do
|
51
|
-
text = "some text"
|
52
|
-
|
53
|
-
tokenizer.preprocess(text).should == text
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
describe 'process' do
|
58
|
-
before(:each) do
|
59
|
-
@tokens = mock :tokens, :null_object => true
|
60
|
-
end
|
61
|
-
it 'should call methods on the tokens in order' do
|
62
|
-
@tokens.should_receive(:reject).once.ordered
|
63
|
-
@tokens.should_receive(:cap).once.ordered
|
64
|
-
@tokens.should_receive(:partialize_last).once.ordered
|
65
|
-
|
66
|
-
tokenizer.process @tokens
|
67
|
-
end
|
68
|
-
it 'should return the tokens' do
|
69
|
-
tokenizer.process(@tokens).should == @tokens
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
describe 'pretokenize' do
|
74
|
-
def self.it_should_pretokenize text, expected
|
75
|
-
it "should pretokenize #{text} as #{expected}" do
|
76
|
-
tokenizer.pretokenize(text).should == expected
|
77
|
-
end
|
78
|
-
end
|
79
|
-
it_should_pretokenize 'test miau test', ['test', 'miau', 'test']
|
80
|
-
end
|
81
|
-
|
82
|
-
describe "tokenizing" do
|
83
|
-
def self.it_should_tokenize_token(text, expected)
|
84
|
-
it "should handle the #{text} case" do
|
85
|
-
tokenizer.tokenize(text).map(&:text).should == expected
|
86
|
-
end
|
87
|
-
end
|
88
|
-
it_should_tokenize_token 'simple tokenizing on \s', [:simple, :tokenizing, :on, :'\s']
|
89
|
-
end
|
90
|
-
|
91
|
-
describe 'normalize_with_patterns' do
|
92
|
-
def self.it_should_pattern_normalize original, expected
|
93
|
-
it "should normalize #{original} with pattern into #{expected}" do
|
94
|
-
tokenizer.normalize_with_patterns(original).should == expected
|
95
|
-
end
|
96
|
-
end
|
97
|
-
it_should_pattern_normalize 'no pattern normalization', 'no pattern normalization'
|
98
|
-
end
|
99
|
-
|
100
|
-
describe 'reject' do
|
101
|
-
it 'should reject blank tokens' do
|
102
|
-
tokenizer.reject(["some token answering to blank?", nil, nil]).should == ["some token answering to blank?"]
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
describe "last token" do
|
107
|
-
it "should be partial" do
|
108
|
-
tokenizer.tokenize("First Second Third Last").last.instance_variable_get(:@partial).should be_true
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
describe ".tokenize" do
|
113
|
-
it "should return an Array of tokens" do
|
114
|
-
tokenizer.tokenize('test test').to_a.should be_instance_of(Array)
|
115
|
-
end
|
116
|
-
it "should return an empty tokenized query if the query string is blank or empty" do
|
117
|
-
tokenizer.tokenize('').map(&:to_s).should == []
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
end
|