outoftime-sunspot 0.7.2 → 0.7.3

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.
data/README.rdoc CHANGED
@@ -10,9 +10,7 @@ features for indexing objects and searching against them.
10
10
  Sunspot is designed to be easily plugged in to any ORM, or even non-database-backed
11
11
  objects such as the filesystem.
12
12
 
13
- Sunspot is currently under active development and is not feature-complete.
14
-
15
- === Sunspot already has these features:
13
+ === Features:
16
14
 
17
15
  * Define indexing strategy for each searchable class using intuitive block-based API
18
16
  * Clean separation between keyword-searchable fields and fields for scoping/ordering
@@ -24,13 +22,6 @@ Sunspot is currently under active development and is not feature-complete.
24
22
  * Full compatibility with will_paginate
25
23
  * Ordering
26
24
 
27
- === Sunspot will have these features:
28
-
29
- * Adapters for DataMapper, ActiveRecord, and File objects
30
- * High-power integration with ORM features for maximum efficiency (e.g., specify AR :include argument for eager loading associations when hydrating search results)
31
- * Define association facets, which return model objects as row values
32
- * Plugins for drop-in integration with Merb and Rails
33
-
34
25
  == Installation
35
26
 
36
27
  gem sources -a http://gems.github.com
@@ -47,6 +38,11 @@ You can change the URL at which Sunspot accesses Solr with:
47
38
 
48
39
  Sunspot.config.solr.url = 'http://solr.my.host:9818/solr'
49
40
 
41
+ == Rails Integration
42
+
43
+ The {Sunspot::Rails}[http://github.com/outoftime/sunspot_rails] plugin makes
44
+ integrating Sunspot into Rails drop-in easy.
45
+
50
46
  == Using Sunspot
51
47
 
52
48
  === Define an index:
@@ -109,15 +105,24 @@ me so I can rectify the situation!
109
105
  1. solr-ruby
110
106
  2. Java
111
107
 
108
+ == Bugs
109
+
110
+ Please submit bug reports to
111
+ http://outoftime.lighthouseapp.com/projects/20339-sunspot
112
+
112
113
  == Further Reading
113
114
 
114
115
  Posts about Sunspot from my tumblog: http://outofti.me/tagged/sunspot
115
116
 
117
+ == Contributors
118
+
119
+ Mat Brown <mat@patch.com>
120
+
116
121
  == LICENSE:
117
122
 
118
123
  (The MIT License)
119
124
 
120
- Copyright (c) 2008 Mat Brown
125
+ Copyright (c) 2008-2009 Mat Brown
121
126
 
122
127
  Permission is hereby granted, free of charge, to any person obtaining
123
128
  a copy of this software and associated documentation files (the
data/TODO CHANGED
@@ -1,4 +1,5 @@
1
1
  === 0.8 ===
2
+ * Expose Query as part of public API
2
3
  * Facet by type
3
4
  * Dynamic fields
4
5
  * ActiveRecord, DataMapper, File adapters
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :patch: 2
2
+ :patch: 3
3
3
  :major: 0
4
4
  :minor: 7
@@ -94,13 +94,19 @@ module Sunspot
94
94
  #
95
95
  # Class:: Subclass of InstanceAdapter, or nil if none found
96
96
  #
97
+ # ==== Raises
98
+ #
99
+ # Sunspot::NoAdapterError:: If no adapter is registered for this class
100
+ #
97
101
  def for(clazz) #:nodoc:
102
+ original_class_name = clazz.name
98
103
  while clazz != Object
99
104
  class_name = clazz.name.to_sym
100
105
  return instance_adapters[class_name] if instance_adapters[class_name]
101
106
  clazz = clazz.superclass
102
107
  end
103
- nil
108
+ raise(Sunspot::NoAdapterError,
109
+ "No adapter is configured for #{original_class_name} or its superclasses. See the documentation for Sunspot::Adapters")
104
110
  end
105
111
 
106
112
  protected
@@ -68,6 +68,14 @@ module Sunspot
68
68
  end
69
69
  end
70
70
 
71
+ #
72
+ # See Sunspot.remove!
73
+ #
74
+ def remove!(*objects)
75
+ remove(*objects)
76
+ commit
77
+ end
78
+
71
79
  #
72
80
  # See Sunspot.remove_all
73
81
  #
@@ -84,6 +92,14 @@ module Sunspot
84
92
  end
85
93
  end
86
94
 
95
+ #
96
+ # See Sunspot.remove_all!
97
+ #
98
+ def remove_all!(*classes)
99
+ remove_all(*classes)
100
+ commit
101
+ end
102
+
87
103
  #
88
104
  # See Sunspot.dirty?
89
105
  #
@@ -112,7 +128,7 @@ module Sunspot
112
128
  # Sunspot::Setup:: The setup for the object's class
113
129
  #
114
130
  def setup_for(object)
115
- Setup.for(object.class) || raise(ArgumentError, "Sunspot is not configured for #{object.class.inspect}")
131
+ Setup.for(object.class) || raise(NoSetupError, "Sunspot is not configured for #{object.class.inspect}")
116
132
  end
117
133
 
118
134
  #
data/lib/sunspot.rb CHANGED
@@ -24,6 +24,8 @@ end
24
24
  module Sunspot
25
25
  UnrecognizedFieldError = Class.new(Exception)
26
26
  UnrecognizedRestrictionError = Class.new(Exception)
27
+ NoAdapterError = Class.new(Exception)
28
+ NoSetupError = Class.new(Exception)
27
29
 
28
30
  class <<self
29
31
  # Configures indexing and search for a given class.
@@ -225,9 +227,21 @@ module Sunspot
225
227
  session.remove(*objects)
226
228
  end
227
229
 
230
+ #
231
+ # Remove objects from the index and immediately commit. See Sunspot.remove
232
+ #
233
+ # ==== Parameters
234
+ #
235
+ # objects...<Object>:: Objects to remove from the index
236
+ #
237
+ def remove!
238
+ session.remove!(*objects)
239
+ end
240
+
228
241
  # Remove all objects of the given classes from the index. There isn't much
229
242
  # use for this in general operations but it can be useful for maintenance,
230
- # testing, etc.
243
+ # testing, etc. If no arguments are passed, remove everything from the
244
+ # index.
231
245
  #
232
246
  # ==== Parameters
233
247
  #
@@ -243,6 +257,18 @@ module Sunspot
243
257
  session.remove_all(*classes)
244
258
  end
245
259
 
260
+ #
261
+ # Remove all objects of the given classes from the index and immediately
262
+ # commit. See Sunspot.remove_all
263
+ #
264
+ # ==== Parameters
265
+ #
266
+ # classes...<Class>::
267
+ # classes for which to remove all instances from the index
268
+ def remove_all!(*classes)
269
+ session.remove_all(*classes)
270
+ end
271
+
246
272
  #
247
273
  # True if documents have been added, updated, or removed since the last
248
274
  # commit.
@@ -92,11 +92,23 @@ describe 'indexer' do
92
92
  session.remove(post)
93
93
  end
94
94
 
95
- it 'should be able to remove everything from the index' do
95
+ it 'should remove an object from the index and immediately commit' do
96
+ connection.should_receive(:delete).with("Post #{post.id}").ordered
97
+ connection.should_receive(:commit).ordered
98
+ session.remove!(post)
99
+ end
100
+
101
+ it 'should remove everything from the index' do
96
102
  connection.should_receive(:delete_by_query).with("type:[* TO *]")
97
103
  session.remove_all
98
104
  end
99
105
 
106
+ it 'should remove everything from the index and immediately commit' do
107
+ connection.should_receive(:delete_by_query).with("type:[* TO *]").ordered
108
+ connection.should_receive(:commit).ordered
109
+ session.remove_all!
110
+ end
111
+
100
112
  it 'should be able to remove everything of a given class from the index' do
101
113
  connection.should_receive(:delete_by_query).with("type:Post")
102
114
  session.remove_all(Post)
@@ -113,7 +125,7 @@ describe 'indexer' do
113
125
  end
114
126
 
115
127
  it 'should throw an ArgumentError if an attempt is made to index an object that has no configuration' do
116
- lambda { session.index(Time.now) }.should raise_error(ArgumentError)
128
+ lambda { session.index(Time.now) }.should raise_error(Sunspot::NoSetupError)
117
129
  end
118
130
 
119
131
  it 'should throw an ArgumentError if single-value field tries to index multiple values' do
@@ -123,6 +135,10 @@ describe 'indexer' do
123
135
  end.should raise_error(ArgumentError)
124
136
  end
125
137
 
138
+ it 'should throw a NoAdapterError if class without adapter is indexed' do
139
+ lambda { session.index(User.new) }.should raise_error(Sunspot::NoAdapterError)
140
+ end
141
+
126
142
  private
127
143
 
128
144
  def config
@@ -0,0 +1,8 @@
1
+ class User
2
+ attr_accessor :name
3
+ end
4
+
5
+ Sunspot.setup(User) do
6
+ text :name
7
+ string :name
8
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: outoftime-sunspot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.2
4
+ version: 0.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mat Brown
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-29 00:00:00 -07:00
12
+ date: 2009-05-06 00:00:00 -07:00
13
13
  default_executable: sunspot-solr
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -89,6 +89,7 @@ files:
89
89
  - spec/mocks
90
90
  - spec/mocks/base_class.rb
91
91
  - spec/mocks/mock_adapter.rb
92
+ - spec/mocks/user.rb
92
93
  - spec/mocks/post.rb
93
94
  - spec/mocks/comment.rb
94
95
  - spec/api