elastic-site-search 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. checksums.yaml +7 -0
  2. data/.circleci/config.yml +58 -0
  3. data/.gitignore +10 -0
  4. data/.travis.yml +13 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +201 -0
  7. data/NOTICE.txt +3 -0
  8. data/README.md +418 -0
  9. data/Rakefile +1 -0
  10. data/elastic-site-search.gemspec +26 -0
  11. data/lib/data/ca-bundle.crt +3554 -0
  12. data/lib/elastic/site-search.rb +9 -0
  13. data/lib/elastic/site-search/client.rb +527 -0
  14. data/lib/elastic/site-search/configuration.rb +67 -0
  15. data/lib/elastic/site-search/exceptions.rb +11 -0
  16. data/lib/elastic/site-search/ext/backport-uri.rb +33 -0
  17. data/lib/elastic/site-search/request.rb +156 -0
  18. data/lib/elastic/site-search/result_set.rb +84 -0
  19. data/lib/elastic/site-search/sso.rb +22 -0
  20. data/lib/elastic/site-search/version.rb +5 -0
  21. data/logo-site-search.png +0 -0
  22. data/spec/client_spec.rb +728 -0
  23. data/spec/configuration_spec.rb +37 -0
  24. data/spec/fixtures/vcr/analytics_autoselects.yml +57 -0
  25. data/spec/fixtures/vcr/analytics_autoselects_with_document_type.yml +57 -0
  26. data/spec/fixtures/vcr/analytics_autoselects_with_document_type_and_time_range.yml +57 -0
  27. data/spec/fixtures/vcr/analytics_autoselects_with_time_range.yml +57 -0
  28. data/spec/fixtures/vcr/analytics_clicks.yml +57 -0
  29. data/spec/fixtures/vcr/analytics_clicks_with_document_type.yml +57 -0
  30. data/spec/fixtures/vcr/analytics_clicks_with_document_type_and_time_range.yml +57 -0
  31. data/spec/fixtures/vcr/analytics_clicks_with_time_range.yml +57 -0
  32. data/spec/fixtures/vcr/analytics_searches.yml +57 -0
  33. data/spec/fixtures/vcr/analytics_searches_with_document_type_and_time_range.yml +57 -0
  34. data/spec/fixtures/vcr/analytics_searches_with_time_range.yml +57 -0
  35. data/spec/fixtures/vcr/analytics_searchs_with_document_type.yml +57 -0
  36. data/spec/fixtures/vcr/analytics_top_no_result_queries.yml +57 -0
  37. data/spec/fixtures/vcr/analytics_top_no_result_queries_paginated.yml +57 -0
  38. data/spec/fixtures/vcr/analytics_top_queries.yml +57 -0
  39. data/spec/fixtures/vcr/analytics_top_queries_paginated.yml +57 -0
  40. data/spec/fixtures/vcr/analytics_top_queries_too_large.yml +53 -0
  41. data/spec/fixtures/vcr/async_create_or_update_document_failure.yml +48 -0
  42. data/spec/fixtures/vcr/async_create_or_update_document_success.yml +52 -0
  43. data/spec/fixtures/vcr/bulk_create_documents.yml +52 -0
  44. data/spec/fixtures/vcr/bulk_create_or_update_documents_failure.yml +47 -0
  45. data/spec/fixtures/vcr/bulk_create_or_update_documents_success.yml +52 -0
  46. data/spec/fixtures/vcr/bulk_create_or_update_documents_verbose_failure.yml +47 -0
  47. data/spec/fixtures/vcr/bulk_create_or_update_documents_verbose_success.yml +52 -0
  48. data/spec/fixtures/vcr/bulk_destroy_documents.yml +47 -0
  49. data/spec/fixtures/vcr/crawl_url.yml +47 -0
  50. data/spec/fixtures/vcr/create_document.yml +52 -0
  51. data/spec/fixtures/vcr/create_document_type.yml +47 -0
  52. data/spec/fixtures/vcr/create_domain.yml +47 -0
  53. data/spec/fixtures/vcr/create_engine.yml +47 -0
  54. data/spec/fixtures/vcr/create_or_update_document_create.yml +51 -0
  55. data/spec/fixtures/vcr/create_or_update_document_update.yml +51 -0
  56. data/spec/fixtures/vcr/create_user.yml +47 -0
  57. data/spec/fixtures/vcr/destroy_document.yml +43 -0
  58. data/spec/fixtures/vcr/destroy_document_type.yml +43 -0
  59. data/spec/fixtures/vcr/destroy_domain.yml +43 -0
  60. data/spec/fixtures/vcr/destroy_engine.yml +43 -0
  61. data/spec/fixtures/vcr/destroy_non_existent_document_type.yml +45 -0
  62. data/spec/fixtures/vcr/document_receipts_multiple.yml +48 -0
  63. data/spec/fixtures/vcr/document_receipts_multiple_complete.yml +48 -0
  64. data/spec/fixtures/vcr/document_type_search.yml +63 -0
  65. data/spec/fixtures/vcr/document_type_search_pagination.yml +47 -0
  66. data/spec/fixtures/vcr/document_type_suggest.yml +52 -0
  67. data/spec/fixtures/vcr/document_type_suggest_pagination.yml +47 -0
  68. data/spec/fixtures/vcr/engine_search.yml +67 -0
  69. data/spec/fixtures/vcr/engine_search_facets.yml +164 -0
  70. data/spec/fixtures/vcr/engine_search_pagination.yml +47 -0
  71. data/spec/fixtures/vcr/engine_suggest.yml +55 -0
  72. data/spec/fixtures/vcr/engine_suggest_pagination.yml +47 -0
  73. data/spec/fixtures/vcr/find_document.yml +50 -0
  74. data/spec/fixtures/vcr/find_document_type.yml +47 -0
  75. data/spec/fixtures/vcr/find_domain.yml +47 -0
  76. data/spec/fixtures/vcr/find_domain_failure.yml +45 -0
  77. data/spec/fixtures/vcr/find_engine.yml +47 -0
  78. data/spec/fixtures/vcr/list_document_type.yml +47 -0
  79. data/spec/fixtures/vcr/list_documents.yml +71 -0
  80. data/spec/fixtures/vcr/list_documents_with_pagination.yml +71 -0
  81. data/spec/fixtures/vcr/list_domains.yml +47 -0
  82. data/spec/fixtures/vcr/list_engines.yml +48 -0
  83. data/spec/fixtures/vcr/list_users.yml +47 -0
  84. data/spec/fixtures/vcr/list_users_with_pagination.yml +47 -0
  85. data/spec/fixtures/vcr/log_clickthrough_failure.yml +45 -0
  86. data/spec/fixtures/vcr/log_clickthrough_success.yml +47 -0
  87. data/spec/fixtures/vcr/recrawl_domain_failure.yml +46 -0
  88. data/spec/fixtures/vcr/recrawl_domain_success.yml +47 -0
  89. data/spec/fixtures/vcr/show_user.yml +47 -0
  90. data/spec/fixtures/vcr/update_document.yml +50 -0
  91. data/spec/fixtures/vcr/update_document_unknown_field_failure.yml +48 -0
  92. data/spec/fixtures/vcr/update_documents_failure_non_existent_document.yml +47 -0
  93. data/spec/fixtures/vcr/update_documents_success.yml +47 -0
  94. data/spec/fixtures/vcr/users_client_secret_incorrect.yml +44 -0
  95. data/spec/fixtures/vcr/users_no_api_key.yml +44 -0
  96. data/spec/fixtures/vcr/users_no_client_id_or_secret.yml +45 -0
  97. data/spec/platform_spec.rb +95 -0
  98. data/spec/spec_helper.rb +27 -0
  99. data/spec/ssl_spec.rb +34 -0
  100. data/spec/sso_spec.rb +24 -0
  101. metadata +279 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 783fde51a3b94285bcc1516c0305807d1298ca1430cefc878c9503faeb516b11
4
+ data.tar.gz: bd640f5a1896286dae00d682143b33d312ded42e88497515af1f969b6d6c806f
5
+ SHA512:
6
+ metadata.gz: 8488aea312a337ce19a5ec5908da0a1ce6b96a047a435bca29b79ea770495038be508dec2202365cfd1374a6bb536b1a1a2fc413927a66aa7ccfd93e586c2fcc
7
+ data.tar.gz: d5a5a8094eb77c15f59421b0401e19f259a630c0ee747625a3e7ae49c27b1c1f9340eaa14dd730a405a2ebfe06059c4facd011ecdaf3951a5431927df84e3b82
@@ -0,0 +1,58 @@
1
+ # Ruby CircleCI 2.0 configuration file
2
+ #
3
+ # Check https://circleci.com/docs/2.0/language-ruby/ for more details
4
+ #
5
+ version: 2
6
+ jobs:
7
+ build:
8
+ docker:
9
+ # specify the version you desire here
10
+ - image: circleci/ruby:2.4.1-node-browsers
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
16
+
17
+ working_directory: ~/repo
18
+
19
+ steps:
20
+ - checkout
21
+
22
+ # Download and cache dependencies
23
+ - restore_cache:
24
+ keys:
25
+ - v1-dependencies-{{ checksum "Gemfile" }}
26
+ # fallback to using the latest cache if no exact match is found
27
+ - v1-dependencies-
28
+
29
+ - run:
30
+ name: install dependencies
31
+ command: |
32
+ bundle install --jobs=4 --retry=3 --path vendor/bundle
33
+
34
+ - save_cache:
35
+ paths:
36
+ - ./vendor/bundle
37
+ key: v1-dependencies-{{ checksum "Gemfile" }}
38
+
39
+ # run tests!
40
+ - run:
41
+ name: run tests
42
+ command: |
43
+ mkdir /tmp/test-results
44
+ TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | \
45
+ circleci tests split --split-by=timings)"
46
+
47
+ bundle exec rspec \
48
+ --format progress \
49
+ --out /tmp/test-results/rspec.xml \
50
+ --format progress \
51
+ $TEST_FILES
52
+
53
+ # collect reports
54
+ - store_test_results:
55
+ path: /tmp/test-results
56
+ - store_artifacts:
57
+ path: /tmp/test-results
58
+ destination: test-results
@@ -0,0 +1,10 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .DS_Store
6
+ .rvmrc
7
+ .ruby-version
8
+ .ruby-gemset
9
+ .yardoc
10
+ doc
@@ -0,0 +1,13 @@
1
+ language: ruby
2
+ script: rspec
3
+ rvm:
4
+ - 2.0
5
+ - 2.1
6
+ - 2.2
7
+ - jruby
8
+ jdk:
9
+ - oraclejdk8
10
+
11
+ before_install:
12
+ - gem --version
13
+ - gem update bundler
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in elastic-site-search-ruby.gemspec
4
+ gemspec
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2019 Elasticsearch B.V.
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,3 @@
1
+ Elastic Site Search Ruby client.
2
+
3
+ Copyright 2012-2019 Elasticsearch B.V.
@@ -0,0 +1,418 @@
1
+ <p align="center"><img src="https://github.com/elastic/site-search-ruby/blob/master/logo-site-search.png?raw=true" alt="Elastic Site Search Logo"></p>
2
+
3
+ <p align="center"><a href="https://circleci.com/gh/elastic/site-search-ruby"><img src="https://circleci.com/gh/elastic/site-search-ruby.svg?style=svg" alt="CircleCI build"></a></p>
4
+
5
+ > A first-party Ruby client for the [Elastic Site Search API](https://swiftype.com/documentation/site-search/overview).
6
+
7
+ ## Contents
8
+
9
+ - [Getting started](#getting-started-)
10
+ - [Usage](#usage)
11
+ - [Migrating from pervious versions](#migrating-from-previous-versions)
12
+ - [Development](#development)
13
+ - [FAQ](#faq-)
14
+ - [Contribute](#contribute-)
15
+ - [License](#license-)
16
+
17
+ ---
18
+
19
+ ## Getting started 🐣
20
+
21
+ Before beginning with the `elastic-site-search` gem, you should be familiar with the concepts behind the Elastic Site Search API:
22
+
23
+ 1. **Engines**
24
+ 2. **DocumentTypes**
25
+ 3. **Documents**
26
+
27
+ An **Engine** is a search engine.
28
+
29
+ It can contain one or more **DocumentTypes** which are collections of **Documents**.
30
+
31
+ A **Document** is a collection of fields that can be queried using the Site Search API.
32
+
33
+ Documents have a special **external_id** field that ties a Document in Site Search to a record in your system. The layout of fields of the Documents belonging to a DocumentType is called a **schema**. Fields may be strings, integers, geographic locations, and so forth.
34
+
35
+ The Documents in your Engine can be searched two ways: **full-text** (`search`) or **autocomplete** (`suggest`). The difference is that autocomplete queries work on prefixes (for example, "gla" will match "glass"). This is less accurate in general, but is useful for implementing type-ahead search drop downs.
36
+
37
+ You can think of an Engine as a database, DocumentTypes as tables, and Documents as rows. Using the API, you can search an Engine for all Documents containing a word. You can also search an individual DocumentType, or any subset of DocumentTypes.
38
+
39
+ The examples in this documentation use the schema defined in the [site-search-api-example](https://github.com/swiftype/swiftype-api-example) project, which is based on YouTube. It has two DocumentTypes, **videos** and **channels**. Using the script found in the site-search-api-example project, you can create your own search engine that matches the examples and try the queries for yourself.
40
+
41
+ To learn more about the Site Search API, read the [API overview](https://swiftype.com/documentation/site-search/overview) and our [schema design tutorial](https://swiftype.com/documentation/site-search/guides/schema-design).
42
+
43
+ Depends on Ruby.
44
+
45
+ To install the gem, execute:
46
+
47
+ gem install elastic-site-search
48
+
49
+ Or place `gem 'elastic-site-search', '~> 2.0.0` in your `Gemfile` and run `bundle install`.
50
+
51
+ > **Note:** This client has been developed for the [Elastic Site Search](https://www.elastic.co/products/site-search/service) API endpoints only.
52
+
53
+ ## Usage
54
+
55
+ ### Configuration:
56
+
57
+ Before issuing commands to the API, configure the client with your API key:
58
+
59
+ Elastic::SiteSearch.api_key = 'YOUR_API_KEY'
60
+
61
+ You can find your API key in your [Account Settings](https://app.swiftype.com/settings/account).
62
+
63
+ ### Create a client
64
+
65
+ client = Elastic::SiteSearch::Client.new
66
+
67
+ You can also provide the API key when creating the client instance:
68
+
69
+ client = Elastic::SiteSearch::Client.new(:api_key => 'different_api_key')
70
+
71
+ If the API key is provided as an option to constructor, it will override the globally configured Elastic::SiteSearch API key (if any).
72
+
73
+ ### Specifying an HTTP Proxy
74
+
75
+ client = Elastic::SiteSearch::Client.new(:api_key => 'api_key', :proxy => 'http://localhost:8888')
76
+
77
+ This client will also support configuring a proxy via the environment variable `http_proxy`.
78
+
79
+ ### Full-text search
80
+
81
+ If you want to search for `cat` on your engine, you can use:
82
+
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', ... }, ... ]
86
+
87
+ To limit the search to only the `videos` DocumentType:
88
+
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
92
+
93
+ 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
+
95
+ Here is an example for showing only videos in the "Pets & Animals" category (which has ID 23):
96
+
97
+ results = client.search_document_type('site-search-api-example', 'videos', 'cat', {:filters => {'videos' => {:category_id => '23'}}})
98
+
99
+ ### Autocomplete search
100
+
101
+ Autocomplete (also known as suggest, prefix, or type-ahead) searches can be used to implement autocompletion. They have the same functionality as full-text searches, but work on prefixes instead of all the text. Because of this, autocomplete queries only search string fields.
102
+
103
+ You can perform a suggest query across all of your Engine's Documents:
104
+
105
+ results = client.suggest("site-search-api-example", "gla")
106
+ results['videos'] # => [{'external_id' => 'v1uyQZNg2vE', 'title' => 'How It Feels [through Glass]', ...}, ...]
107
+
108
+ or just for one DocumentType:
109
+
110
+ results = client.suggest_document_type("site-search-api-example", "videos", "gla")
111
+ results['videos'] # => [{'external_id' => 'v1uyQZNg2vE', 'title' => 'How It Feels [through Glass]', ...}, ...]
112
+
113
+ or add options to have more control over the results:
114
+
115
+ results = client.suggest('site-search-api-example', 'glass', {:sort_field => {'videos' => 'view_count'}, :sort_direction => {'videos' => 'desc'}})
116
+
117
+ ### Engines
118
+
119
+ Retrieve every Engine:
120
+
121
+ engines = client.engines
122
+
123
+ Create a new Engine with the name `site-search-api-example`:
124
+
125
+ engine = client.create_engine('site-search-api-example')
126
+
127
+ Retrieve an Engine by `slug` or `id`:
128
+
129
+ engine = client.engine('site-search-api-example')
130
+ engine = client.engine('5230b9102ed960ba20000021')
131
+
132
+ Delete an Engine by `slug` or the `id`:
133
+
134
+ client.destroy_engine('site-search-api-example')
135
+
136
+ ### Document Types
137
+
138
+ List all the
139
+
140
+ Retrieve `DocumentTypes`s of the Engine with the `slug` field `site-search-api-example`:
141
+
142
+ document_types = client.document_types('site-search-api-example')
143
+
144
+ Show the second batch of documents:
145
+
146
+ document_types = client.document_types('site-search-api-example', 2)
147
+
148
+ Create a new DocumentType for an Engine with the name `videos`:
149
+
150
+ document_type = client.create_document_type('site-search-api-example', 'videos')
151
+
152
+ Retrieve an DocumentType by `slug` or `id`:
153
+
154
+ document_type = client.document_type('site-search-api-example', 'videos')
155
+
156
+ Delete a DocumentType using the `slug` or `id` of it:
157
+
158
+ client.destroy_document_type('site-search-api-example', 'videos')
159
+
160
+ ### Documents
161
+
162
+ Retrieve the first page of Documents of Engine `site-search-api-example` and DocumentType `videos`:
163
+
164
+ documents = client.documents('site-search-api-example', 'videos')
165
+
166
+ Retrieve a specific Document using its `id` or `external_id`:
167
+
168
+ document = client.document('site-search-api-example', 'videos', 'FHtvDA0W34I')
169
+
170
+ To create or update. single or multiple documents, we use the method `index_documents`.
171
+
172
+ Create a new Document with mandatory `external_id` and user-defined fields:
173
+
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
+ ]})
181
+
182
+ Create multiple Documents at once and return status for each Document creation:
183
+
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
+ ]}])
197
+
198
+ Update fields of an existing Document specified by `id` or `external_id`:
199
+
200
+ client.index_documents('site-search-api-example', 'videos', 'FHtvDA0W34I', {:title =>'New Title'})
201
+
202
+ **NOTE:** A field must already exist on a Document in order to update it.
203
+
204
+ Update multiple Documents at once:
205
+
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
+ ])
210
+
211
+ All methods above will have a return in the following format:
212
+
213
+ [
214
+ {
215
+ "id": "5473d6142ed96065a9000001",
216
+ "external_id": "FHtvDA0W34I",
217
+ "status": "complete",
218
+ "errors": [],
219
+ "links": {
220
+ "receipt": "https://api.swiftype.com/api/v1/document_receipts/5473d6142ed96065a9000001.json",
221
+ "document": "https://api.swiftype.com/api/v1/engine/xyz/document_type/abc/document/5473d6142ed96065a9000001.json"
222
+ }
223
+ },
224
+ {
225
+ "id": "5473d6142ed96065a9000002",
226
+ "external_id": "dMH0bHeiRNg",
227
+ "status": "complete",
228
+ "errors": [],
229
+ "links": {
230
+ "receipt": "https://api.swiftype.com/api/v1/document_receipts/5473d6142ed96065a9000001.json",
231
+ "document": "https://api.swiftype.com/api/v1/engine/xyz/document_type/abc/document/5473d6142ed96065a9000002.json"
232
+ }
233
+ }
234
+ ]
235
+
236
+ **NOTE:** If you'd like to create or update documents asynchronously, simply pass the option `:async => true` as the last argument.
237
+
238
+ For instance, to Create multiple Documents at once:
239
+
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
+ }
279
+
280
+ To check the status of documents with their document_receipt ids:
281
+
282
+ 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
+ ]
305
+
306
+ Destroy a Document by external_id:
307
+
308
+ client.destroy_document('site-search-api-example','videos','dFs9WO2B8uI')
309
+
310
+ Destroy multiple Documents at once:
311
+
312
+ response = client.destroy_documents('site-search-api-example', 'videos', ['QH2-TGUlwu4, 'v1uyQZNg2vE', 'ik5sdwYZ01Q'])
313
+ #=> [true, true, true]
314
+
315
+ ### Domains
316
+
317
+ **Domains** are a feature of crawler-based engines that represent a web site to index with the Swiftype web crawler.
318
+
319
+ Retrieve all Domains of Engine `websites`:
320
+
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"}, ...]
323
+
324
+ Retrieve a specific Domain by `id`:
325
+
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"}
328
+
329
+ Create a new Domain with the URL `https://swiftype.com` and start crawling:
330
+
331
+ domain = client.create_domain('websites', 'https://swiftype.com')
332
+
333
+ Delete a Domain using its `id`:
334
+
335
+ client.destroy_domain('websites', '513fcc042ed960c186000001')
336
+
337
+ Initiate a recrawl of a specific Domain using its `id`:
338
+
339
+ client.recrawl_domain('websites', '513fcc042ed960c186000001')
340
+
341
+ Add or update a URL for a Domain:
342
+
343
+ client.crawl_url('websites', '513fcc042ed960c186000001', 'https://swiftype.com/new/path.html')
344
+
345
+ ### Analytics
346
+
347
+ Site Search records the number of searches, autoselects (when a user clicks a link from a suggest result), and clickthroughs (when a user clicks through to an item from a search result list. You can view this information in your Site Search Dashboard, but you can also export it using the API.
348
+
349
+ To get the number of searches per day from an Engine in the last 14 days:
350
+
351
+ searches = client.analytics_searches('site-search-api-example')
352
+ #=> [['2013-09-13', '123'], [2013-09-12', '94'], ... ]
353
+
354
+ You can also use a specific start and/or end date:
355
+
356
+ searches = client.analytics_searches('site-search-api-example', {:start_date => '2013-01-01', :end_date => '2013-01-07'})
357
+
358
+ To get the number of autoselects in the past 14 days:
359
+
360
+ autoselects = client.analytics_autoselects('site-search-api-example')
361
+
362
+ As with searches you can also limit by start and/or end date:
363
+
364
+ autoselects = client.analytics_autoselects('site-search-api-example', {:start_date => '2013-01-01', :end_date => '2013-01-07'})
365
+
366
+ If you are interested in the top queries for your Engine you can use:
367
+
368
+ top_queries = client.analytics_top_queries('site-search-api-example')
369
+ # => [['query term', 123], ['another query', 121], ['yet another query', 92], ...]
370
+
371
+ To see more top queries you can paginate through them using:
372
+
373
+ top_queries = client.analytics_top_queries('site-search-api-example', {:page => 2})
374
+
375
+ Or you can get the top queries in a specific date range:
376
+
377
+ top_queries = client.analytics_top_queries('site-search-api-example', {:start_date => '2013-01-01', :end_date => '2013-01-07'})
378
+
379
+ 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
+
381
+ top_no_result_queries = client.analytics_top_no_result_queries('site-search-api-example')
382
+
383
+ You can also specifiy a date range for queries without results:
384
+
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'})
386
+
387
+ ## Development
388
+
389
+ You can run tests with `rspec`.
390
+
391
+ All HTTP interactions are stubbed out using VCR.
392
+
393
+ ## FAQ 🔮
394
+
395
+ ### Where do I report issues with the client?
396
+
397
+ If something is not working as expected, please open an [issue](https://github.com/elastic/site-search-ruby/issues/new).
398
+
399
+ ### Where can I learn more about Site Search?
400
+
401
+ Your best bet is to read the [documentation](https://swiftype.com/documentation/site-search).
402
+
403
+ ### Where else can I go to get help?
404
+
405
+ You can checkout the [Elastic Site Search community discuss forums](https://discuss.elastic.co/c/site-search).
406
+
407
+ ## Contribute 🚀
408
+
409
+ We welcome contributors to the project. Before you begin, a couple notes...
410
+
411
+ - Before opening a pull request, please create an issue to [discuss the scope of your proposal](https://github.com/elastic/site-search-ruby/issues).
412
+ - Please write simple code and concise documentation, when appropriate.
413
+
414
+ ## License 📗
415
+
416
+ [Apache 2.0](https://github.com/elastic/site-search-ruby/blob/master/LICENSE.txt) © [Elastic](https://github.com/elastic)
417
+
418
+ Thank you to all the [contributors](https://github.com/elastic/site-search-ruby/graphs/contributors)!