dnif 0.0.1.beta.3 → 0.0.1.beta.4

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.
Files changed (44) hide show
  1. data/.gitignore +4 -0
  2. data/.rspec +2 -0
  3. data/Gemfile +15 -0
  4. data/Gemfile.lock +52 -0
  5. data/Rakefile +24 -26
  6. data/dnif.gemspec +81 -55
  7. data/lib/dnif.rb +73 -24
  8. data/lib/dnif/configuration.rb +4 -3
  9. data/lib/dnif/document.rb +8 -8
  10. data/lib/dnif/indexer.rb +0 -2
  11. data/lib/dnif/schema.rb +1 -1
  12. data/lib/dnif/search.rb +1 -50
  13. data/lib/dnif/tasks.rb +11 -11
  14. data/lib/dnif/version.rb +10 -0
  15. data/spec/dnif/configuration_spec.rb +41 -0
  16. data/spec/dnif/dnif_spec.rb +157 -0
  17. data/spec/dnif/document_spec.rb +46 -0
  18. data/spec/dnif/index_spec.rb +20 -0
  19. data/spec/dnif/indexer_spec.rb +64 -0
  20. data/spec/dnif/multi_attribute_spec.rb +20 -0
  21. data/{test/unit/test_schema.rb → spec/dnif/schema_spec.rb} +5 -5
  22. data/spec/dnif/search_spec.rb +18 -0
  23. data/{test → spec}/fixtures/db/schema.rb +1 -0
  24. data/{test → spec}/fixtures/log/searchd.pid +0 -0
  25. data/{test → spec}/fixtures/models.rb +0 -0
  26. data/{test → spec}/fixtures/sphinx_1.xml +1 -0
  27. data/{test → spec}/fixtures/sphinx_2.xml +1 -0
  28. data/{test → spec}/fixtures/sphinx_3.xml +1 -0
  29. data/{test → spec}/fixtures/sphinx_4.xml +1 -0
  30. data/{test → spec}/fixtures/sphinx_5.xml +1 -0
  31. data/{test → spec}/fixtures/templates/config.erb +0 -0
  32. data/spec/spec_helper.rb +31 -0
  33. data/{test/test_helper.rb → spec/support/activerecord/models.rb} +2 -21
  34. data/templates/config.erb +38 -0
  35. metadata +158 -46
  36. data/lib/dnif/index_builder.rb +0 -30
  37. data/test/unit/test_configuration.rb +0 -37
  38. data/test/unit/test_dnif.rb +0 -21
  39. data/test/unit/test_document.rb +0 -41
  40. data/test/unit/test_index.rb +0 -21
  41. data/test/unit/test_index_builder.rb +0 -33
  42. data/test/unit/test_indexer.rb +0 -60
  43. data/test/unit/test_multi_attribute.rb +0 -17
  44. data/test/unit/test_search.rb +0 -116
@@ -0,0 +1,20 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Dnif::MultiAttribute do
5
+
6
+ it ".encode" do
7
+ Dnif::MultiAttribute.encode("Dnif").should == "324,622,873,1126"
8
+ end
9
+
10
+ describe ".decode" do
11
+
12
+ it "should decode a string" do
13
+ Dnif::MultiAttribute.decode("324,622,873,1126").should == "Dnif"
14
+ end
15
+
16
+ it "should decode an array" do
17
+ Dnif::MultiAttribute.decode(["324", "622", "873", "1126"]).should == "Dnif"
18
+ end
19
+ end
20
+ end
@@ -1,11 +1,11 @@
1
1
  # encoding: utf-8
2
- require 'test_helper'
2
+ require 'spec_helper'
3
3
 
4
- class TestSchema < Test::Unit::TestCase
4
+ describe Dnif::Schema do
5
5
 
6
- test ".generate" do
6
+ it ".generate" do
7
7
  schema = Dnif::Schema.new(User)
8
8
  expected = File.read(File.dirname(__FILE__) + "/../fixtures/sphinx_4.xml")
9
- assert_equal expected, schema.generate
9
+ schema.generate.should == expected
10
10
  end
11
- end
11
+ end
@@ -0,0 +1,18 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Dnif::Search do
5
+
6
+ describe "#search" do
7
+
8
+ it "should search specific class" do
9
+ klass = Class.new
10
+ klass.extend(Dnif::Search)
11
+ klass.should_receive(:name).and_return("ClassName")
12
+
13
+ Dnif.should_receive(:search).with("foo", :classes => "ClassName").and_return("results")
14
+
15
+ klass.search("foo").should == "results"
16
+ end
17
+ end
18
+ end
@@ -7,6 +7,7 @@ ActiveRecord::Schema.define(:version => 1) do
7
7
  create_table "users", :force => true do |t|
8
8
  t.string :name
9
9
  t.boolean :active
10
+ t.decimal :weight, :precision => 16, :scale => 2
10
11
  end
11
12
 
12
13
  create_table "people", :force => true do |t|
File without changes
File without changes
@@ -8,6 +8,7 @@
8
8
  <sphinx:attr name="class_id" type="int"/>
9
9
  <sphinx:attr name="class_name" type="multi"/>
10
10
  <sphinx:attr name="active" type="bool"/>
11
+ <sphinx:attr name="weight" type="float"/>
11
12
  <sphinx:attr name="clicked" type="int"/>
12
13
  <sphinx:attr name="published_at" type="timestamp"/>
13
14
  <sphinx:attr name="expire_at" type="timestamp"/>
@@ -8,6 +8,7 @@
8
8
  <class_id>3</class_id>
9
9
  <class_name>334,623,884,1125</class_name>
10
10
  <active>true</active>
11
+ <weight></weight>
11
12
  <clicked>10</clicked>
12
13
  <published_at>{now}</published_at>
13
14
  <expire_at>{expire}</expire_at>
@@ -8,6 +8,7 @@
8
8
  <class_id>1</class_id>
9
9
  <class_name>336,613,882,1139,1391,1646</class_name>
10
10
  <active></active>
11
+ <weight></weight>
11
12
  <clicked></clicked>
12
13
  <published_at></published_at>
13
14
  <expire_at></expire_at>
@@ -6,6 +6,7 @@
6
6
  <sphinx:attr name="class_id" type="int"/>
7
7
  <sphinx:attr name="class_name" type="multi"/>
8
8
  <sphinx:attr name="active" type="bool"/>
9
+ <sphinx:attr name="weight" type="float"/>
9
10
  <sphinx:attr name="clicked" type="int"/>
10
11
  <sphinx:attr name="published_at" type="timestamp"/>
11
12
  <sphinx:attr name="expire_at" type="timestamp"/>
@@ -8,6 +8,7 @@
8
8
  <class_id>0</class_id>
9
9
  <class_name>1,2,3,4</class_name>
10
10
  <active>true</active>
11
+ <weight>34.5</weight>
11
12
  <clicked></clicked>
12
13
  <published_at></published_at>
13
14
  <expire_at></expire_at>
@@ -0,0 +1,31 @@
1
+ # encoding: utf-8
2
+ require "bundler"
3
+ Bundler.require(:default, :development)
4
+
5
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
6
+ require "dnif"
7
+
8
+ # Requires supporting files with custom matchers and macros, etc,
9
+ # in ./support/ and its subdirectories.
10
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f }
11
+
12
+ RSpec.configure do |config|
13
+ config.mock_with :rspec
14
+
15
+ config.before(:suite) do
16
+ Dnif.root_path = File.expand_path(File.dirname(__FILE__) + "/fixtures")
17
+
18
+ ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
19
+ silence_stream(STDOUT) { load "fixtures/db/schema.rb" }
20
+
21
+ DatabaseCleaner.strategy = :transaction
22
+ end
23
+
24
+ config.before(:each) do
25
+ DatabaseCleaner.start
26
+ end
27
+
28
+ config.after(:each) do
29
+ DatabaseCleaner.clean
30
+ end
31
+ end
@@ -1,23 +1,3 @@
1
- # encoding: utf-8
2
-
3
- # $:.unshift(File.dirname(__FILE__) + "/../../lib/")
4
-
5
- require "test/unit"
6
- require "mocha"
7
- require "active_record"
8
- require "ap"
9
-
10
- require 'database_cleaner'
11
- DatabaseCleaner.strategy = :transaction
12
-
13
- $:.unshift(File.dirname(__FILE__) + '/../lib')
14
- require "dnif"
15
-
16
- Dnif.root_path = File.expand_path(File.dirname(__FILE__) + "/fixtures")
17
-
18
- ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
19
- silence_stream(STDOUT) { load "fixtures/db/schema.rb" }
20
-
21
1
  class Post
22
2
 
23
3
  extend Dnif::Search
@@ -33,6 +13,7 @@ class User < ActiveRecord::Base
33
13
  define_index do
34
14
  field :name
35
15
  attribute :active, :type => :boolean
16
+ attribute :weight, :type => :decimal
36
17
  end
37
18
  end
38
19
 
@@ -73,4 +54,4 @@ class Note < ActiveRecord::Base
73
54
  attribute :active, :type => :boolean
74
55
  attribute :points, :type => :float
75
56
  end
76
- end
57
+ end
@@ -0,0 +1,38 @@
1
+ # Hand modifications will be overwritten.
2
+ indexer {
3
+ mem_limit = 512M
4
+ }
5
+
6
+ searchd {
7
+ listen = 127.0.0.1:3313
8
+ seamless_rotate = 1
9
+ log = <%= Dnif.root_path %>/log/searchd.<%= Dnif.environment %>.log
10
+ query_log = <%= Dnif.root_path %>/log/query.<%= Dnif.environment %>.log
11
+ read_timeout = 5
12
+ max_children = 300
13
+ pid_file = <%= Dnif.root_path %>/log/searchd.<%= Dnif.environment %>.pid
14
+ max_matches = 1000
15
+ }
16
+
17
+ <% sources do |name, model| %>
18
+ source <%= name %>
19
+ {
20
+ type = xmlpipe2
21
+ xmlpipe_command = <%= (defined?(Rails) ? "RAILS_ENV" : "RACK_ENV") %>=<%= Dnif.environment %> MODEL=<%= model %> rake dnif:xml --silent
22
+ }
23
+ <% end %>
24
+
25
+ index main
26
+ {
27
+ <% sources do |name| %>
28
+ source = <%= name %>
29
+ <% end %>
30
+ path = <%= Dnif.root_path %>/db/sphinx/<%= Dnif.environment %>/index_main
31
+ docinfo = extern
32
+ morphology = none
33
+ min_word_len = 1
34
+ html_strip = 0
35
+ html_index_attrs =
36
+ charset_type = utf-8
37
+ charset_table = 0..9, A..Z->a..z, -, _, ., &, a..z, U+410..U+42F->U+430..U+44F, U+430..U+44F,U+C5->U+E5, U+E5, U+C4->U+E4, U+E4, U+D6->U+F6, U+F6, U+16B, U+0c1->a, U+0c4->a, U+0c9->e, U+0cd->i, U+0d3->o, U+0d4->o, U+0da->u, U+0dd->y, U+0e1->a, U+0e4->a, U+0e9->e, U+0ed->i, U+0f3->o, U+0f4->o, U+0fa->u, U+0fd->y, U+104->U+105, U+105, U+106->U+107, U+10c->c, U+10d->c, U+10e->d, U+10f->d, U+116->U+117, U+117, U+118->U+119, U+11a->e, U+11b->e, U+12E->U+12F, U+12F, U+139->l, U+13a->l, U+13d->l, U+13e->l, U+141->U+142, U+142, U+143->U+144, U+144,U+147->n, U+148->n, U+154->r, U+155->r, U+158->r, U+159->r, U+15A->U+15B, U+15B, U+160->s, U+160->U+161, U+161->s, U+164->t, U+165->t, U+16A->U+16B, U+16B, U+16e->u, U+16f->u, U+172->U+173, U+173, U+179->U+17A, U+17A, U+17B->U+17C, U+17C, U+17d->z, U+17e->z,
38
+ }
metadata CHANGED
@@ -7,8 +7,8 @@ version: !ruby/object:Gem::Version
7
7
  - 0
8
8
  - 1
9
9
  - beta
10
- - 3
11
- version: 0.0.1.beta.3
10
+ - 4
11
+ version: 0.0.1.beta.4
12
12
  platform: ruby
13
13
  authors:
14
14
  - Rafael Souza
@@ -16,12 +16,11 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-07-15 00:00:00 -03:00
19
+ date: 2010-09-07 00:00:00 -03:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
- name: activerecord
24
- prerelease: false
23
+ name: rake
25
24
  requirement: &id001 !ruby/object:Gem::Requirement
26
25
  none: false
27
26
  requirements:
@@ -31,33 +30,140 @@ dependencies:
31
30
  - 0
32
31
  version: "0"
33
32
  type: :runtime
33
+ prerelease: false
34
34
  version_requirements: *id001
35
35
  - !ruby/object:Gem::Dependency
36
- name: activesupport
37
- prerelease: false
36
+ name: activerecord
38
37
  requirement: &id002 !ruby/object:Gem::Requirement
39
38
  none: false
40
39
  requirements:
41
40
  - - ">="
42
41
  - !ruby/object:Gem::Version
43
42
  segments:
43
+ - 3
44
44
  - 0
45
- version: "0"
45
+ - 0
46
+ version: 3.0.0
46
47
  type: :runtime
48
+ prerelease: false
47
49
  version_requirements: *id002
48
50
  - !ruby/object:Gem::Dependency
49
- name: riddle
50
- prerelease: false
51
+ name: activesupport
51
52
  requirement: &id003 !ruby/object:Gem::Requirement
52
53
  none: false
53
54
  requirements:
54
55
  - - ">="
55
56
  - !ruby/object:Gem::Version
56
57
  segments:
58
+ - 3
57
59
  - 0
58
- version: "0"
60
+ - 0
61
+ version: 3.0.0
59
62
  type: :runtime
63
+ prerelease: false
60
64
  version_requirements: *id003
65
+ - !ruby/object:Gem::Dependency
66
+ name: riddle
67
+ requirement: &id004 !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ segments:
73
+ - 1
74
+ - 1
75
+ - 0
76
+ version: 1.1.0
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: *id004
80
+ - !ruby/object:Gem::Dependency
81
+ name: builder
82
+ requirement: &id005 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ segments:
88
+ - 2
89
+ - 1
90
+ - 2
91
+ version: 2.1.2
92
+ type: :runtime
93
+ prerelease: false
94
+ version_requirements: *id005
95
+ - !ruby/object:Gem::Dependency
96
+ name: jeweler
97
+ requirement: &id006 !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ segments:
103
+ - 1
104
+ - 5
105
+ - 0
106
+ - pre2
107
+ version: 1.5.0.pre2
108
+ type: :development
109
+ prerelease: false
110
+ version_requirements: *id006
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec
113
+ requirement: &id007 !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ segments:
119
+ - 2
120
+ - 0
121
+ - 0
122
+ - beta
123
+ - 20
124
+ version: 2.0.0.beta.20
125
+ type: :development
126
+ prerelease: false
127
+ version_requirements: *id007
128
+ - !ruby/object:Gem::Dependency
129
+ name: database_cleaner
130
+ requirement: &id008 !ruby/object:Gem::Requirement
131
+ none: false
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ segments:
136
+ - 0
137
+ version: "0"
138
+ type: :development
139
+ prerelease: false
140
+ version_requirements: *id008
141
+ - !ruby/object:Gem::Dependency
142
+ name: awesome_print
143
+ requirement: &id009 !ruby/object:Gem::Requirement
144
+ none: false
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ segments:
149
+ - 0
150
+ version: "0"
151
+ type: :development
152
+ prerelease: false
153
+ version_requirements: *id009
154
+ - !ruby/object:Gem::Dependency
155
+ name: sqlite3-ruby
156
+ requirement: &id010 !ruby/object:Gem::Requirement
157
+ none: false
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ segments:
162
+ - 0
163
+ version: "0"
164
+ type: :development
165
+ prerelease: false
166
+ version_requirements: *id010
61
167
  description: dnif is a gem to index data using ActiveRecord finders, letting you index your custom methods and not only your table fields
62
168
  email: me@rafaelss.com
63
169
  executables: []
@@ -67,6 +173,10 @@ extensions: []
67
173
  extra_rdoc_files:
68
174
  - README.rdoc
69
175
  files:
176
+ - .gitignore
177
+ - .rspec
178
+ - Gemfile
179
+ - Gemfile.lock
70
180
  - README.rdoc
71
181
  - Rakefile
72
182
  - dnif.gemspec
@@ -74,38 +184,39 @@ files:
74
184
  - lib/dnif/configuration.rb
75
185
  - lib/dnif/document.rb
76
186
  - lib/dnif/index.rb
77
- - lib/dnif/index_builder.rb
78
187
  - lib/dnif/indexer.rb
79
188
  - lib/dnif/multi_attribute.rb
80
189
  - lib/dnif/schema.rb
81
190
  - lib/dnif/search.rb
82
191
  - lib/dnif/tasks.rb
83
- - test/fixtures/db/schema.rb
84
- - test/fixtures/log/searchd.pid
85
- - test/fixtures/models.rb
86
- - test/fixtures/sphinx_1.xml
87
- - test/fixtures/sphinx_2.xml
88
- - test/fixtures/sphinx_3.xml
89
- - test/fixtures/sphinx_4.xml
90
- - test/fixtures/sphinx_5.xml
91
- - test/fixtures/templates/config.erb
92
- - test/test_helper.rb
93
- - test/unit/test_configuration.rb
94
- - test/unit/test_dnif.rb
95
- - test/unit/test_document.rb
96
- - test/unit/test_index.rb
97
- - test/unit/test_index_builder.rb
98
- - test/unit/test_indexer.rb
99
- - test/unit/test_multi_attribute.rb
100
- - test/unit/test_schema.rb
101
- - test/unit/test_search.rb
102
- has_rdoc: true
192
+ - lib/dnif/version.rb
193
+ - spec/dnif/configuration_spec.rb
194
+ - spec/dnif/dnif_spec.rb
195
+ - spec/dnif/document_spec.rb
196
+ - spec/dnif/index_spec.rb
197
+ - spec/dnif/indexer_spec.rb
198
+ - spec/dnif/multi_attribute_spec.rb
199
+ - spec/dnif/schema_spec.rb
200
+ - spec/dnif/search_spec.rb
201
+ - spec/fixtures/db/schema.rb
202
+ - spec/fixtures/log/searchd.pid
203
+ - spec/fixtures/models.rb
204
+ - spec/fixtures/sphinx_1.xml
205
+ - spec/fixtures/sphinx_2.xml
206
+ - spec/fixtures/sphinx_3.xml
207
+ - spec/fixtures/sphinx_4.xml
208
+ - spec/fixtures/sphinx_5.xml
209
+ - spec/fixtures/templates/config.erb
210
+ - spec/spec_helper.rb
211
+ - spec/support/activerecord/models.rb
212
+ - templates/config.erb
213
+ has_rdoc: false
103
214
  homepage: http://github.com/rafaelss/dnif
104
215
  licenses: []
105
216
 
106
217
  post_install_message:
107
- rdoc_options:
108
- - --charset=UTF-8
218
+ rdoc_options: []
219
+
109
220
  require_paths:
110
221
  - lib
111
222
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -113,6 +224,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
113
224
  requirements:
114
225
  - - ">="
115
226
  - !ruby/object:Gem::Version
227
+ hash: 3446720878037895666
116
228
  segments:
117
229
  - 0
118
230
  version: "0"
@@ -134,15 +246,15 @@ signing_key:
134
246
  specification_version: 3
135
247
  summary: dnif is the new find... for sphinx
136
248
  test_files:
137
- - test/fixtures/db/schema.rb
138
- - test/fixtures/models.rb
139
- - test/test_helper.rb
140
- - test/unit/test_configuration.rb
141
- - test/unit/test_dnif.rb
142
- - test/unit/test_document.rb
143
- - test/unit/test_index.rb
144
- - test/unit/test_index_builder.rb
145
- - test/unit/test_indexer.rb
146
- - test/unit/test_multi_attribute.rb
147
- - test/unit/test_schema.rb
148
- - test/unit/test_search.rb
249
+ - spec/dnif/configuration_spec.rb
250
+ - spec/dnif/dnif_spec.rb
251
+ - spec/dnif/document_spec.rb
252
+ - spec/dnif/index_spec.rb
253
+ - spec/dnif/indexer_spec.rb
254
+ - spec/dnif/multi_attribute_spec.rb
255
+ - spec/dnif/schema_spec.rb
256
+ - spec/dnif/search_spec.rb
257
+ - spec/fixtures/db/schema.rb
258
+ - spec/fixtures/models.rb
259
+ - spec/spec_helper.rb
260
+ - spec/support/activerecord/models.rb