swiftype 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -2,3 +2,4 @@
2
2
  .bundle
3
3
  Gemfile.lock
4
4
  pkg/*
5
+ .DS_Store
data/README.md CHANGED
@@ -15,7 +15,7 @@ Installation
15
15
 
16
16
  To install the gem, execute:
17
17
 
18
- gem install swiftype
18
+ gem install swiftype
19
19
 
20
20
  Or place `gem 'swiftype'` in your `Gemfile` and run `bundle install`.
21
21
 
@@ -62,9 +62,11 @@ Configuration:
62
62
 
63
63
  Before issuing commands to the API, configure the client with your API key:
64
64
 
65
- Swiftype.configure do |config|
66
- config.api_key = 'YOUR_API_KEY'
67
- end
65
+ ```ruby
66
+ Swiftype.configure do |config|
67
+ config.api_key = 'YOUR_API_KEY'
68
+ end
69
+ ```
68
70
 
69
71
  Indexing:
70
72
  ---
@@ -233,7 +235,30 @@ Search a `document_type` for the query "lucene":
233
235
  type = engine.document_type('books')
234
236
  results = type.search("lucene")
235
237
 
236
- You can pass the following options to the search method: `page`, `per_page`, `fetch_fields`, `search_fields`, and `filters`.
238
+ Searches return a `ResultSet` object from which you retrieve the results. Results are grouped by their `DocumentType`, so you retrieve the results for a specific `DocumentType` as follows:
239
+
240
+ resultset = type.search('lucene')
241
+ book_results = resultset['books']
242
+ book_results.each do |book|
243
+ puts book.title
244
+ puts book.author
245
+ puts book.genre
246
+ end
247
+
248
+ The `ResultSet` object also contains meta data for the search, such as pagination and facets if the user has specified them.
249
+
250
+ #### Pagination
251
+
252
+ To get pagination information from a `ResultSet`, you call the `num_pages`, `current_page`, and `per_page` methods. For example:
253
+
254
+ resultset = type.search('lucene')
255
+ puts "Current page of results: #{resultset.current_page}"
256
+ puts "Total pages in this result set: #{resultset.num_pages}"
257
+ puts "Number of results per page: #{resultset.per_page}"
258
+
259
+ #### Search Options
260
+
261
+ You can pass the following options to the search method: `page`, `per_page`, `fetch_fields`, `search_fields`, `filters`, and `facets`.
237
262
 
238
263
  * `page` should be an integer of the page of results you want
239
264
  * `per_page` should be an integer of the number of results you want from each page
@@ -241,21 +266,24 @@ You can pass the following options to the search method: `page`, `per_page`, `fe
241
266
  * `search_fields` is a hash containing arrays of the fields you want to match your query against for each object of each document_type
242
267
  * `functional_boosts` is a hash containing boosts that are to be applied to numerically valued fields
243
268
  * `filters` is a hash specifying additional conditions that should be applied to your query for each document_type
269
+ * `facets` is a hash specifying fields for faceted counts for each document type
244
270
 
245
271
  An example of using search options is as follows:
246
272
 
247
- results = type.search('lucene', :filters => { :books => { :in_stock => false, :genre => 'fiction' }}, :per_page => 10, :page => 2, :fetch_fields => {:books => ['title','genre']}, :search_fields => {:books => ['title']})
273
+ resultset = type.search('lucene', :filters => { :books => { :in_stock => false, :genre => 'fiction' }}, :per_page => 10, :page => 2, :fetch_fields => {:books => ['title','genre']}, :search_fields => {:books => ['title']})
248
274
 
249
275
  Filters also support datetime range queries. For example, to return only those books with an `updated_at` field between `2012-02-16` and now, use the following filter:
250
276
 
251
- results = type.search('lucene', :filters => { :books => { :updated_at => '[2012-02-16 TO *]' }})
277
+ resultset = type.search('lucene', :filters => { :books => { :updated_at => '[2012-02-16 TO *]' }})
278
+
279
+ See the (Swiftype Documentation)[http://swiftype.com/documentation/searching] for more details and examples of search options.
252
280
 
253
281
 
254
282
  ##### Functional Boosts
255
283
 
256
284
  Functional boosts allow you to boost result scores based on some numerically valued field. For example, you might want your search engine to return the most popular books first, so you would boost results on the `total_purchases` field, which contains an `integer` of the total number of purchases of that book:
257
285
 
258
- results = type.search('lucene', :functional_boosts => { :books => { :total_purchases => 'logarithmic' }})
286
+ resultset = type.search('lucene', :functional_boosts => { :books => { :total_purchases => 'logarithmic' }})
259
287
 
260
288
  There are 3 types of functional boosts:
261
289
 
@@ -265,6 +293,18 @@ There are 3 types of functional boosts:
265
293
 
266
294
  Functional boosts may be applied to `integer` and `float` valued fields.
267
295
 
296
+ ##### Facets
297
+
298
+ You may get facets for your search results by passing the facets option when you search. For example, to get aggregate counts for the number of results in each genre, use the following:
299
+
300
+ resultset = type.search('lucene', :facets => { :books => ['genre']})
301
+
302
+ You can retrieve the facet counts from the `ResultSet` as follows:
303
+
304
+ resultset = type.search('lucene', :facets => { :books => ['genre']})
305
+ resultset.facets('books')
306
+ => {"genre"=>{"fiction"=>5, "non-fiction"=>2, "political"=>1, "fantasy"=>1}}
307
+
268
308
  #### Autocomplete
269
309
 
270
310
  Get autocomplete suggestions from a `document_type` for the prefix "act"
@@ -2,7 +2,7 @@ require 'swiftype/version'
2
2
 
3
3
  module Swiftype
4
4
  module Configuration
5
- DEFAULT_ENDPOINT = "http://api.swiftype.com/api/v1/"
5
+ DEFAULT_ENDPOINT = "https://api.swiftype.com/api/v1/"
6
6
  DEFAULT_USER_AGENT = "Swiftype-Ruby/#{Swiftype::VERSION}"
7
7
 
8
8
  VALID_OPTIONS_KEYS = [
@@ -39,4 +39,4 @@ module Swiftype
39
39
  options
40
40
  end
41
41
  end
42
- end
42
+ end
data/lib/swiftype/easy.rb CHANGED
@@ -10,7 +10,6 @@ module Swiftype
10
10
 
11
11
  module Engine
12
12
  def engines
13
- test_search_module
14
13
  get("engines.json")
15
14
  end
16
15
  def create_engine(engine={})
@@ -1,3 +1,3 @@
1
1
  module Swiftype
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
data/swiftype.gemspec CHANGED
@@ -18,9 +18,9 @@ Gem::Specification.new do |s|
18
18
 
19
19
  # specify any dependencies here; for example:
20
20
  # s.add_development_dependency "rspec"
21
- s.add_runtime_dependency "json"
21
+ s.add_runtime_dependency "json", ['~> 1.7.7']
22
22
  s.add_runtime_dependency "faraday", ['~> 0.8.1']
23
23
  s.add_runtime_dependency "faraday_middleware", ['~> 0.8.7']
24
24
  s.add_runtime_dependency "hashie", ['~> 1.2.0']
25
- s.add_runtime_dependency 'activesupport', ['>= 2.3.9', '< 4']
25
+ s.add_runtime_dependency 'activesupport', ['>= 2.3.9']
26
26
  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.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,24 +10,24 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-10-31 00:00:00.000000000 Z
13
+ date: 2013-07-19 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: json
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
- - - ! '>='
20
+ - - ~>
21
21
  - !ruby/object:Gem::Version
22
- version: '0'
22
+ version: 1.7.7
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  none: false
27
27
  requirements:
28
- - - ! '>='
28
+ - - ~>
29
29
  - !ruby/object:Gem::Version
30
- version: '0'
30
+ version: 1.7.7
31
31
  - !ruby/object:Gem::Dependency
32
32
  name: faraday
33
33
  requirement: !ruby/object:Gem::Requirement
@@ -84,9 +84,6 @@ dependencies:
84
84
  - - ! '>='
85
85
  - !ruby/object:Gem::Version
86
86
  version: 2.3.9
87
- - - <
88
- - !ruby/object:Gem::Version
89
- version: '4'
90
87
  type: :runtime
91
88
  prerelease: false
92
89
  version_requirements: !ruby/object:Gem::Requirement
@@ -95,9 +92,6 @@ dependencies:
95
92
  - - ! '>='
96
93
  - !ruby/object:Gem::Version
97
94
  version: 2.3.9
98
- - - <
99
- - !ruby/object:Gem::Version
100
- version: '4'
101
95
  description: Official gem for accessing the Swiftype Search API
102
96
  email:
103
97
  - team@swiftype.com
@@ -145,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
145
139
  version: '0'
146
140
  requirements: []
147
141
  rubyforge_project:
148
- rubygems_version: 1.8.24
142
+ rubygems_version: 1.8.23
149
143
  signing_key:
150
144
  specification_version: 3
151
145
  summary: Swiftype API Gem