shanna-dm-sphinx-adapter 0.6 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +10 -0
- data/Rakefile +1 -1
- data/dm-sphinx-adapter.gemspec +3 -3
- data/lib/dm-sphinx-adapter/adapter.rb +8 -6
- data/test/test_adapter.rb +25 -9
- metadata +2 -2
data/History.txt
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
=== 0.6.1 / 2008-12-16
|
2
|
+
|
3
|
+
* The adapter returns the entire Riddle::Client#query response so document :weight and :attributes are usable.
|
4
|
+
* Fixed broken naming convention bug. The AbstractAdapter constructor was not being called.
|
5
|
+
|
6
|
+
=== 0.6 / 2008-12-13
|
7
|
+
|
8
|
+
* Removed managed client and all related libs.
|
9
|
+
* Switched to Shoulda for tests in an effort to clean them up a bit.
|
10
|
+
|
1
11
|
=== 0.5 / 2008-12-01
|
2
12
|
|
3
13
|
* Moved sphinx extended query string generator into a class of its own.
|
data/Rakefile
CHANGED
data/dm-sphinx-adapter.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{dm-sphinx-adapter}
|
5
|
-
s.version = "0.6"
|
5
|
+
s.version = "0.6.1"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Shane Hanna"]
|
9
|
-
s.date = %q{2008-12-
|
9
|
+
s.date = %q{2008-12-16}
|
10
10
|
s.description = %q{A DataMapper Sphinx adapter.}
|
11
11
|
s.email = ["shane.hanna@gmail.com"]
|
12
12
|
s.extra_rdoc_files = ["History.txt", "LICENCE.txt", "Manifest.txt", "README.txt"]
|
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.rdoc_options = ["--main", "README.txt"]
|
17
17
|
s.require_paths = ["lib"]
|
18
18
|
s.rubyforge_project = %q{dm-sphinx-adapter}
|
19
|
-
s.rubygems_version = %q{1.3.
|
19
|
+
s.rubygems_version = %q{1.3.0}
|
20
20
|
s.summary = %q{A DataMapper Sphinx adapter.}
|
21
21
|
s.test_files = ["test/test_adapter.rb", "test/test_attribute.rb", "test/test_index.rb", "test/test_query.rb", "test/test_resource.rb"]
|
22
22
|
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'benchmark'
|
2
|
-
|
3
1
|
module DataMapper
|
4
2
|
module Adapters
|
5
3
|
module Sphinx
|
@@ -38,6 +36,8 @@ module DataMapper
|
|
38
36
|
# uri_or_options<URI, DataObject::URI, Addressable::URI, String, Hash, Pathname>::
|
39
37
|
# DataMapper uri or options hash.
|
40
38
|
def initialize(name, uri_or_options)
|
39
|
+
super # Set up defaults.
|
40
|
+
|
41
41
|
options = normalize_options(uri_or_options)
|
42
42
|
@client = Riddle::Client.new(options.delete(:host), options.delete(:port))
|
43
43
|
options.each{|k, v| @client.method("#{k}=".to_sym).call(v) if @client.respond_to?("#{k}=".to_sym)}
|
@@ -58,11 +58,13 @@ module DataMapper
|
|
58
58
|
# These methods are public but normally called indirectly through DataMapper::Resource#get,
|
59
59
|
# DataMapper::Resource#first or DataMapper::Resource#all.
|
60
60
|
#
|
61
|
+
# The document hashes returned are those from Riddle::Client.
|
62
|
+
#
|
61
63
|
# ==== Parameters
|
62
64
|
# query<DataMapper::Query>:: The query object.
|
63
65
|
#
|
64
66
|
# ==== Returns
|
65
|
-
# Array<Hash>:: An array of document hashes. <tt>[{:id => 1}, {:id => 2}]</tt>
|
67
|
+
# Array<Hash>:: An array of document hashes. <tt>[{:id => 1, ...}, {:id => 2, ...}]</tt>
|
66
68
|
# Array<>:: An empty array if no documents match.
|
67
69
|
def read_many(query)
|
68
70
|
read(query)
|
@@ -79,7 +81,7 @@ module DataMapper
|
|
79
81
|
# query<DataMapper::Query>:: The query object.
|
80
82
|
#
|
81
83
|
# ==== Returns
|
82
|
-
# Hash:: An document hash of the first document matched. <tt>{:id => 1}</tt>
|
84
|
+
# Hash:: An document hash of the first document matched. <tt>{:id => 1, ...}</tt>
|
83
85
|
# Nil:: If no documents match.
|
84
86
|
def read_one(query)
|
85
87
|
read(query).first
|
@@ -113,7 +115,7 @@ module DataMapper
|
|
113
115
|
# query<DataMapper::Query>:: The query object.
|
114
116
|
#
|
115
117
|
# ==== Returns
|
116
|
-
# Array<Hash>:: An array of document hashes. <tt>[{:id => 1}, {:id => 2}]</tt>
|
118
|
+
# Array<Hash>:: An array of document hashes. <tt>[{:id => 1, ...}, {:id => 2, ...}]</tt>
|
117
119
|
# Array<>:: An empty array if no documents match.
|
118
120
|
def read(query)
|
119
121
|
from = indexes(query.model).map{|index| index.name}.join(', ')
|
@@ -136,7 +138,7 @@ module DataMapper
|
|
136
138
|
DataMapper.logger.info(
|
137
139
|
%q{Sphinx (%.3f): search '%s' in '%s' found %d documents} % [result[:time], search, from, result[:total]]
|
138
140
|
)
|
139
|
-
result[:matches].map{|doc|
|
141
|
+
result[:matches].map{|doc| doc[:id] = doc[:doc]; doc}
|
140
142
|
end
|
141
143
|
|
142
144
|
|
data/test/test_adapter.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'helper')
|
2
2
|
|
3
3
|
class TestAdapter < Test::Unit::TestCase
|
4
|
-
context 'DM::A::Sphinx::Adapter
|
4
|
+
context 'DM::A::Sphinx::Adapter' do
|
5
5
|
setup do
|
6
6
|
DataMapper.setup(:adapter, :adapter => 'sphinx')
|
7
7
|
load File.join(File.dirname(__FILE__), 'files', 'model.rb')
|
@@ -9,14 +9,30 @@ class TestAdapter < Test::Unit::TestCase
|
|
9
9
|
@resource = Item
|
10
10
|
end
|
11
11
|
|
12
|
+
context 'class' do
|
13
|
+
should 'use default field naming convention' do
|
14
|
+
assert_equal(
|
15
|
+
DataMapper::NamingConventions::Field::Underscored,
|
16
|
+
@it.adapter.field_naming_convention
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
should 'use default resource naming convention' do
|
21
|
+
assert_equal(
|
22
|
+
DataMapper::NamingConventions::Resource::UnderscoredAndPluralized,
|
23
|
+
@it.adapter.resource_naming_convention
|
24
|
+
)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
12
28
|
context '#create' do
|
13
|
-
should '
|
29
|
+
should 'return zero records created' do
|
14
30
|
assert_equal 0, @it.create(create_resource)
|
15
31
|
end
|
16
32
|
end
|
17
33
|
|
18
34
|
context '#delete' do
|
19
|
-
should '
|
35
|
+
should 'return zero records deleted' do
|
20
36
|
assert_equal 0, @it.delete(create_resource)
|
21
37
|
end
|
22
38
|
end
|
@@ -24,26 +40,26 @@ class TestAdapter < Test::Unit::TestCase
|
|
24
40
|
context '#read_many' do
|
25
41
|
context 'conditions' do
|
26
42
|
should 'return all objects when nil' do
|
27
|
-
assert_equal [
|
43
|
+
assert_equal [1, 2, 3], @it.read_many(query).map{|d| d[:id]}
|
28
44
|
end
|
29
45
|
|
30
46
|
should 'return subset of objects for conditions' do
|
31
|
-
assert_equal [
|
47
|
+
assert_equal [2], @it.read_many(query(:t_string => 'two')).map{|d| d[:id]}
|
32
48
|
end
|
33
49
|
end
|
34
50
|
|
35
51
|
context 'offsets' do
|
36
52
|
should 'be able to offset the objects' do
|
37
|
-
assert_equal [
|
38
|
-
assert_equal [
|
53
|
+
assert_equal [1, 2, 3], @it.read_many(query(:offset => 0)).map{|d| d[:id]}
|
54
|
+
assert_equal [2, 3], @it.read_many(query(:offset => 1)).map{|d| d[:id]}
|
39
55
|
assert_equal [], @it.read_many(query(:offset => 3))
|
40
56
|
end
|
41
57
|
end
|
42
58
|
|
43
59
|
context 'limits' do
|
44
60
|
should 'be able to limit the objects' do
|
45
|
-
assert_equal [
|
46
|
-
assert_equal [
|
61
|
+
assert_equal [1], @it.read_many(query(:limit => 1)).map{|d| d[:id]}
|
62
|
+
assert_equal [1, 2], @it.read_many(query(:limit => 2)).map{|d| d[:id]}
|
47
63
|
end
|
48
64
|
end
|
49
65
|
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:
|
4
|
+
version: 0.6.1
|
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: 2008-12-
|
12
|
+
date: 2008-12-16 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|