shanna-dm-sphinx-adapter 0.7.1 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +49 -0
- data/VERSION.yml +2 -2
- data/lib/dm-sphinx-adapter.rb +1 -0
- data/lib/dm-sphinx-adapter/adapter.rb +3 -1
- data/lib/dm-sphinx-adapter/collection.rb +19 -0
- data/lib/dm-sphinx-adapter/xmlpipe2.rb +2 -2
- data/test/helper.rb +1 -1
- data/test/test_collection.rb +26 -0
- data/test/test_xmlpipe2.rb +45 -7
- metadata +18 -35
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "dm-sphinx-adapter"
|
8
|
+
gem.summary = %q{A DataMapper Sphinx adapter.}
|
9
|
+
gem.email = "shane.hanna@gmail.com"
|
10
|
+
gem.homepage = "http://github.com/shanna/dm-sphinx-adapter"
|
11
|
+
gem.authors = ["Shane Hanna"]
|
12
|
+
gem.add_dependency 'dm-core', ['~> 0.9']
|
13
|
+
gem.files.reject!{|f| f=~ %r{test/files/tmp/.*}}
|
14
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
+
end
|
16
|
+
rescue LoadError
|
17
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
18
|
+
end
|
19
|
+
|
20
|
+
require 'rake/rdoctask'
|
21
|
+
Rake::RDocTask.new do |rdoc|
|
22
|
+
rdoc.rdoc_dir = 'rdoc'
|
23
|
+
rdoc.title = 'dm-sphinx-adapter'
|
24
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
25
|
+
rdoc.rdoc_files.include('README*')
|
26
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
27
|
+
end
|
28
|
+
|
29
|
+
require 'rake/testtask'
|
30
|
+
Rake::TestTask.new(:test) do |test|
|
31
|
+
test.libs << 'lib' << 'test'
|
32
|
+
test.pattern = 'test/**/test_*.rb'
|
33
|
+
test.verbose = true
|
34
|
+
end
|
35
|
+
|
36
|
+
begin
|
37
|
+
require 'rcov/rcovtask'
|
38
|
+
Rcov::RcovTask.new do |test|
|
39
|
+
test.libs << 'test'
|
40
|
+
test.pattern = 'test/**/test_*.rb'
|
41
|
+
test.verbose = true
|
42
|
+
end
|
43
|
+
rescue LoadError
|
44
|
+
task :rcov do
|
45
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
task :default => :test
|
data/VERSION.yml
CHANGED
data/lib/dm-sphinx-adapter.rb
CHANGED
@@ -140,7 +140,9 @@ module DataMapper
|
|
140
140
|
DataMapper.logger.info(
|
141
141
|
%q{Sphinx (%.3f): search '%s' in '%s' found %d documents} % [result[:time], search, from, result[:total]]
|
142
142
|
)
|
143
|
-
|
143
|
+
# TODO: Confusing, call it something other than collection?
|
144
|
+
Collection.new(result)
|
145
|
+
# result[:matches].map{|doc| doc[:id] = doc[:doc]; doc}
|
144
146
|
end
|
145
147
|
|
146
148
|
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module DataMapper
|
2
|
+
module Adapters
|
3
|
+
module Sphinx
|
4
|
+
class Collection < Array
|
5
|
+
attr_accessor :error, :time, :total, :words
|
6
|
+
|
7
|
+
def initialize(result)
|
8
|
+
# TODO: One liner that works in Ruby 1.x now #indexes is #keys?
|
9
|
+
@error = result[:error]
|
10
|
+
@time = result[:time]
|
11
|
+
@total = result[:total]
|
12
|
+
@words = result[:words]
|
13
|
+
super result[:matches].map{|doc| doc[:id] = doc[:doc]; doc}
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end # Sphinx
|
18
|
+
end # Adapters
|
19
|
+
end # DataMapper
|
data/test/helper.rb
CHANGED
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'helper')
|
2
|
+
|
3
|
+
class TestAdapter < Test::Unit::TestCase
|
4
|
+
context 'DM::A::Sphinx::Collection instance' do
|
5
|
+
setup do
|
6
|
+
load File.join(File.dirname(__FILE__), 'files', 'model.rb')
|
7
|
+
@it = repository(:search)
|
8
|
+
@resource = Item
|
9
|
+
end
|
10
|
+
|
11
|
+
should 'have total' do
|
12
|
+
assert_equal 3, @it.read_many(query).total
|
13
|
+
assert_equal 1, @it.read_many(query(:t_string => 'two')).total
|
14
|
+
end
|
15
|
+
|
16
|
+
should 'have words' do
|
17
|
+
words = {'two' => {:docs => 1, :hits => 2}}
|
18
|
+
assert_equal words, @it.read_many(query(:t_string => 'two')).words
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
protected
|
23
|
+
def query(conditions = {})
|
24
|
+
DataMapper::Query.new(repository(:search), @resource, conditions)
|
25
|
+
end
|
26
|
+
end
|
data/test/test_xmlpipe2.rb
CHANGED
@@ -3,6 +3,13 @@ require 'dm-sphinx-adapter/xmlpipe2'
|
|
3
3
|
|
4
4
|
class TestResource < Test::Unit::TestCase
|
5
5
|
context 'DM::A::Sphinx::Resource module' do
|
6
|
+
begin
|
7
|
+
require 'nokogiri'
|
8
|
+
rescue LoadError
|
9
|
+
warn ' * WARNING: Nokogiri not found, skipping xmlpipe2 tests.'
|
10
|
+
return nil
|
11
|
+
end
|
12
|
+
|
6
13
|
setup do
|
7
14
|
load File.join(File.dirname(__FILE__), 'files', 'model.rb')
|
8
15
|
end
|
@@ -12,7 +19,7 @@ class TestResource < Test::Unit::TestCase
|
|
12
19
|
end
|
13
20
|
|
14
21
|
context '#xmlpipe2' do
|
15
|
-
|
22
|
+
setup do
|
16
23
|
$stdout = StringIO.new
|
17
24
|
Item.create(
|
18
25
|
:id => 1,
|
@@ -24,14 +31,45 @@ class TestResource < Test::Unit::TestCase
|
|
24
31
|
:t_datetime => Time.at(1235914716)
|
25
32
|
)
|
26
33
|
Item.xmlpipe2(:default, :search)
|
27
|
-
xml = $stdout.rewind && $stdout.read
|
34
|
+
@xml = $stdout.rewind && $stdout.read
|
35
|
+
@doc = Nokogiri::XML.parse(@xml) rescue nil
|
36
|
+
@ns = {'s' => 'sphinx'}
|
28
37
|
$stdout = STDOUT
|
38
|
+
end
|
29
39
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
40
|
+
should 'stream xml to stdout' do
|
41
|
+
assert_not_nil @xml
|
42
|
+
assert_not_nil @doc
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'schema' do
|
46
|
+
should 'have id field' do
|
47
|
+
assert_not_nil @doc.xpath(%q{//s:field[@name='id']}, @ns).first
|
48
|
+
end
|
49
|
+
|
50
|
+
should 'have t_string field' do
|
51
|
+
assert_not_nil @doc.xpath(%q{//s:field[@name='t_string']}, @ns).first
|
52
|
+
end
|
53
|
+
|
54
|
+
should 'have text attribute' do
|
55
|
+
assert_not_nil @doc.xpath(%q{//s:attr[@name='t_text' and @type='str2ordinal']}, @ns).first
|
56
|
+
end
|
57
|
+
|
58
|
+
should 'have decimal attribute' do
|
59
|
+
assert_not_nil @doc.xpath(%q{//s:attr[@name='t_decimal' and @type='float']}, @ns).first
|
60
|
+
end
|
61
|
+
|
62
|
+
should 'have float attribute' do
|
63
|
+
assert_not_nil @doc.xpath(%q{//s:attr[@name='t_float' and @type='float']}, @ns).first
|
64
|
+
end
|
65
|
+
|
66
|
+
should 'have int attribute' do
|
67
|
+
assert_not_nil @doc.xpath(%q{//s:attr[@name='t_integer' and @type='int']}, @ns).first
|
68
|
+
end
|
69
|
+
|
70
|
+
should 'have timestamp attribute' do
|
71
|
+
assert_not_nil @doc.xpath(%q{//s:attr[@name='t_datetime' and @type='timestamp']}, @ns).first
|
72
|
+
end
|
35
73
|
end
|
36
74
|
end
|
37
75
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shanna-dm-sphinx-adapter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shane Hanna
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-05-10 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -32,53 +32,29 @@ extra_rdoc_files:
|
|
32
32
|
- README.rdoc
|
33
33
|
files:
|
34
34
|
- README.rdoc
|
35
|
+
- Rakefile
|
35
36
|
- VERSION.yml
|
36
|
-
- lib/dm-sphinx-adapter
|
37
|
+
- lib/dm-sphinx-adapter.rb
|
37
38
|
- lib/dm-sphinx-adapter/adapter.rb
|
38
39
|
- lib/dm-sphinx-adapter/attribute.rb
|
40
|
+
- lib/dm-sphinx-adapter/collection.rb
|
39
41
|
- lib/dm-sphinx-adapter/index.rb
|
40
42
|
- lib/dm-sphinx-adapter/query.rb
|
41
43
|
- lib/dm-sphinx-adapter/resource.rb
|
42
44
|
- lib/dm-sphinx-adapter/xmlpipe2.rb
|
43
|
-
- lib/
|
44
|
-
- lib/riddle
|
45
|
-
- lib/riddle/client
|
45
|
+
- lib/riddle.rb
|
46
|
+
- lib/riddle/client.rb
|
46
47
|
- lib/riddle/client/filter.rb
|
47
48
|
- lib/riddle/client/message.rb
|
48
49
|
- lib/riddle/client/response.rb
|
49
|
-
- lib/riddle/client.rb
|
50
|
-
- lib/riddle.rb
|
51
|
-
- test/files
|
52
50
|
- test/files/model.rb
|
53
51
|
- test/files/source.xml
|
54
52
|
- test/files/sphinx.conf
|
55
53
|
- test/files/test_xmlpipe2.xml
|
56
|
-
- test/files/tmp
|
57
|
-
- test/files/tmp/items.spa
|
58
|
-
- test/files/tmp/items.spd
|
59
|
-
- test/files/tmp/items.sph
|
60
|
-
- test/files/tmp/items.spi
|
61
|
-
- test/files/tmp/items.spl
|
62
|
-
- test/files/tmp/items.spm
|
63
|
-
- test/files/tmp/items.spp
|
64
|
-
- test/files/tmp/items_delta.spa
|
65
|
-
- test/files/tmp/items_delta.spd
|
66
|
-
- test/files/tmp/items_delta.sph
|
67
|
-
- test/files/tmp/items_delta.spi
|
68
|
-
- test/files/tmp/items_delta.spm
|
69
|
-
- test/files/tmp/items_delta.spp
|
70
|
-
- test/files/tmp/items_main.spa
|
71
|
-
- test/files/tmp/items_main.spd
|
72
|
-
- test/files/tmp/items_main.sph
|
73
|
-
- test/files/tmp/items_main.spi
|
74
|
-
- test/files/tmp/items_main.spm
|
75
|
-
- test/files/tmp/items_main.spp
|
76
|
-
- test/files/tmp/sphinx.log
|
77
|
-
- test/files/tmp/sphinx.pid
|
78
|
-
- test/files/tmp/sphinx.query.log
|
79
54
|
- test/helper.rb
|
80
55
|
- test/test_adapter.rb
|
81
56
|
- test/test_attribute.rb
|
57
|
+
- test/test_collection.rb
|
82
58
|
- test/test_index.rb
|
83
59
|
- test/test_query.rb
|
84
60
|
- test/test_resource.rb
|
@@ -87,7 +63,6 @@ has_rdoc: true
|
|
87
63
|
homepage: http://github.com/shanna/dm-sphinx-adapter
|
88
64
|
post_install_message:
|
89
65
|
rdoc_options:
|
90
|
-
- --inline-source
|
91
66
|
- --charset=UTF-8
|
92
67
|
require_paths:
|
93
68
|
- lib
|
@@ -110,5 +85,13 @@ rubygems_version: 1.2.0
|
|
110
85
|
signing_key:
|
111
86
|
specification_version: 2
|
112
87
|
summary: A DataMapper Sphinx adapter.
|
113
|
-
test_files:
|
114
|
-
|
88
|
+
test_files:
|
89
|
+
- test/files/model.rb
|
90
|
+
- test/helper.rb
|
91
|
+
- test/test_adapter.rb
|
92
|
+
- test/test_attribute.rb
|
93
|
+
- test/test_collection.rb
|
94
|
+
- test/test_index.rb
|
95
|
+
- test/test_query.rb
|
96
|
+
- test/test_resource.rb
|
97
|
+
- test/test_xmlpipe2.rb
|