bdimcheff-dm-sphinx-adapter 0.8.0

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.
@@ -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
@@ -0,0 +1,30 @@
1
+ require File.join(File.dirname(__FILE__), 'helper')
2
+
3
+ class TestIndex < Test::Unit::TestCase
4
+ context 'DM::A::Sphinx::Index instance' do
5
+ should 'respond to delta?'
6
+ end
7
+
8
+ context 'DM::A::Sphinx::Resource class' do
9
+ setup do
10
+ class ::Resource
11
+ include DataMapper::SphinxResource
12
+ end
13
+ end
14
+
15
+ context '#index method' do
16
+ should 'append an index' do
17
+ assert_nothing_raised do
18
+ Resource.class_eval do
19
+ index :name
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ context '#sphinx_indexes method' do
26
+ should 'return DM::A::Sphinx::Index objects'
27
+ should 'return delta indexes at the end of the list'
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,61 @@
1
+ require File.join(File.dirname(__FILE__), 'helper')
2
+
3
+ class TestQuery < Test::Unit::TestCase
4
+ context 'DM::A::Sphinx::Query conditions' do
5
+ setup do
6
+ load File.join(File.dirname(__FILE__), 'files', 'model.rb')
7
+ @adapter = repository(:search)
8
+ @resource = Item
9
+ end
10
+
11
+ should 'treat nil operator as extended field match' do
12
+ assert_equal '@t_string "foo"', query_string(:t_string => 'foo')
13
+ end
14
+
15
+ should 'treat .eql operator as extended field match' do
16
+ assert_equal '@t_string "foo"', query_string(:t_string.eql => 'foo')
17
+ end
18
+
19
+ should 'treat .like operator as extended field match' do
20
+ assert_equal '@t_string "foo"', query_string(:t_string.like => 'foo')
21
+ end
22
+
23
+ should 'treat Array as extended field AND match' do
24
+ assert_equal '@t_string "foo bar"', query_string(:t_string => %w{foo bar})
25
+ end
26
+
27
+ should 'treat .not opeartor as extended field NOT match' do
28
+ assert_equal '@t_string -"foo"', query_string(:t_string.not => 'foo')
29
+ end
30
+
31
+ should 'treat Array .not operator as extended field NOT match' do
32
+ assert_equal '@t_string -"foo bar"', query_string(:t_string.not => %w{foo bar})
33
+ end
34
+
35
+ should 'treat .in operator as extended OR match' do
36
+ assert_equal '@t_string ("foo" | "bar")', query_string(:t_string.in => %w{foo bar})
37
+ end
38
+
39
+ should 'treat multiple .eql operators as AND search' do
40
+ # When is DM going to switch conditions to an array? :(
41
+ assert(/(?:@t_string "b" )?@t_string "a"(?: @t_string "b")?/.match(
42
+ query_string(:t_string.eql => 'a', :t_string.eql => 'b')
43
+ ))
44
+ end
45
+
46
+ should 'leave raw conditions as they are' do
47
+ assert_equal '"foo bar"~10', query_string(:conditions => ['"foo bar"~10'])
48
+ end
49
+ end
50
+
51
+ protected
52
+ def query(conditions = {})
53
+ DataMapper::Adapters::Sphinx::Query.new(
54
+ DataMapper::Query.new(@adapter, @resource, conditions)
55
+ )
56
+ end
57
+
58
+ def query_string(conditions = {})
59
+ query(conditions).to_s
60
+ end
61
+ end
@@ -0,0 +1,17 @@
1
+ require File.join(File.dirname(__FILE__), 'helper')
2
+
3
+ class TestResource < Test::Unit::TestCase
4
+ context 'DM::A::Sphinx::Resource module' do
5
+ setup do
6
+ class ::Resource
7
+ include DataMapper::SphinxResource
8
+ end
9
+ end
10
+
11
+ [:index, :sphinx_indexes, :attribute, :sphinx_attributes].each do |method|
12
+ should "respond to #{method}" do
13
+ assert_respond_to Resource, method
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,77 @@
1
+ require File.join(File.dirname(__FILE__), 'helper')
2
+ require 'dm-sphinx-adapter/xmlpipe2'
3
+
4
+ class TestResource < Test::Unit::TestCase
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
+
13
+ setup do
14
+ load File.join(File.dirname(__FILE__), 'files', 'model.rb')
15
+ end
16
+
17
+ should 'respond to #xmlpipe2' do
18
+ assert_respond_to Item, :xmlpipe2
19
+ end
20
+
21
+ context '#xmlpipe2' do
22
+ setup do
23
+ $stdout = StringIO.new
24
+ Item.create(
25
+ :id => 1,
26
+ :t_string => 'one',
27
+ :t_text => "text one!",
28
+ :t_decimal => BigDecimal.new('0.01'),
29
+ :t_float => 0.0001,
30
+ :t_integer => 1,
31
+ :t_datetime => Time.at(1235914716)
32
+ )
33
+ Item.xmlpipe2(:default, :search)
34
+ @xml = $stdout.rewind && $stdout.read
35
+ @doc = Nokogiri::XML.parse(@xml) rescue nil
36
+ @ns = {'s' => 'sphinx'}
37
+ $stdout = STDOUT
38
+ end
39
+
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
73
+ end
74
+ end
75
+ end
76
+ end
77
+
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bdimcheff-dm-sphinx-adapter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.8.0
5
+ platform: ruby
6
+ authors:
7
+ - Shane Hanna
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-05-10 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: dm-core
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: "0.9"
24
+ version:
25
+ description:
26
+ email: shane.hanna@gmail.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - README.rdoc
33
+ files:
34
+ - README.rdoc
35
+ - Rakefile
36
+ - VERSION.yml
37
+ - lib/dm-sphinx-adapter.rb
38
+ - lib/dm-sphinx-adapter/adapter.rb
39
+ - lib/dm-sphinx-adapter/attribute.rb
40
+ - lib/dm-sphinx-adapter/collection.rb
41
+ - lib/dm-sphinx-adapter/index.rb
42
+ - lib/dm-sphinx-adapter/query.rb
43
+ - lib/dm-sphinx-adapter/resource.rb
44
+ - lib/dm-sphinx-adapter/xmlpipe2.rb
45
+ - lib/riddle.rb
46
+ - lib/riddle/client.rb
47
+ - lib/riddle/client/filter.rb
48
+ - lib/riddle/client/message.rb
49
+ - lib/riddle/client/response.rb
50
+ - test/files/model.rb
51
+ - test/files/source.xml
52
+ - test/files/sphinx.conf
53
+ - test/files/test_xmlpipe2.xml
54
+ - test/helper.rb
55
+ - test/test_adapter.rb
56
+ - test/test_attribute.rb
57
+ - test/test_collection.rb
58
+ - test/test_index.rb
59
+ - test/test_query.rb
60
+ - test/test_resource.rb
61
+ - test/test_xmlpipe2.rb
62
+ has_rdoc: true
63
+ homepage: http://github.com/shanna/dm-sphinx-adapter
64
+ post_install_message:
65
+ rdoc_options:
66
+ - --charset=UTF-8
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: "0"
74
+ version:
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: "0"
80
+ version:
81
+ requirements: []
82
+
83
+ rubyforge_project:
84
+ rubygems_version: 1.2.0
85
+ signing_key:
86
+ specification_version: 2
87
+ summary: A DataMapper Sphinx adapter.
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