swiftype 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
@@ -13,20 +13,15 @@ Prerequisites
13
13
  Installation
14
14
  ---
15
15
 
16
- For now, just clone this repository and then pull in the library:
16
+ To install the gem, execute:
17
17
 
18
- #### Bundler
18
+ gem install swiftype
19
19
 
20
- gem 'swiftype-rb', :git => "https://github.com/swiftype/swiftype-rb.git", :require => 'swiftype'
20
+ Or place `gem 'swiftype'` in your `Gemfile` and run `bundle install`.
21
21
 
22
- #### Non-Bundler
23
-
24
- git clone https://github.com/swiftype/swiftype-rb.git
25
-
26
- rake build && rake install
27
-
28
- require 'swiftype'
22
+ To use the GitHub version, you may add this to your Gemfile:
29
23
 
24
+ gem 'swiftype', :git => "https://github.com/swiftype/swiftype-rb.git"
30
25
 
31
26
  Overview
32
27
  ---
@@ -65,11 +60,10 @@ Basic Usage
65
60
  Configuration:
66
61
  ---
67
62
 
68
- Before issuing commands to the API, configure the client with your authentication credentials:
63
+ Before issuing commands to the API, configure the client with your API key:
69
64
 
70
65
  Swiftype.configure do |config|
71
- config.username = "{YOUR_SWIFTYPE_LOGIN}"
72
- config.password = "{YOUR_SWIFTYPE_PASSWORD}"
66
+ config.api_key = 'YOUR_API_KEY'
73
67
  end
74
68
 
75
69
  Indexing:
@@ -382,4 +376,4 @@ Questions?
382
376
  ===
383
377
  Get in touch! We would be happy to help you get up and running.
384
378
 
385
- [Quin](mailto:quin@swiftype.com) and [Matt](mailto:matt@swiftype.com) from [Swiftype](http://swiftype.com)
379
+ [Quin](mailto:quin@swiftype.com) and [Matt](mailto:matt@swiftype.com) from [Swiftype](http://swiftype.com)
data/lib/swiftype.rb CHANGED
@@ -9,6 +9,7 @@ module Swiftype
9
9
  autoload :Client, 'swiftype/client'
10
10
  autoload :BaseModel, 'swiftype/base_model'
11
11
  autoload :Request, 'swiftype/request'
12
+ autoload :ResultSet, 'swiftype/result_set'
12
13
  autoload :Search, 'swiftype/search'
13
14
  autoload :Engine, 'swiftype/engine'
14
15
  autoload :DocumentType, 'swiftype/document_type'
@@ -21,10 +21,6 @@ module Swiftype
21
21
  end
22
22
  end
23
23
 
24
- def id
25
- self._id
26
- end
27
-
28
24
  def to_hash
29
25
  table
30
26
  end
@@ -63,10 +63,7 @@ module Swiftype
63
63
 
64
64
  def search(query, options={})
65
65
  search_params = { :q => query }.merge(parse_search_options(options))
66
- response = post("engines/#{engine_id}/document_types/#{slug}/search.json", search_params)
67
- results = {}
68
- response['records'].each { |document_type, records| results[document_type] = records.map { |d| Swiftype::Document.new(d) }}
69
- results
66
+ ResultSet.new(post("engines/#{engine_id}/document_types/#{slug}/search.json", search_params))
70
67
  end
71
68
  end
72
69
  end
data/lib/swiftype/easy.rb CHANGED
@@ -21,17 +21,11 @@ module Swiftype
21
21
  end
22
22
  def suggest(engine_id, query, options={})
23
23
  search_params = { :q => query }.merge(parse_suggest_options(options))
24
- response = post("engines/#{engine_id}/suggest.json", search_params)
25
- results = {}
26
- response['records'].each { |document_type, records| results[document_type] = records.map { |d| Swiftype::Document.new(d) }}
27
- results
24
+ ResultSet.new(post("engines/#{engine_id}/suggest.json", search_params))
28
25
  end
29
26
  def search(engine_id, query, options={})
30
27
  search_params = { :q => query }.merge(parse_search_options(options))
31
- response = post("engines/#{engine_id}/search.json", search_params)
32
- results = {}
33
- response['records'].each { |document_type, records| results[document_type] = records.map { |d| Swiftype::Document.new(d) }}
34
- results
28
+ ResultSet.new(post("engines/#{engine_id}/search.json", search_params))
35
29
  end
36
30
  end
37
31
 
@@ -0,0 +1,45 @@
1
+ module Swiftype
2
+ class ResultSet
3
+ attr_accessor :records, :info
4
+
5
+ def initialize(results)
6
+ @records = {}
7
+ results['records'].each do |document_type, documents|
8
+ @records[document_type] = documents.map { |d| Swiftype::Document.new(d) }
9
+ end
10
+ @info = results['info']
11
+ end
12
+
13
+ def [](document_type)
14
+ records[document_type]
15
+ end
16
+
17
+ def facets(document_type)
18
+ info[document_type]['facets']
19
+ end
20
+
21
+ def current_page
22
+ info[info.keys.first]['current_page']
23
+ end
24
+
25
+ def per_page
26
+ info[info.keys.first]['per_page']
27
+ end
28
+
29
+ def num_pages(document_type=nil)
30
+ if document_type
31
+ info[document_type]['num_pages']
32
+ else
33
+ info.values.map { |v| v['num_pages'] }.max
34
+ end
35
+ end
36
+
37
+ def total_result_count(document_type)
38
+ info[document_type]['total_result_count']
39
+ end
40
+
41
+ def query
42
+ info[info.keys.first]['query']
43
+ end
44
+ end
45
+ end
@@ -1,7 +1,7 @@
1
1
  module Swiftype
2
2
  module Search
3
3
  VALID_SUGGEST_OPTIONS = [:fetch_fields, :search_fields, :filters, :document_types, :functional_boosts, :page, :per_page]
4
- VALID_SEARCH_OPTIONS = [:fetch_fields, :search_fields, :filters, :document_types, :functional_boosts, :page, :per_page, :sort_field, :sort_direction]
4
+ VALID_SEARCH_OPTIONS = [:fetch_fields, :search_fields, :filters, :document_types, :functional_boosts, :page, :per_page, :sort_field, :sort_direction, :facets]
5
5
 
6
6
  def parse_search_options(options)
7
7
  parse_options(options, VALID_SEARCH_OPTIONS)
@@ -1,3 +1,3 @@
1
1
  module Swiftype
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: swiftype
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:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-08-27 00:00:00.000000000 Z
13
+ date: 2012-10-31 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: json
@@ -121,6 +121,7 @@ files:
121
121
  - lib/swiftype/engine.rb
122
122
  - lib/swiftype/exceptions.rb
123
123
  - lib/swiftype/request.rb
124
+ - lib/swiftype/result_set.rb
124
125
  - lib/swiftype/search.rb
125
126
  - lib/swiftype/version.rb
126
127
  - swiftype.gemspec