oedipus 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -251,7 +251,7 @@ it does two optimizations, though in future this will likely improve further, so
251
251
  using this technique to do your faceted searches is a good idea.
252
252
 
253
253
  ``` ruby
254
- results = sphinx[:articles].facted_search(
254
+ results = sphinx[:articles].search(
255
255
  "badgers",
256
256
  facets: {
257
257
  popular: { views: 100..10000 },
data/lib/oedipus/index.rb CHANGED
@@ -117,26 +117,12 @@ module Oedipus
117
117
  # @example Attribute search only
118
118
  # index.search(author_id: 57)
119
119
  #
120
- # @param [String] query
121
- # a fulltext query
122
- #
123
- # @param [Hash] filters
124
- # attribute filters, limits, sorting and other options
125
- #
126
- # @return [Hash]
127
- # a Hash containing meta data, with the records in :records
128
- def search(*args)
129
- multi_search(_main_: args)[:_main_]
130
- end
131
-
132
- # Perform a faceted search on the index, using a base query and one or more facets.
133
- #
134
- # The base query is inherited by each facet, which may override (or refine) the
135
- # query.
120
+ # When performing a faceted search, the base query is inherited by each facet, which
121
+ # may override (or refine) the query.
136
122
  #
137
123
  # The results returned include a :facets key, containing the results for each facet.
138
124
  #
139
- # @example
125
+ # @example Performing a faceted search
140
126
  # index.faceted_search(
141
127
  # "cats | dogs",
142
128
  # category_id: 7,
@@ -146,16 +132,34 @@ module Oedipus
146
132
  # }
147
133
  # )
148
134
  #
149
- # @param [String] fulltext_query
150
- # a fulltext query to search on, optional
135
+ # @param [String] query
136
+ # a fulltext query
151
137
  #
152
138
  # @param [Hash] options
153
- # attribute filters and facets in a sub-hash
139
+ # attribute filters, limits, sorting, facets and other options
140
+ #
141
+ # @option [Hash] facets
142
+ # variations on the main search to return nested in the result
143
+ #
144
+ # @option [Array] attrs
145
+ # attributes to fetch from the index, either as Symbols, or SphinxQL fragments
146
+ #
147
+ # @option [Hash] order
148
+ # an attr => direction mapping of sort orders
149
+ #
150
+ # @option [Fixnum] limit
151
+ # a limit to apply, defaults to 20 inside Sphinx itself
152
+ #
153
+ # @option [Fixnum] offset
154
+ # an offset to apply, defaults to 0
155
+ #
156
+ # @option [Object] everything_else
157
+ # all additional options are taken to be attribute filters
154
158
  #
155
159
  # @return [Hash]
156
- # a Hash whose top-level result set is for the main query and which
157
- # contains a :facets element with keys mapping 1:1 for all facets
158
- def faceted_search(*args)
160
+ # a Hash containing meta data, with the records in :records, and if any
161
+ # facets were included, the facets inside the :facets Hash
162
+ def search(*args)
159
163
  query, options = extract_query_data(args)
160
164
  main_query = [query, options.reject { |k, _| k == :facets }]
161
165
  facets = merge_queries(main_query, options.fetch(:facets, {}))
@@ -167,6 +171,17 @@ module Oedipus
167
171
  end
168
172
  end
169
173
 
174
+ # Perform a faceted search on the index, using a base query and one or more facets.
175
+ #
176
+ # This method is deprecated and will be removed in version 1.0. Use #search instead.
177
+ #
178
+ # @deprecated
179
+ #
180
+ # @see #search
181
+ def faceted_search(*args)
182
+ search(*args)
183
+ end
184
+
170
185
  # Perform a a batch search on the index.
171
186
  #
172
187
  # A Hash of queries is passed, whose keys are used to collate the results in
@@ -8,5 +8,5 @@
8
8
  ##
9
9
 
10
10
  module Oedipus
11
- VERSION = "0.0.3"
11
+ VERSION = "0.0.4"
12
12
  end
@@ -283,53 +283,7 @@ describe Oedipus::Index do
283
283
  end
284
284
  end
285
285
 
286
- describe "#multi_search" do
287
- before(:each) do
288
- index.insert(1, title: "Badgers and foxes", views: 150, user_id: 1)
289
- index.insert(2, title: "Rabbits and hares", views: 87, user_id: 1)
290
- index.insert(3, title: "Badgers in the wild", views: 41, user_id: 2)
291
- index.insert(4, title: "Badgers for all!", views: 3003, user_id: 1)
292
- end
293
-
294
- context "by fulltext querying" do
295
- it "indicates the number of results for each query" do
296
- results = index.multi_search(
297
- badgers: "badgers",
298
- rabbits: "rabbits"
299
- )
300
- results[:badgers][:total_found].should == 3
301
- results[:rabbits][:total_found].should == 1
302
- end
303
-
304
- it "returns the records for each search" do
305
- results = index.multi_search(
306
- badgers: "badgers",
307
- rabbits: "rabbits"
308
- )
309
- results[:badgers][:records].should == [
310
- { id: 1, views: 150, user_id: 1, status: "" },
311
- { id: 3, views: 41, user_id: 2, status: "" },
312
- { id: 4, views: 3003, user_id: 1, status: "" }
313
- ]
314
- results[:rabbits][:records].should == [
315
- { id: 2, views: 87, user_id: 1, status: "" }
316
- ]
317
- end
318
- end
319
-
320
- context "by attribute filtering" do
321
- it "indicates the number of results for each query" do
322
- results = index.multi_search(
323
- shiela: {user_id: 1},
324
- barry: {user_id: 2}
325
- )
326
- results[:shiela][:total_found].should == 3
327
- results[:barry][:total_found].should == 1
328
- end
329
- end
330
- end
331
-
332
- describe "#faceted_search" do
286
+ describe "#search", "with :facets" do
333
287
  before(:each) do
334
288
  index.insert(1, title: "Badgers and foxes", body: "Badgers", views: 150, user_id: 1)
335
289
  index.insert(2, title: "Rabbits and hares", body: "Rabbits", views: 87, user_id: 1)
@@ -339,7 +293,7 @@ describe Oedipus::Index do
339
293
 
340
294
  context "with additional attribute filters" do
341
295
  let(:results) do
342
- index.faceted_search(
296
+ index.search(
343
297
  "badgers",
344
298
  facets: {
345
299
  popular: {views: Oedipus.gte(50)},
@@ -369,7 +323,7 @@ describe Oedipus::Index do
369
323
 
370
324
  context "with overriding attribute filters" do
371
325
  let(:results) do
372
- index.faceted_search(
326
+ index.search(
373
327
  "badgers",
374
328
  user_id: 1,
375
329
  facets: {
@@ -387,7 +341,7 @@ describe Oedipus::Index do
387
341
 
388
342
  context "with overriding overriding fulltext queries" do
389
343
  let(:results) do
390
- index.faceted_search(
344
+ index.search(
391
345
  "badgers",
392
346
  facets: {
393
347
  rabbits: "rabbits"
@@ -404,7 +358,7 @@ describe Oedipus::Index do
404
358
 
405
359
  context "with overriding refined fulltext queries" do
406
360
  let(:results) do
407
- index.faceted_search(
361
+ index.search(
408
362
  "badgers",
409
363
  facets: {
410
364
  in_body: "@body (%{query})"
@@ -419,4 +373,50 @@ describe Oedipus::Index do
419
373
  end
420
374
  end
421
375
  end
376
+
377
+ describe "#multi_search" do
378
+ before(:each) do
379
+ index.insert(1, title: "Badgers and foxes", views: 150, user_id: 1)
380
+ index.insert(2, title: "Rabbits and hares", views: 87, user_id: 1)
381
+ index.insert(3, title: "Badgers in the wild", views: 41, user_id: 2)
382
+ index.insert(4, title: "Badgers for all!", views: 3003, user_id: 1)
383
+ end
384
+
385
+ context "by fulltext querying" do
386
+ it "indicates the number of results for each query" do
387
+ results = index.multi_search(
388
+ badgers: "badgers",
389
+ rabbits: "rabbits"
390
+ )
391
+ results[:badgers][:total_found].should == 3
392
+ results[:rabbits][:total_found].should == 1
393
+ end
394
+
395
+ it "returns the records for each search" do
396
+ results = index.multi_search(
397
+ badgers: "badgers",
398
+ rabbits: "rabbits"
399
+ )
400
+ results[:badgers][:records].should == [
401
+ { id: 1, views: 150, user_id: 1, status: "" },
402
+ { id: 3, views: 41, user_id: 2, status: "" },
403
+ { id: 4, views: 3003, user_id: 1, status: "" }
404
+ ]
405
+ results[:rabbits][:records].should == [
406
+ { id: 2, views: 87, user_id: 1, status: "" }
407
+ ]
408
+ end
409
+ end
410
+
411
+ context "by attribute filtering" do
412
+ it "indicates the number of results for each query" do
413
+ results = index.multi_search(
414
+ shiela: {user_id: 1},
415
+ barry: {user_id: 2}
416
+ )
417
+ results[:shiela][:total_found].should == 3
418
+ results[:barry][:total_found].should == 1
419
+ end
420
+ end
421
+ end
422
422
  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.3
4
+ version: 0.0.4
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-28 00:00:00.000000000 Z
12
+ date: 2012-04-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &18061060 !ruby/object:Gem::Requirement
16
+ requirement: &12876920 !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: *18061060
24
+ version_requirements: *12876920
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake-compiler
27
- requirement: &18156200 !ruby/object:Gem::Requirement
27
+ requirement: &12831220 !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: *18156200
35
+ version_requirements: *12831220
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: -3912643508357883661
111
+ hash: 765099216142211442
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: -3912643508357883661
120
+ hash: 765099216142211442
121
121
  requirements: []
122
122
  rubyforge_project: oedipus
123
123
  rubygems_version: 1.8.11