elastic-site-search 2.1.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 382515c8c38a1933e31fd980bc0951a3f366c66097553283d4de306f5b134cd4
4
- data.tar.gz: 670a1f44b00fed5ee5ba3bfb9611ed2657a3f50ef7299bbd32c89efecb1c7206
3
+ metadata.gz: 5981e7c63cf7474d20008bbf06886e770e155428379de2a873499b8e5bda4e26
4
+ data.tar.gz: 4ab08fab6691807b3a6d2e25798ddece63c6635e091bd659b77d38a0522ab916
5
5
  SHA512:
6
- metadata.gz: 183d39ff3f62f43c3c695a96b74daeac3d99627b90e0ff18b355fdc45b9456cfbd7ecc5bfa3ac39e721e835b5d83e32c680bd8667729c855c09619eda187462c
7
- data.tar.gz: d5f41d5165c203221a13123cff1621e6e7f62d7a3425926c9ab1095f34bb6654331bf357308e1a7160efda636cacccff6063c9d2db42378aba928035a67aaa8c
6
+ metadata.gz: 79a6075cd55f86e9dccaeaa31d306a9c1ea4b0b90708239cd6439b3515b1d42a7d74c7acbf30a52a89faae3dfed03dd645afa17ac540c5c6137c717ab0ad2dc3
7
+ data.tar.gz: ae1d85615cfe15a7f4c70866faf0650226aefb6101e86754d8ece73e710f74cd33532f21545e5a43572d4bef771d18751d590e7f6b09c338426ac115562e014d
data/README.md CHANGED
@@ -44,9 +44,11 @@ Depends on Ruby.
44
44
 
45
45
  To install the gem, execute:
46
46
 
47
- gem install elastic-site-search
47
+ ```shell
48
+ gem install elastic-site-search
49
+ ```
48
50
 
49
- Or place `gem 'elastic-site-search', '~> 2.1.0` in your `Gemfile` and run `bundle install`.
51
+ Or place `gem 'elastic-site-search', '~> 2.2.0` in your `Gemfile` and run `bundle install`.
50
52
 
51
53
  > **Note:** This client has been developed for the [Elastic Site Search](https://www.elastic.co/products/site-search/service) API endpoints only.
52
54
 
@@ -56,23 +58,31 @@ Or place `gem 'elastic-site-search', '~> 2.1.0` in your `Gemfile` and run `bundl
56
58
 
57
59
  Before issuing commands to the API, configure the client with your API key:
58
60
 
59
- Elastic::SiteSearch.api_key = 'YOUR_API_KEY'
61
+ ```ruby
62
+ Elastic::SiteSearch.api_key = 'YOUR_API_KEY'
63
+ ```
60
64
 
61
65
  You can find your API key in your [Account Settings](https://app.swiftype.com/settings/account).
62
66
 
63
67
  ### Create a client
64
68
 
65
- client = Elastic::SiteSearch::Client.new
69
+ ```ruby
70
+ client = Elastic::SiteSearch::Client.new
71
+ ```
66
72
 
67
73
  You can also provide the API key when creating the client instance:
68
74
 
69
- client = Elastic::SiteSearch::Client.new(:api_key => 'different_api_key')
75
+ ```ruby
76
+ client = Elastic::SiteSearch::Client.new(:api_key => 'different_api_key')
77
+ ```
70
78
 
71
79
  If the API key is provided as an option to constructor, it will override the globally configured Elastic::SiteSearch API key (if any).
72
80
 
73
81
  ### Specifying an HTTP Proxy
74
82
 
75
- client = Elastic::SiteSearch::Client.new(:api_key => 'api_key', :proxy => 'http://localhost:8888')
83
+ ```ruby
84
+ client = Elastic::SiteSearch::Client.new(:api_key => 'api_key', :proxy => 'http://localhost:8888')
85
+ ```
76
86
 
77
87
  This client will also support configuring a proxy via the environment variable `http_proxy`.
78
88
 
@@ -80,21 +90,27 @@ This client will also support configuring a proxy via the environment variable `
80
90
 
81
91
  If you want to search for `cat` on your engine, you can use:
82
92
 
83
- results = client.search('site-search-api-example', 'cat')
84
- results['videos'] # => [{'external_id' => 'QH2-TGUlwu4', 'title' => 'Nyan Cat [original]', ... }, ... ]
85
- results['channels'] # => [{'external_id' => 'UC3VHfy8e1jbDnT5TG2pjP1w', 'title' => 'saraj00n', ... }, ... ]
93
+ ```ruby
94
+ results = client.search('site-search-api-example', 'cat')
95
+ results['videos'] # => [{'external_id' => 'QH2-TGUlwu4', 'title' => 'Nyan Cat [original]', ... }, ... ]
96
+ results['channels'] # => [{'external_id' => 'UC3VHfy8e1jbDnT5TG2pjP1w', 'title' => 'saraj00n', ... }, ... ]
97
+ ```
86
98
 
87
99
  To limit the search to only the `videos` DocumentType:
88
100
 
89
- results = client.search_document_type('site-search-api-example', 'videos', 'cat')
90
- results['videos'] # => [{'external_id' => 'QH2-TGUlwu4', 'title' => 'Nyan Cat [original]', ... }, ... ]
91
- results['channels'] # => nil
101
+ ```ruby
102
+ results = client.search_document_type('site-search-api-example', 'videos', 'cat')
103
+ results['videos'] # => [{'external_id' => 'QH2-TGUlwu4', 'title' => 'Nyan Cat [original]', ... }, ... ]
104
+ results['channels'] # => nil
105
+ ```
92
106
 
93
107
  Both search methods allow you to specify options to filter or sort on fields, boost the weight of certain fields, calculate faceted counts, and so on. For more details on these options, review the [Search Options](https://swiftype.com/documentation/site-search/searching).
94
108
 
95
109
  Here is an example for showing only videos in the "Pets & Animals" category (which has ID 23):
96
110
 
97
- results = client.search_document_type('site-search-api-example', 'videos', 'cat', {:filters => {'videos' => {:category_id => '23'}}})
111
+ ```ruby
112
+ results = client.search_document_type('site-search-api-example', 'videos', 'cat', {:filters => {'videos' => {:category_id => '23'}}})
113
+ ```
98
114
 
99
115
  ### Autocomplete search
100
116
 
@@ -102,36 +118,50 @@ Autocomplete (also known as suggest, prefix, or type-ahead) searches can be used
102
118
 
103
119
  You can perform a suggest query across all of your Engine's Documents:
104
120
 
105
- results = client.suggest("site-search-api-example", "gla")
106
- results['videos'] # => [{'external_id' => 'v1uyQZNg2vE', 'title' => 'How It Feels [through Glass]', ...}, ...]
121
+ ```ruby
122
+ results = client.suggest("site-search-api-example", "gla")
123
+ results['videos'] # => [{'external_id' => 'v1uyQZNg2vE', 'title' => 'How It Feels [through Glass]', ...}, ...]
124
+ ```
107
125
 
108
126
  or just for one DocumentType:
109
127
 
110
- results = client.suggest_document_type("site-search-api-example", "videos", "gla")
111
- results['videos'] # => [{'external_id' => 'v1uyQZNg2vE', 'title' => 'How It Feels [through Glass]', ...}, ...]
128
+ ```ruby
129
+ results = client.suggest_document_type("site-search-api-example", "videos", "gla")
130
+ results['videos'] # => [{'external_id' => 'v1uyQZNg2vE', 'title' => 'How It Feels [through Glass]', ...}, ...]
131
+ ```
112
132
 
113
133
  or add options to have more control over the results:
114
134
 
115
- results = client.suggest('site-search-api-example', 'glass', {:sort_field => {'videos' => 'view_count'}, :sort_direction => {'videos' => 'desc'}})
135
+ ```ruby
136
+ results = client.suggest('site-search-api-example', 'glass', {:sort_field => {'videos' => 'view_count'}, :sort_direction => {'videos' => 'desc'}})
137
+ ```
116
138
 
117
139
  ### Engines
118
140
 
119
141
  Retrieve every Engine:
120
142
 
121
- engines = client.engines
143
+ ```ruby
144
+ engines = client.engines
145
+ ```
122
146
 
123
147
  Create a new Engine with the name `site-search-api-example`:
124
148
 
125
- engine = client.create_engine('site-search-api-example')
149
+ ```ruby
150
+ engine = client.create_engine('site-search-api-example')
151
+ ```
126
152
 
127
153
  Retrieve an Engine by `slug` or `id`:
128
154
 
129
- engine = client.engine('site-search-api-example')
130
- engine = client.engine('5230b9102ed960ba20000021')
155
+ ```ruby
156
+ engine = client.engine('site-search-api-example')
157
+ engine = client.engine('5230b9102ed960ba20000021')
158
+ ```
131
159
 
132
160
  Delete an Engine by `slug` or the `id`:
133
161
 
134
- client.destroy_engine('site-search-api-example')
162
+ ```ruby
163
+ client.destroy_engine('site-search-api-example')
164
+ ```
135
165
 
136
166
  ### Document Types
137
167
 
@@ -139,77 +169,100 @@ List all the
139
169
 
140
170
  Retrieve `DocumentTypes`s of the Engine with the `slug` field `site-search-api-example`:
141
171
 
142
- document_types = client.document_types('site-search-api-example')
172
+ ```ruby
173
+ document_types = client.document_types('site-search-api-example')
174
+ ```
143
175
 
144
176
  Show the second batch of documents:
145
177
 
146
- document_types = client.document_types('site-search-api-example', 2)
178
+ ```ruby
179
+ document_types = client.document_types('site-search-api-example', 2)
180
+ ```
147
181
 
148
182
  Create a new DocumentType for an Engine with the name `videos`:
149
183
 
150
- document_type = client.create_document_type('site-search-api-example', 'videos')
184
+ ```ruby
185
+ document_type = client.create_document_type('site-search-api-example', 'videos')
186
+ ```
151
187
 
152
188
  Retrieve an DocumentType by `slug` or `id`:
153
189
 
154
- document_type = client.document_type('site-search-api-example', 'videos')
190
+ ```ruby
191
+ document_type = client.document_type('site-search-api-example', 'videos')
192
+ ```
155
193
 
156
194
  Delete a DocumentType using the `slug` or `id` of it:
157
195
 
158
- client.destroy_document_type('site-search-api-example', 'videos')
196
+ ```ruby
197
+ client.destroy_document_type('site-search-api-example', 'videos')
198
+ ```
159
199
 
160
200
  ### Documents
161
201
 
162
202
  Retrieve the first page of Documents of Engine `site-search-api-example` and DocumentType `videos`:
163
203
 
164
- documents = client.documents('site-search-api-example', 'videos')
204
+ ```ruby
205
+ documents = client.documents('site-search-api-example', 'videos')
206
+ ```
165
207
 
166
208
  Retrieve a specific Document using its `id` or `external_id`:
167
209
 
168
- document = client.document('site-search-api-example', 'videos', 'FHtvDA0W34I')
210
+ ```ruby
211
+ document = client.document('site-search-api-example', 'videos', 'FHtvDA0W34I')
212
+ ```
169
213
 
170
214
  To create or update. single or multiple documents, we use the method `index_documents`.
171
215
 
172
216
  Create a new Document with mandatory `external_id` and user-defined fields:
173
217
 
174
- document = client.index_documents('site-search-api-example', 'videos', {
175
- :external_id => 'FHtvDA0W34I',
176
- :fields => [
177
- {:name => 'title', :value => "Felix Baumgartner's supersonic freefall from 128k' - Mission Highlights", :type => 'string'},
178
- {:name => 'url', :value => 'http://www.youtube.com/watch?v=FHtvDA0W34I', :type => 'enum'},
179
- {:name => 'chanel_id', :value => 'UCblfuW_4rakIf2h6aqANefA', :type => 'enum'}
180
- ]})
218
+ ```ruby
219
+ document = client.index_documents('site-search-api-example', 'videos', {
220
+ :external_id => 'FHtvDA0W34I',
221
+ :fields => [
222
+ {:name => 'title', :value => "Felix Baumgartner's supersonic freefall from 128k' - Mission Highlights", :type => 'string'},
223
+ {:name => 'url', :value => 'http://www.youtube.com/watch?v=FHtvDA0W34I', :type => 'enum'},
224
+ {:name => 'chanel_id', :value => 'UCblfuW_4rakIf2h6aqANefA', :type => 'enum'}
225
+ ]})
226
+ ```
181
227
 
182
228
  Create multiple Documents at once and return status for each Document creation:
183
229
 
184
- response = client.index_documents('site-search-api-example', 'videos', [{
185
- :external_id => 'FHtvDA0W34I',
186
- :fields => [
187
- {:name => 'title', :value => "Felix Baumgartner's supersonic freefall from 128k' - Mission Highlights", :type => 'string'},
188
- {:name => 'url', :value => 'http://www.youtube.com/watch?v=FHtvDA0W34I', :type => 'enum'},
189
- {:name => 'chanel_id', :value => 'UCblfuW_4rakIf2h6aqANefA', :type => 'enum'}
190
- ]}, {
191
- :external_id => 'dMH0bHeiRNg',
192
- :fields => [
193
- {:name => 'title', :value => 'Evolution of Dance - By Judson Laipply', :type => 'string'},
194
- {:name => 'url', :value => 'http://www.youtube.com/watch?v='dMH0bHeiRNg', :type => 'enum'},
195
- {:name => 'chanel_id', :value => UC5B9H4l2vtgo7cAoExcFh-w', :type => 'enum'}
196
- ]}])
230
+ ```ruby
231
+ response = client.index_documents('site-search-api-example', 'videos', [{
232
+ :external_id => 'FHtvDA0W34I',
233
+ :fields => [
234
+ {:name => 'title', :value => "Felix Baumgartner's supersonic freefall from 128k' - Mission Highlights", :type => 'string'},
235
+ {:name => 'url', :value => 'http://www.youtube.com/watch?v=FHtvDA0W34I', :type => 'enum'},
236
+ {:name => 'chanel_id', :value => 'UCblfuW_4rakIf2h6aqANefA', :type => 'enum'}
237
+ ]}, {
238
+ :external_id => 'dMH0bHeiRNg',
239
+ :fields => [
240
+ {:name => 'title', :value => 'Evolution of Dance - By Judson Laipply', :type => 'string'},
241
+ {:name => 'url', :value => 'http://www.youtube.com/watch?v='dMH0bHeiRNg', :type => 'enum'},
242
+ {:name => 'chanel_id', :value => UC5B9H4l2vtgo7cAoExcFh-w', :type => 'enum'}
243
+ ]}])
244
+ ```
197
245
 
198
246
  Update fields of an existing Document specified by `id` or `external_id`:
199
247
 
200
- client.index_documents('site-search-api-example', 'videos', 'FHtvDA0W34I', {:title =>'New Title'})
248
+ ```ruby
249
+ client.index_documents('site-search-api-example', 'videos', 'FHtvDA0W34I', {:title =>'New Title'})
250
+ ```
201
251
 
202
252
  **NOTE:** A field must already exist on a Document in order to update it.
203
253
 
204
254
  Update multiple Documents at once:
205
255
 
206
- response = client.index_documents('site-search-api-example','videos', [
207
- {:external_id => 'FHtvDA0W34I', :fields => {:view_count => 32874417}},
208
- {:external_id => 'dMH0bHeiRNg', :fields => {:view_count => 98323493}}
209
- ])
256
+ ```ruby
257
+ response = client.index_documents('site-search-api-example','videos', [
258
+ {:external_id => 'FHtvDA0W34I', :fields => {:view_count => 32874417}},
259
+ {:external_id => 'dMH0bHeiRNg', :fields => {:view_count => 98323493}}
260
+ ])
261
+ ```
210
262
 
211
263
  All methods above will have a return in the following format:
212
264
 
265
+ ```ruby
213
266
  [
214
267
  {
215
268
  "id": "5473d6142ed96065a9000001",
@@ -232,85 +285,96 @@ All methods above will have a return in the following format:
232
285
  }
233
286
  }
234
287
  ]
288
+ ```
235
289
 
236
290
  **NOTE:** If you'd like to create or update documents asynchronously, simply pass the option `:async => true` as the last argument.
237
291
 
238
292
  For instance, to Create multiple Documents at once:
239
293
 
240
- response = client.index_documents('site-search-api-example', 'videos', [{
241
- :external_id => 'FHtvDA0W34I',
242
- :fields => [
243
- {:name => 'title', :value => "Felix Baumgartner's supersonic freefall from 128k' - Mission Highlights", :type => 'string'},
244
- {:name => 'url', :value => 'http://www.youtube.com/watch?v=FHtvDA0W34I', :type => 'enum'},
245
- {:name => 'chanel_id', :value => 'UCblfuW_4rakIf2h6aqANefA', :type => 'enum'}
246
- ]}, {
247
- :external_id => 'dMH0bHeiRNg',
248
- :fields => [
249
- {:name => 'title', :value => 'Evolution of Dance - By Judson Laipply', :type => 'string'},
250
- {:name => 'url', :value => 'http://www.youtube.com/watch?v='dMH0bHeiRNg', :type => 'enum'},
251
- {:name => 'chanel_id', :value => UC5B9H4l2vtgo7cAoExcFh-w', :type => 'enum'}
252
- ]}],
253
- :async => true )
254
- #=> {
255
- "batch_link": "https://api.swiftype.com/api/v1/document_receipts.json?ids=5473d6142ed96065a9000001,5473d6142ed96065a9000002",
256
- "document_receipts": [
257
- {
258
- "id": "5473d6142ed96065a9000001",
259
- "external_id": "FHtvDA0W34I",
260
- "status": "pending",
261
- "errors": [],
262
- "links": {
263
- "receipt": "https://api.swiftype.com/api/v1/document_receipts/5473d6142ed96065a9000001.json",
264
- "document": null
265
- }
266
- },
267
- {
268
- "id": "5473d6342ed96065a9000002",
269
- "external_id": "dMH0bHeiRNg",
270
- "status": "pending",
271
- "errors": [],
272
- "links": {
273
- "receipt": "https://api.swiftype.com/api/v1/document_receipts/5473d6142ed96065a9000002.json",
274
- "document": null
275
- }
276
- }
277
- ]
278
- }
294
+ ```ruby
295
+ response = client.index_documents('site-search-api-example', 'videos', [{
296
+ :external_id => 'FHtvDA0W34I',
297
+ :fields => [
298
+ {:name => 'title', :value => "Felix Baumgartner's supersonic freefall from 128k' - Mission Highlights", :type => 'string'},
299
+ {:name => 'url', :value => 'http://www.youtube.com/watch?v=FHtvDA0W34I', :type => 'enum'},
300
+ {:name => 'chanel_id', :value => 'UCblfuW_4rakIf2h6aqANefA', :type => 'enum'}
301
+ ]}, {
302
+ :external_id => 'dMH0bHeiRNg',
303
+ :fields => [
304
+ {:name => 'title', :value => 'Evolution of Dance - By Judson Laipply', :type => 'string'},
305
+ {:name => 'url', :value => 'http://www.youtube.com/watch?v='dMH0bHeiRNg', :type => 'enum'},
306
+ {:name => 'chanel_id', :value => UC5B9H4l2vtgo7cAoExcFh-w', :type => 'enum'}
307
+ ]}],
308
+ :async => true )
309
+ #=>
310
+ # {
311
+ # "batch_link": "https://api.swiftype.com/api/v1/document_receipts.json?ids=5473d6142ed96065a9000001,5473d6142ed96065a9000002",
312
+ # "document_receipts": [
313
+ # {
314
+ # "id": "5473d6142ed96065a9000001",
315
+ # "external_id": "FHtvDA0W34I",
316
+ # "status": "pending",
317
+ # "errors": [],
318
+ # "links": {
319
+ # "receipt": "https://api.swiftype.com/api/v1/document_receipts/5473d6142ed96065a9000001.json",
320
+ # "document": null
321
+ # }
322
+ # },
323
+ # {
324
+ # "id": "5473d6342ed96065a9000002",
325
+ # "external_id": "dMH0bHeiRNg",
326
+ # "status": "pending",
327
+ # "errors": [],
328
+ # "links": {
329
+ # "receipt": "https://api.swiftype.com/api/v1/document_receipts/5473d6142ed96065a9000002.json",
330
+ # "document": null
331
+ # }
332
+ # }
333
+ # ]
334
+ # }
335
+ ```
279
336
 
280
337
  To check the status of documents with their document_receipt ids:
281
338
 
339
+ ```ruby
282
340
  response = client.document_receipts(["5473d6142ed96065a9000001", "5473d6342ed96065a9000002"])
283
- #=> [
284
- {
285
- "id": "5473d6142ed96065a9000001",
286
- "external_id": "FHtvDA0W34I",
287
- "status": "complete",
288
- "errors": [],
289
- "links": {
290
- "receipt": "https://api.swiftype.com/api/v1/document_receipts/5473d6142ed96065a9000001.json",
291
- "document": "https://api.swiftype.com/api/v1/engine/xyz/document_type/abc/document/5473d6142ed96065a9000001.json"
292
- }
293
- },
294
- {
295
- "id": "5473d6142ed96065a9000002",
296
- "external_id": "dMH0bHeiRNg",
297
- "status": "complete",
298
- "errors": [],
299
- "links": {
300
- "receipt": "https://api.swiftype.com/api/v1/document_receipts/5473d6142ed96065a9000001.json",
301
- "document": "https://api.swiftype.com/api/v1/engine/xyz/document_type/abc/document/5473d6142ed96065a9000002.json"
302
- }
303
- }
304
- ]
341
+ #=>
342
+ # [
343
+ # {
344
+ # "id": "5473d6142ed96065a9000001",
345
+ # "external_id": "FHtvDA0W34I",
346
+ # "status": "complete",
347
+ # "errors": [],
348
+ # "links": {
349
+ # "receipt": "https://api.swiftype.com/api/v1/document_receipts/5473d6142ed96065a9000001.json",
350
+ # "document": "https://api.swiftype.com/api/v1/engine/xyz/document_type/abc/document/5473d6142ed96065a9000001.json"
351
+ # }
352
+ # },
353
+ # {
354
+ # "id": "5473d6142ed96065a9000002",
355
+ # "external_id": "dMH0bHeiRNg",
356
+ # "status": "complete",
357
+ # "errors": [],
358
+ # "links": {
359
+ # "receipt": "https://api.swiftype.com/api/v1/document_receipts/5473d6142ed96065a9000001.json",
360
+ # "document": "https://api.swiftype.com/api/v1/engine/xyz/document_type/abc/document/5473d6142ed96065a9000002.json"
361
+ # }
362
+ # }
363
+ # ]
364
+ ```
305
365
 
306
366
  Destroy a Document by external_id:
307
367
 
308
- client.destroy_document('site-search-api-example','videos','dFs9WO2B8uI')
368
+ ```ruby
369
+ client.destroy_document('site-search-api-example','videos','dFs9WO2B8uI')
370
+ ```
309
371
 
310
372
  Destroy multiple Documents at once:
311
373
 
312
- response = client.destroy_documents('site-search-api-example', 'videos', ['QH2-TGUlwu4, 'v1uyQZNg2vE', 'ik5sdwYZ01Q'])
313
- #=> [true, true, true]
374
+ ```ruby
375
+ response = client.destroy_documents('site-search-api-example', 'videos', ['QH2-TGUlwu4, 'v1uyQZNg2vE', 'ik5sdwYZ01Q'])
376
+ #=> [true, true, true]
377
+ ```
314
378
 
315
379
  ### Domains
316
380
 
@@ -318,29 +382,41 @@ Destroy multiple Documents at once:
318
382
 
319
383
  Retrieve all Domains of Engine `websites`:
320
384
 
321
- domains = client.domains('websites')
322
- #=> [{"id"=>"513fcc042ed960c186000001", "engine_id"=>"513fcc042ed960114400000d", "submitted_url"=>"http://example.com/", "start_crawl_url"=>"http://www.example.com/", "crawling"=>false, "document_count"=>337, "updated_at"=>"2013-03-13T00:48:32Z"}, ...]
385
+ ```ruby
386
+ domains = client.domains('websites')
387
+ #=> [{"id"=>"513fcc042ed960c186000001", "engine_id"=>"513fcc042ed960114400000d", "submitted_url"=>"http://example.com/", "start_crawl_url"=>"http://www.example.com/", "crawling"=>false, "document_count"=>337, "updated_at"=>"2013-03-13T00:48:32Z"}, ...]
388
+ ```
323
389
 
324
390
  Retrieve a specific Domain by `id`:
325
391
 
326
- domain = client.domain('websites', '513fcc042ed960c186000001'')
327
- #=> {"id"=>"513fcc042ed960c186000001", "engine_id"=>"513fcc042ed960114400000d", "submitted_url"=>"http://example.com/", "start_crawl_url"=>"http://www.example.com/", "crawling"=>false, "document_count"=>337, "updated_at"=>"2013-03-13T00:48:32Z"}
392
+ ```ruby
393
+ domain = client.domain('websites', '513fcc042ed960c186000001'')
394
+ #=> {"id"=>"513fcc042ed960c186000001", "engine_id"=>"513fcc042ed960114400000d", "submitted_url"=>"http://example.com/", "start_crawl_url"=>"http://www.example.com/", "crawling"=>false, "document_count"=>337, "updated_at"=>"2013-03-13T00:48:32Z"}
395
+ ```
328
396
 
329
397
  Create a new Domain with the URL `https://swiftype.com` and start crawling:
330
398
 
331
- domain = client.create_domain('websites', 'https://swiftype.com')
399
+ ```ruby
400
+ domain = client.create_domain('websites', 'https://swiftype.com')
401
+ ```
332
402
 
333
403
  Delete a Domain using its `id`:
334
404
 
335
- client.destroy_domain('websites', '513fcc042ed960c186000001')
405
+ ```ruby
406
+ client.destroy_domain('websites', '513fcc042ed960c186000001')
407
+ ```
336
408
 
337
409
  Initiate a recrawl of a specific Domain using its `id`:
338
410
 
339
- client.recrawl_domain('websites', '513fcc042ed960c186000001')
411
+ ```ruby
412
+ client.recrawl_domain('websites', '513fcc042ed960c186000001')
413
+ ```
340
414
 
341
415
  Add or update a URL for a Domain:
342
416
 
343
- client.crawl_url('websites', '513fcc042ed960c186000001', 'https://swiftype.com/new/path.html')
417
+ ```ruby
418
+ client.crawl_url('websites', '513fcc042ed960c186000001', 'https://swiftype.com/new/path.html')
419
+ ```
344
420
 
345
421
  ### Analytics
346
422
 
@@ -348,41 +424,59 @@ Site Search records the number of searches, autoselects (when a user clicks a li
348
424
 
349
425
  To get the number of searches per day from an Engine in the last 14 days:
350
426
 
351
- searches = client.analytics_searches('site-search-api-example')
352
- #=> [['2013-09-13', '123'], [2013-09-12', '94'], ... ]
427
+ ```ruby
428
+ searches = client.analytics_searches('site-search-api-example')
429
+ #=> [['2013-09-13', '123'], [2013-09-12', '94'], ... ]
430
+ ```
353
431
 
354
432
  You can also use a specific start and/or end date:
355
433
 
356
- searches = client.analytics_searches('site-search-api-example', {:start_date => '2013-01-01', :end_date => '2013-01-07'})
434
+ ```ruby
435
+ searches = client.analytics_searches('site-search-api-example', {:start_date => '2013-01-01', :end_date => '2013-01-07'})
436
+ ```
357
437
 
358
438
  To get the number of autoselects in the past 14 days:
359
439
 
360
- autoselects = client.analytics_autoselects('site-search-api-example')
440
+ ```ruby
441
+ autoselects = client.analytics_autoselects('site-search-api-example')
442
+ ```
361
443
 
362
444
  As with searches you can also limit by start and/or end date:
363
445
 
364
- autoselects = client.analytics_autoselects('site-search-api-example', {:start_date => '2013-01-01', :end_date => '2013-01-07'})
446
+ ```ruby
447
+ autoselects = client.analytics_autoselects('site-search-api-example', {:start_date => '2013-01-01', :end_date => '2013-01-07'})
448
+ ```
365
449
 
366
450
  If you are interested in the top queries for your Engine you can use:
367
451
 
368
- top_queries = client.analytics_top_queries('site-search-api-example')
369
- # => [['query term', 123], ['another query', 121], ['yet another query', 92], ...]
452
+ ```ruby
453
+ top_queries = client.analytics_top_queries('site-search-api-example')
454
+ # => [['query term', 123], ['another query', 121], ['yet another query', 92], ...]
455
+ ```
370
456
 
371
457
  To see more top queries you can paginate through them using:
372
458
 
373
- top_queries = client.analytics_top_queries('site-search-api-example', {:page => 2})
459
+ ```ruby
460
+ top_queries = client.analytics_top_queries('site-search-api-example', {:page => 2})
461
+ ```
374
462
 
375
463
  Or you can get the top queries in a specific date range:
376
464
 
377
- top_queries = client.analytics_top_queries('site-search-api-example', {:start_date => '2013-01-01', :end_date => '2013-01-07'})
465
+ ```ruby
466
+ top_queries = client.analytics_top_queries('site-search-api-example', {:start_date => '2013-01-01', :end_date => '2013-01-07'})
467
+ ```
378
468
 
379
469
  If you want to improve you search results, you should always have a look at search queries, that return no results and perhaps add some Documents that match for this query or use our pining feature to add Documents for this query:
380
470
 
381
- top_no_result_queries = client.analytics_top_no_result_queries('site-search-api-example')
471
+ ```ruby
472
+ top_no_result_queries = client.analytics_top_no_result_queries('site-search-api-example')
473
+ ```
382
474
 
383
475
  You can also specifiy a date range for queries without results:
384
476
 
385
- top_no_result_queries = client.analytics_top_no_result_queries('site-search-api-example', {:start_date => '2013-01-01', :end_date => '2013-01-07'})
477
+ ```ruby
478
+ top_no_result_queries = client.analytics_top_no_result_queries('site-search-api-example', {:start_date => '2013-01-01', :end_date => '2013-01-07'})
479
+ ```
386
480
 
387
481
  ## Development
388
482
 
@@ -1,4 +1,4 @@
1
- require 'digest/sha1'
1
+ require 'digest/sha2'
2
2
 
3
3
  module Elastic
4
4
  module SiteSearch
@@ -15,7 +15,7 @@ module Elastic
15
15
  end
16
16
 
17
17
  def self.token(user_id, timestamp)
18
- Digest::SHA1.hexdigest("#{user_id}:#{Elastic::SiteSearch.platform_client_secret}:#{timestamp}")
18
+ Digest::SHA256.hexdigest("#{user_id}:#{Elastic::SiteSearch.platform_client_secret}:#{timestamp}")
19
19
  end
20
20
  end
21
21
  end
@@ -1,5 +1,5 @@
1
1
  module Elastic
2
2
  module SiteSearch
3
- VERSION = "2.1.0"
3
+ VERSION = "2.2.0"
4
4
  end
5
5
  end
data/spec/sso_spec.rb CHANGED
@@ -11,14 +11,14 @@ describe Elastic::SiteSearch::SSO do
11
11
  end
12
12
 
13
13
  context '.token' do
14
- it 'generates an SSO token' do
15
- expect(Elastic::SiteSearch::SSO.token(user_id, timestamp)).to eq('81033d182ad51f231cc9cda9fb24f2298a411437')
14
+ it 'generates a proper SHA256 SSO token' do
15
+ expect(Elastic::SiteSearch::SSO.token(user_id, timestamp)).to eq('3da93f6d82efc8530614966ab847fd6d0b6d158ef02e4e65a8f731e299c28d86')
16
16
  end
17
17
  end
18
18
 
19
19
  context '.url' do
20
20
  it 'generates an SSO URL' do
21
- expect(Elastic::SiteSearch::SSO.url(user_id)).to eq('https://swiftype.com/sso?user_id=5064a7de2ed960e715000276&client_id=3e4fd842fc99aecb4dc50e5b88a186c1e206ddd516cdd336da3622c4afd7e2e9&timestamp=1379382520&token=81033d182ad51f231cc9cda9fb24f2298a411437')
21
+ expect(Elastic::SiteSearch::SSO.url(user_id)).to eq('https://swiftype.com/sso?user_id=5064a7de2ed960e715000276&client_id=3e4fd842fc99aecb4dc50e5b88a186c1e206ddd516cdd336da3622c4afd7e2e9&timestamp=1379382520&token=3da93f6d82efc8530614966ab847fd6d0b6d158ef02e4e65a8f731e299c28d86')
22
22
  end
23
23
  end
24
24
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elastic-site-search
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Quin Hoxie
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-09-09 00:00:00.000000000 Z
12
+ date: 2023-03-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -193,8 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
193
193
  - !ruby/object:Gem::Version
194
194
  version: '0'
195
195
  requirements: []
196
- rubyforge_project:
197
- rubygems_version: 2.7.6
196
+ rubygems_version: 3.0.3
198
197
  signing_key:
199
198
  specification_version: 4
200
199
  summary: Official gem for accessing the Elastic Site Search API