oedipus 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -5,7 +5,8 @@ real-time indexes and multi and/or faceted searches.
5
5
 
6
6
  It is not a clone of the PHP API, rather it is written from the ground up,
7
7
  wrapping the SphinxQL API offered by searchd. Nor is it a plugin for
8
- ActiveRecord or DataMapper... though this will follow in separate gems.
8
+ ActiveRecord or DataMapper... though this will follow in separate gems (see
9
+ [oedipus-dm](https://github.com/d11wtq/oedipus-dm)).
9
10
 
10
11
  Oedipus provides a level of abstraction in terms of the ease with which faceted
11
12
  search may be implemented, while remaining light and simple.
@@ -344,11 +345,12 @@ You may also compile the C extension and run the specs separately, if you prefer
344
345
  ## Future Plans
345
346
 
346
347
  * Integration with DataMapper and ActiveRecord (DataMapper first)
348
+ * Support for re-indexing non-realtime indexes from ruby code
347
349
  * Distributed index support (sharding writes between indexes)
348
350
  * Make C extension optional and provide an implementation in pure-ruby
349
351
  * N-dimensional faceted search (facets inside of facets)
350
- * Query translation layer for Google-style AND/OR/NOT interpretation
351
- * Fulltext query sanitization for unsafe user input (e.g. @missing field)
352
+ * Query translation layer for Lucene-style AND/OR/NOT and attribute:value interpretation
353
+ * Fulltext query sanitization for unsafe user input (e.g. @@missing field)
352
354
 
353
355
  ## Copyright and Licensing
354
356
 
data/lib/oedipus/index.rb CHANGED
@@ -76,6 +76,20 @@ module Oedipus
76
76
  @conn.execute(@builder.replace(id, hash))
77
77
  end
78
78
 
79
+ # Delete the record with the ID +id+.
80
+ #
81
+ # @example
82
+ # index.delete(42)
83
+ #
84
+ # @param [Integer] id
85
+ # the unique ID of the document in the index
86
+ #
87
+ # @return [Fixnum]
88
+ # the number of rows deleted (currently always 1 or 0)
89
+ def delete(id)
90
+ @conn.execute(@builder.delete(id))
91
+ end
92
+
79
93
  # Fetch a single document by its ID.
80
94
  #
81
95
  # Returns the Hash of attributes if found, otherwise nil.
@@ -83,7 +83,16 @@ module Oedipus
83
83
  into("REPLACE", id, attributes)
84
84
  end
85
85
 
86
- private
86
+ # Build a SphinxQL query to delete the record identified by +id+.
87
+ #
88
+ # @param [Fixnum] id
89
+ # the unique ID of the document to delete
90
+ #
91
+ # @return [String]
92
+ # the SphinxQL to delete the record
93
+ def delete(id)
94
+ "DELETE FROM #{@index_name} WHERE id = #{Connection.quote(id)}"
95
+ end
87
96
 
88
97
  private
89
98
 
@@ -8,5 +8,5 @@
8
8
  ##
9
9
 
10
10
  module Oedipus
11
- VERSION = "0.0.2"
11
+ VERSION = "0.0.3"
12
12
  end
@@ -147,6 +147,25 @@ describe Oedipus::Index do
147
147
  end
148
148
  end
149
149
 
150
+ describe "#delete" do
151
+ before(:each) do
152
+ index.insert(
153
+ 1,
154
+ title: "Badgers",
155
+ body: "They live in setts, do badgers.",
156
+ views: 721,
157
+ user_id: 7
158
+ )
159
+ end
160
+
161
+ context "with valid existing data" do
162
+ it "entirely deletes the record" do
163
+ index.delete(1)
164
+ index.fetch(1).should be_nil
165
+ end
166
+ end
167
+ end
168
+
150
169
  describe "#search" do
151
170
  before(:each) do
152
171
  index.insert(1, title: "Badgers and foxes", views: 150)
@@ -180,6 +199,18 @@ describe Oedipus::Index do
180
199
  { id: 3, views: 41, user_id: 0, status: "" }
181
200
  ]
182
201
  end
202
+
203
+ pending "the sphinxql grammar does not currently support this, though I'm patching it" do
204
+ context "with string attributes" do
205
+ before(:each) do
206
+ index.insert(5, title: "No more badgers, please", views: 0, status: "new")
207
+ end
208
+
209
+ it "filters by the string attribute" do
210
+ index.search(status: "new")[:records].should == [{ id: 5, views: 0, user_id: 0, status: "new" }]
211
+ end
212
+ end
213
+ end
183
214
  end
184
215
 
185
216
  context "by fulltext with attribute filtering" do
@@ -159,4 +159,10 @@ describe Oedipus::QueryBuilder do
159
159
  builder.replace(3, title: "example", views: 9).should == "REPLACE INTO posts (id, title, views) VALUES (3, 'example', 9)"
160
160
  end
161
161
  end
162
+
163
+ describe "#delete" do
164
+ it "includes the ID" do
165
+ builder.delete(3).should == "DELETE FROM posts WHERE id = 3"
166
+ end
167
+ end
162
168
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oedipus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-26 00:00:00.000000000 Z
12
+ date: 2012-04-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &17523900 !ruby/object:Gem::Requirement
16
+ requirement: &18061060 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *17523900
24
+ version_requirements: *18061060
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake-compiler
27
- requirement: &17785080 !ruby/object:Gem::Requirement
27
+ requirement: &18156200 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *17785080
35
+ version_requirements: *18156200
36
36
  description: ! "== Sphinx 2 Comes to Ruby\n\nOedipus brings full support for Sphinx
37
37
  2 to Ruby:\n\n - real-time indexes (insert, replace, update, delete)\n - faceted
38
38
  search (variations on a base query)\n - multi-queries (multiple queries executed
@@ -108,7 +108,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
108
108
  version: '0'
109
109
  segments:
110
110
  - 0
111
- hash: -2156223476035950462
111
+ hash: -3912643508357883661
112
112
  required_rubygems_version: !ruby/object:Gem::Requirement
113
113
  none: false
114
114
  requirements:
@@ -117,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
117
  version: '0'
118
118
  segments:
119
119
  - 0
120
- hash: -2156223476035950462
120
+ hash: -3912643508357883661
121
121
  requirements: []
122
122
  rubyforge_project: oedipus
123
123
  rubygems_version: 1.8.11