picky 3.0.1 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. data/lib/picky/application.rb +12 -12
  2. data/lib/picky/backends/backend.rb +17 -0
  3. data/lib/picky/{backend → backends}/file/basic.rb +1 -1
  4. data/lib/picky/{backend → backends}/file/json.rb +1 -1
  5. data/lib/picky/{backend → backends}/file/marshal.rb +1 -1
  6. data/lib/picky/{backend → backends}/file/text.rb +1 -1
  7. data/lib/picky/backends/memory.rb +53 -0
  8. data/lib/picky/{backend → backends}/redis/basic.rb +9 -14
  9. data/lib/picky/backends/redis/float_hash.rb +26 -0
  10. data/lib/picky/{backend → backends}/redis/list_hash.rb +7 -11
  11. data/lib/picky/{backend → backends}/redis/string_hash.rb +7 -11
  12. data/lib/picky/backends/redis.rb +87 -0
  13. data/lib/picky/bundle.rb +107 -11
  14. data/lib/picky/category.rb +5 -5
  15. data/lib/picky/index.rb +329 -0
  16. data/lib/picky/index_indexed.rb +31 -0
  17. data/lib/picky/index_indexing.rb +161 -0
  18. data/lib/picky/indexed/bundle.rb +112 -0
  19. data/lib/picky/indexed/wrappers/exact_first.rb +1 -1
  20. data/lib/picky/indexers/parallel.rb +2 -1
  21. data/lib/picky/indexers/serial.rb +2 -1
  22. data/lib/picky/indexes_indexing.rb +1 -1
  23. data/lib/picky/indexing/bundle.rb +188 -0
  24. data/lib/picky/indexing/wrappers/category/location.rb +1 -1
  25. data/lib/picky/interfaces/live_parameters.rb +8 -8
  26. data/lib/picky/loader.rb +24 -38
  27. data/lib/picky/migrations/from_30_to_31.rb +61 -0
  28. data/lib/picky/query/allocation.rb +10 -5
  29. data/lib/picky/query/combinations.rb +70 -0
  30. data/lib/picky/query/indexes.rb +8 -7
  31. data/lib/picky/query/indexes_check.rb +47 -0
  32. data/lib/picky/query/token.rb +16 -29
  33. data/lib/picky/query/tokens.rb +4 -20
  34. data/lib/picky/search.rb +51 -58
  35. data/lib/picky/tokenizer.rb +231 -0
  36. data/lib/picky/tokenizers/location.rb +1 -1
  37. data/lib/tasks/try.rake +4 -12
  38. data/lib/tasks/try.rb +37 -0
  39. data/spec/lib/application_spec.rb +5 -5
  40. data/spec/lib/{backend → backends}/file/basic_spec.rb +2 -2
  41. data/spec/lib/{backend → backends}/file/json_spec.rb +2 -2
  42. data/spec/lib/{backend → backends}/file/marshal_spec.rb +2 -2
  43. data/spec/lib/{backend → backends}/file/text_spec.rb +1 -1
  44. data/spec/lib/backends/memory_spec.rb +77 -0
  45. data/spec/lib/{backend → backends}/redis/basic_spec.rb +19 -21
  46. data/spec/lib/backends/redis/float_hash_spec.rb +38 -0
  47. data/spec/lib/backends/redis/list_hash_spec.rb +27 -0
  48. data/spec/lib/backends/redis/string_hash_spec.rb +38 -0
  49. data/spec/lib/backends/redis_spec.rb +79 -0
  50. data/spec/lib/categories_indexed_spec.rb +3 -3
  51. data/spec/lib/category_indexed_spec.rb +6 -6
  52. data/spec/lib/category_indexing_spec.rb +1 -1
  53. data/spec/lib/category_spec.rb +1 -1
  54. data/spec/lib/frontend_adapters/rack_spec.rb +2 -2
  55. data/spec/lib/{indexes/index_indexed_spec.rb → index_indexed_spec.rb} +1 -1
  56. data/spec/lib/{indexes/index_indexing_spec.rb → index_indexing_spec.rb} +1 -1
  57. data/spec/lib/{indexes/index_spec.rb → index_spec.rb} +1 -1
  58. data/spec/lib/indexed/{bundle/memory_spec.rb → memory_spec.rb} +18 -18
  59. data/spec/lib/indexed/wrappers/exact_first_spec.rb +2 -2
  60. data/spec/lib/indexing/{bundle/memory_partial_generation_speed_spec.rb → bundle_partial_generation_speed_spec.rb} +3 -3
  61. data/spec/lib/indexing/bundle_spec.rb +302 -0
  62. data/spec/lib/query/allocation_spec.rb +21 -11
  63. data/spec/lib/query/combination_spec.rb +2 -2
  64. data/spec/lib/query/{combinations/base_spec.rb → combinations_spec.rb} +1 -1
  65. data/spec/lib/query/indexes_check_spec.rb +25 -0
  66. data/spec/lib/query/indexes_spec.rb +5 -1
  67. data/spec/lib/query/token_spec.rb +18 -20
  68. data/spec/lib/query/tokens_spec.rb +14 -65
  69. data/spec/lib/search_spec.rb +36 -37
  70. data/spec/lib/tasks/try_spec.rb +51 -0
  71. data/spec/lib/{tokenizers/base_spec.rb → tokenizer_spec.rb} +15 -44
  72. metadata +64 -81
  73. data/lib/picky/backend/base.rb +0 -121
  74. data/lib/picky/backend/files.rb +0 -28
  75. data/lib/picky/backend/redis.rb +0 -44
  76. data/lib/picky/indexed/bundle/base.rb +0 -47
  77. data/lib/picky/indexed/bundle/memory.rb +0 -88
  78. data/lib/picky/indexed/bundle/redis.rb +0 -91
  79. data/lib/picky/indexes/index.rb +0 -328
  80. data/lib/picky/indexes/index_indexed.rb +0 -35
  81. data/lib/picky/indexes/index_indexing.rb +0 -165
  82. data/lib/picky/indexes/memory.rb +0 -20
  83. data/lib/picky/indexes/redis.rb +0 -20
  84. data/lib/picky/indexing/bundle/base.rb +0 -242
  85. data/lib/picky/indexing/bundle/memory.rb +0 -26
  86. data/lib/picky/indexing/bundle/redis.rb +0 -26
  87. data/lib/picky/query/combinations/base.rb +0 -74
  88. data/lib/picky/query/combinations/memory.rb +0 -52
  89. data/lib/picky/query/combinations/redis.rb +0 -90
  90. data/lib/picky/query.rb +0 -6
  91. data/lib/picky/tokenizers/base.rb +0 -231
  92. data/lib/picky/tokenizers/index.rb +0 -34
  93. data/lib/picky/tokenizers/query.rb +0 -61
  94. data/spec/lib/backend/files_spec.rb +0 -189
  95. data/spec/lib/backend/redis/list_hash_spec.rb +0 -40
  96. data/spec/lib/backend/redis/string_hash_spec.rb +0 -47
  97. data/spec/lib/backend/redis_spec.rb +0 -170
  98. data/spec/lib/indexed/bundle/redis_spec.rb +0 -41
  99. data/spec/lib/indexes/redis_spec.rb +0 -15
  100. data/spec/lib/indexing/bundle/base_spec.rb +0 -38
  101. data/spec/lib/indexing/bundle/memory_spec.rb +0 -287
  102. data/spec/lib/indexing/bundle/redis_spec.rb +0 -283
  103. data/spec/lib/query/combinations/memory_spec.rb +0 -158
  104. data/spec/lib/query/combinations/redis_spec.rb +0 -172
  105. data/spec/lib/tokenizers/index_spec.rb +0 -69
  106. 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