elastic-site-search 2.0.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +20 -9
- data/README.md +232 -138
- data/lib/elastic/site-search/exceptions.rb +6 -0
- data/lib/elastic/site-search/request.rb +18 -10
- data/lib/elastic/site-search/sso.rb +2 -2
- data/lib/elastic/site-search/version.rb +1 -1
- data/lib/elastic-site-search.rb +1 -0
- data/spec/sso_spec.rb +3 -3
- metadata +4 -4
- data/.travis.yml +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5981e7c63cf7474d20008bbf06886e770e155428379de2a873499b8e5bda4e26
|
4
|
+
data.tar.gz: 4ab08fab6691807b3a6d2e25798ddece63c6635e091bd659b77d38a0522ab916
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 79a6075cd55f86e9dccaeaa31d306a9c1ea4b0b90708239cd6439b3515b1d42a7d74c7acbf30a52a89faae3dfed03dd645afa17ac540c5c6137c717ab0ad2dc3
|
7
|
+
data.tar.gz: ae1d85615cfe15a7f4c70866faf0650226aefb6101e86754d8ece73e710f74cd33532f21545e5a43572d4bef771d18751d590e7f6b09c338426ac115562e014d
|
data/.circleci/config.yml
CHANGED
@@ -2,17 +2,20 @@
|
|
2
2
|
#
|
3
3
|
# Check https://circleci.com/docs/2.0/language-ruby/ for more details
|
4
4
|
#
|
5
|
-
version: 2
|
5
|
+
version: 2.1
|
6
|
+
|
7
|
+
executors:
|
8
|
+
ruby-24: { docker: [{ image: "ruby:2.4" }] }
|
9
|
+
ruby-25: { docker: [{ image: "ruby:2.5" }] }
|
10
|
+
ruby-26: { docker: [{ image: "ruby:2.6" }] }
|
11
|
+
jruby-92: { docker: [{ image: "jruby:9.2.7-jdk" }] }
|
12
|
+
|
6
13
|
jobs:
|
7
14
|
build:
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
# Specify service dependencies here if necessary
|
13
|
-
# CircleCI maintains a library of pre-built images
|
14
|
-
# documented at https://circleci.com/docs/2.0/circleci-images/
|
15
|
-
# - image: circleci/postgres:9.4
|
15
|
+
parameters:
|
16
|
+
executor:
|
17
|
+
type: executor
|
18
|
+
executor: << parameters.executor >>
|
16
19
|
|
17
20
|
working_directory: ~/repo
|
18
21
|
|
@@ -56,3 +59,11 @@ jobs:
|
|
56
59
|
- store_artifacts:
|
57
60
|
path: /tmp/test-results
|
58
61
|
destination: test-results
|
62
|
+
|
63
|
+
workflows:
|
64
|
+
run-tests:
|
65
|
+
jobs:
|
66
|
+
- build: { name: run-tests-ruby-2.4, executor: ruby-24 }
|
67
|
+
- build: { name: run-tests-ruby-2.5, executor: ruby-25 }
|
68
|
+
- build: { name: run-tests-ruby-2.6, executor: ruby-26 }
|
69
|
+
- build: { name: run-tests-jruby-92, executor: jruby-92 }
|
data/README.md
CHANGED
@@ -44,9 +44,11 @@ Depends on Ruby.
|
|
44
44
|
|
45
45
|
To install the gem, execute:
|
46
46
|
|
47
|
-
|
47
|
+
```shell
|
48
|
+
gem install elastic-site-search
|
49
|
+
```
|
48
50
|
|
49
|
-
Or place `gem 'elastic-site-search', '~> 2.
|
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.0.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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
84
|
-
|
85
|
-
|
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
|
-
|
90
|
-
|
91
|
-
|
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
|
-
|
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
|
-
|
106
|
-
|
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
|
-
|
111
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
130
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
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
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
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
|
-
|
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
|
-
|
207
|
-
|
208
|
-
|
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
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
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
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
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
|
-
|
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
|
-
|
313
|
-
|
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
|
-
|
322
|
-
|
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
|
-
|
327
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
411
|
+
```ruby
|
412
|
+
client.recrawl_domain('websites', '513fcc042ed960c186000001')
|
413
|
+
```
|
340
414
|
|
341
415
|
Add or update a URL for a Domain:
|
342
416
|
|
343
|
-
|
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
|
-
|
352
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
369
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
|
@@ -7,5 +7,11 @@ module Elastic
|
|
7
7
|
class BadRequest < ClientException; end
|
8
8
|
class Forbidden < ClientException; end
|
9
9
|
class UnexpectedHTTPException < ClientException; end
|
10
|
+
|
11
|
+
class ServerException < StandardError; end
|
12
|
+
class InternalServerError < ServerException; end
|
13
|
+
class BadGateway < ServerException; end
|
14
|
+
class ServiceUnavailable < ServerException; end
|
15
|
+
class GatewayTimeout < ServerException; end
|
10
16
|
end
|
11
17
|
end
|
@@ -93,21 +93,29 @@ module Elastic
|
|
93
93
|
case response
|
94
94
|
when Net::HTTPSuccess
|
95
95
|
response
|
96
|
-
when Net::HTTPUnauthorized
|
97
|
-
raise Elastic::SiteSearch::InvalidCredentials, error_message_from_response(response)
|
98
|
-
when Net::HTTPNotFound
|
99
|
-
raise Elastic::SiteSearch::NonExistentRecord, error_message_from_response(response)
|
100
|
-
when Net::HTTPConflict
|
101
|
-
raise Elastic::SiteSearch::RecordAlreadyExists, error_message_from_response(response)
|
102
|
-
when Net::HTTPBadRequest
|
103
|
-
raise Elastic::SiteSearch::BadRequest, error_message_from_response(response)
|
104
|
-
when Net::HTTPForbidden
|
105
|
-
raise Elastic::SiteSearch::Forbidden, error_message_from_response(response)
|
106
96
|
else
|
97
|
+
EXCEPTION_MAP.each do |response_class, exception_class|
|
98
|
+
if response.is_a?(response_class)
|
99
|
+
raise exception_class, error_message_from_response(response)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
107
103
|
raise Elastic::SiteSearch::UnexpectedHTTPException, "#{response.code} #{response.body}"
|
108
104
|
end
|
109
105
|
end
|
110
106
|
|
107
|
+
EXCEPTION_MAP = {
|
108
|
+
Net::HTTPUnauthorized => Elastic::SiteSearch::InvalidCredentials,
|
109
|
+
Net::HTTPNotFound => Elastic::SiteSearch::NonExistentRecord,
|
110
|
+
Net::HTTPConflict => Elastic::SiteSearch::RecordAlreadyExists,
|
111
|
+
Net::HTTPBadRequest => Elastic::SiteSearch::BadRequest,
|
112
|
+
Net::HTTPForbidden => Elastic::SiteSearch::Forbidden,
|
113
|
+
Net::HTTPInternalServerError => Elastic::SiteSearch::InternalServerError,
|
114
|
+
Net::HTTPBadGateway => Elastic::SiteSearch::BadGateway,
|
115
|
+
Net::HTTPServiceUnavailable => Elastic::SiteSearch::ServiceUnavailable,
|
116
|
+
Net::HTTPGatewayTimeOut => Elastic::SiteSearch::GatewayTimeout
|
117
|
+
}.freeze
|
118
|
+
|
111
119
|
def error_message_from_response(response)
|
112
120
|
body = response.body
|
113
121
|
json = JSON.parse(body) if body && body.strip != ''
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'digest/
|
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::
|
18
|
+
Digest::SHA256.hexdigest("#{user_id}:#{Elastic::SiteSearch.platform_client_secret}:#{timestamp}")
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'elastic/site-search'
|
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
|
15
|
-
expect(Elastic::SiteSearch::SSO.token(user_id, timestamp)).to eq('
|
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×tamp=1379382520&token=
|
21
|
+
expect(Elastic::SiteSearch::SSO.url(user_id)).to eq('https://swiftype.com/sso?user_id=5064a7de2ed960e715000276&client_id=3e4fd842fc99aecb4dc50e5b88a186c1e206ddd516cdd336da3622c4afd7e2e9×tamp=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.
|
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:
|
12
|
+
date: 2023-03-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -77,7 +77,6 @@ extra_rdoc_files: []
|
|
77
77
|
files:
|
78
78
|
- ".circleci/config.yml"
|
79
79
|
- ".gitignore"
|
80
|
-
- ".travis.yml"
|
81
80
|
- Gemfile
|
82
81
|
- LICENSE.txt
|
83
82
|
- NOTICE.txt
|
@@ -85,6 +84,7 @@ files:
|
|
85
84
|
- Rakefile
|
86
85
|
- elastic-site-search.gemspec
|
87
86
|
- lib/data/ca-bundle.crt
|
87
|
+
- lib/elastic-site-search.rb
|
88
88
|
- lib/elastic/site-search.rb
|
89
89
|
- lib/elastic/site-search/client.rb
|
90
90
|
- lib/elastic/site-search/configuration.rb
|
@@ -193,7 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
193
193
|
- !ruby/object:Gem::Version
|
194
194
|
version: '0'
|
195
195
|
requirements: []
|
196
|
-
rubygems_version: 3.0.
|
196
|
+
rubygems_version: 3.0.3
|
197
197
|
signing_key:
|
198
198
|
specification_version: 4
|
199
199
|
summary: Official gem for accessing the Elastic Site Search API
|