elasticsearch-model 0.1.9 → 7.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.gitignore +3 -2
- data/Gemfile +22 -0
- data/LICENSE.txt +199 -10
- data/README.md +96 -43
- data/Rakefile +49 -35
- data/elasticsearch-model.gemspec +53 -41
- data/examples/activerecord_article.rb +18 -1
- data/examples/activerecord_associations.rb +86 -17
- data/examples/activerecord_custom_analyzer.rb +152 -0
- data/examples/activerecord_mapping_completion.rb +33 -16
- data/examples/activerecord_mapping_edge_ngram.rb +118 -0
- data/examples/couchbase_article.rb +17 -0
- data/examples/datamapper_article.rb +28 -1
- data/examples/mongoid_article.rb +17 -0
- data/examples/ohm_article.rb +17 -0
- data/examples/riak_article.rb +17 -0
- data/gemfiles/3.0.gemfile +23 -1
- data/gemfiles/4.0.gemfile +25 -1
- data/gemfiles/5.0.gemfile +35 -0
- data/gemfiles/6.0.gemfile +36 -0
- data/lib/elasticsearch/model/adapter.rb +17 -0
- data/lib/elasticsearch/model/adapters/active_record.rb +31 -27
- data/lib/elasticsearch/model/adapters/default.rb +17 -0
- data/lib/elasticsearch/model/adapters/mongoid.rb +27 -3
- data/lib/elasticsearch/model/adapters/multiple.rb +29 -4
- data/lib/elasticsearch/model/callbacks.rb +17 -0
- data/lib/elasticsearch/model/client.rb +17 -0
- data/lib/elasticsearch/model/ext/active_record.rb +17 -0
- data/lib/elasticsearch/model/hash_wrapper.rb +32 -0
- data/lib/elasticsearch/model/importing.rb +61 -17
- data/lib/elasticsearch/model/indexing.rb +87 -49
- data/lib/elasticsearch/model/multimodel.rb +17 -0
- data/lib/elasticsearch/model/naming.rb +33 -2
- data/lib/elasticsearch/model/proxy.rb +61 -18
- data/lib/elasticsearch/model/response/aggregations.rb +55 -0
- data/lib/elasticsearch/model/response/base.rb +25 -3
- data/lib/elasticsearch/model/response/pagination/kaminari.rb +126 -0
- data/lib/elasticsearch/model/response/pagination/will_paginate.rb +112 -0
- data/lib/elasticsearch/model/response/pagination.rb +19 -192
- data/lib/elasticsearch/model/response/records.rb +17 -1
- data/lib/elasticsearch/model/response/result.rb +19 -2
- data/lib/elasticsearch/model/response/results.rb +17 -0
- data/lib/elasticsearch/model/response/suggestions.rb +20 -1
- data/lib/elasticsearch/model/response.rb +28 -10
- data/lib/elasticsearch/model/searching.rb +17 -0
- data/lib/elasticsearch/model/serializing.rb +17 -0
- data/lib/elasticsearch/model/version.rb +18 -1
- data/lib/elasticsearch/model.rb +36 -39
- data/spec/elasticsearch/model/adapter_spec.rb +136 -0
- data/spec/elasticsearch/model/adapters/active_record/associations_spec.rb +351 -0
- data/spec/elasticsearch/model/adapters/active_record/basic_spec.rb +395 -0
- data/spec/elasticsearch/model/adapters/active_record/dynamic_index_name_spec.rb +35 -0
- data/spec/elasticsearch/model/adapters/active_record/import_spec.rb +193 -0
- data/spec/elasticsearch/model/adapters/active_record/multi_model_spec.rb +127 -0
- data/spec/elasticsearch/model/adapters/active_record/namespaced_model_spec.rb +55 -0
- data/spec/elasticsearch/model/adapters/active_record/pagination_spec.rb +332 -0
- data/spec/elasticsearch/model/adapters/active_record/parent_child_spec.rb +92 -0
- data/spec/elasticsearch/model/adapters/active_record/serialization_spec.rb +78 -0
- data/spec/elasticsearch/model/adapters/active_record_spec.rb +224 -0
- data/spec/elasticsearch/model/adapters/default_spec.rb +58 -0
- data/spec/elasticsearch/model/adapters/mongoid/basic_spec.rb +284 -0
- data/spec/elasticsearch/model/adapters/mongoid/multi_model_spec.rb +83 -0
- data/spec/elasticsearch/model/adapters/mongoid_spec.rb +252 -0
- data/spec/elasticsearch/model/adapters/multiple_spec.rb +142 -0
- data/spec/elasticsearch/model/callbacks_spec.rb +50 -0
- data/spec/elasticsearch/model/client_spec.rb +83 -0
- data/spec/elasticsearch/model/hash_wrapper_spec.rb +29 -0
- data/spec/elasticsearch/model/importing_spec.rb +243 -0
- data/spec/elasticsearch/model/indexing_spec.rb +1014 -0
- data/spec/elasticsearch/model/module_spec.rb +94 -0
- data/spec/elasticsearch/model/multimodel_spec.rb +72 -0
- data/spec/elasticsearch/model/naming_spec.rb +203 -0
- data/spec/elasticsearch/model/proxy_spec.rb +124 -0
- data/spec/elasticsearch/model/response/aggregations_spec.rb +83 -0
- data/spec/elasticsearch/model/response/base_spec.rb +107 -0
- data/spec/elasticsearch/model/response/pagination/kaminari_spec.rb +472 -0
- data/spec/elasticsearch/model/response/pagination/will_paginate_spec.rb +279 -0
- data/spec/elasticsearch/model/response/records_spec.rb +135 -0
- data/spec/elasticsearch/model/response/response_spec.rb +148 -0
- data/spec/elasticsearch/model/response/result_spec.rb +139 -0
- data/spec/elasticsearch/model/response/results_spec.rb +73 -0
- data/spec/elasticsearch/model/searching_search_request_spec.rb +129 -0
- data/spec/elasticsearch/model/searching_spec.rb +66 -0
- data/spec/elasticsearch/model/serializing_spec.rb +39 -0
- data/spec/spec_helper.rb +193 -0
- data/spec/support/app/answer.rb +50 -0
- data/spec/support/app/article.rb +39 -0
- data/spec/support/app/article_for_pagination.rb +29 -0
- data/spec/support/app/article_no_type.rb +37 -0
- data/spec/support/app/article_with_custom_serialization.rb +30 -0
- data/spec/support/app/article_with_dynamic_index_name.rb +32 -0
- data/spec/support/app/author.rb +26 -0
- data/spec/support/app/authorship.rb +21 -0
- data/spec/support/app/category.rb +20 -0
- data/spec/support/app/comment.rb +20 -0
- data/spec/support/app/episode.rb +28 -0
- data/spec/support/app/image.rb +36 -0
- data/spec/support/app/import_article.rb +29 -0
- data/spec/support/app/mongoid_article.rb +38 -0
- data/spec/support/app/namespaced_book.rb +27 -0
- data/spec/support/app/parent_and_child_searchable.rb +41 -0
- data/spec/support/app/post.rb +31 -0
- data/spec/support/app/question.rb +44 -0
- data/spec/support/app/searchable.rb +65 -0
- data/spec/support/app/series.rb +28 -0
- data/spec/support/app.rb +46 -0
- data/spec/support/model.json +1 -0
- data/{test → spec}/support/model.yml +0 -0
- metadata +175 -121
- data/test/integration/active_record_associations_parent_child.rb +0 -139
- data/test/integration/active_record_associations_test.rb +0 -326
- data/test/integration/active_record_basic_test.rb +0 -234
- data/test/integration/active_record_custom_serialization_test.rb +0 -62
- data/test/integration/active_record_import_test.rb +0 -109
- data/test/integration/active_record_namespaced_model_test.rb +0 -49
- data/test/integration/active_record_pagination_test.rb +0 -145
- data/test/integration/dynamic_index_name_test.rb +0 -47
- data/test/integration/mongoid_basic_test.rb +0 -177
- data/test/integration/multiple_models_test.rb +0 -172
- data/test/support/model.json +0 -1
- data/test/test_helper.rb +0 -93
- data/test/unit/adapter_active_record_test.rb +0 -157
- data/test/unit/adapter_default_test.rb +0 -41
- data/test/unit/adapter_mongoid_test.rb +0 -104
- data/test/unit/adapter_multiple_test.rb +0 -106
- data/test/unit/adapter_test.rb +0 -69
- data/test/unit/callbacks_test.rb +0 -31
- data/test/unit/client_test.rb +0 -27
- data/test/unit/importing_test.rb +0 -203
- data/test/unit/indexing_test.rb +0 -650
- data/test/unit/module_test.rb +0 -57
- data/test/unit/multimodel_test.rb +0 -38
- data/test/unit/naming_test.rb +0 -103
- data/test/unit/proxy_test.rb +0 -100
- data/test/unit/response_base_test.rb +0 -40
- data/test/unit/response_pagination_kaminari_test.rb +0 -433
- data/test/unit/response_pagination_will_paginate_test.rb +0 -398
- data/test/unit/response_records_test.rb +0 -91
- data/test/unit/response_result_test.rb +0 -90
- data/test/unit/response_results_test.rb +0 -31
- data/test/unit/response_test.rb +0 -104
- data/test/unit/searching_search_request_test.rb +0 -78
- data/test/unit/searching_test.rb +0 -41
- data/test/unit/serializing_test.rb +0 -17
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 4301031eeda01ef94c74b9ad4dc6943a248f876408332d79d1215efddab9eef1
|
|
4
|
+
data.tar.gz: 7b180c808882ae6539ecc42abe550138fd55b79a1548230529dbd0ddc6af30a4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c16dc60e532cbbca544cd234e8897168de3504ced1c9d13a2b7e531a8aaa8e03acf48934f6605dcfb4a35f2e4a32f74a211382302a911411a113d22294b0756a
|
|
7
|
+
data.tar.gz: 28606153ac91b2bfbd472c8727d7764964a793cb4075d9d3b30eb39bb72dda8192020c6e00e2b39e044c36883a1a18cf34c0e5454b939780d3bd9969fe693b53
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
|
@@ -1,4 +1,26 @@
|
|
|
1
|
+
# Licensed to Elasticsearch B.V. under one or more contributor
|
|
2
|
+
# license agreements. See the NOTICE file distributed with
|
|
3
|
+
# this work for additional information regarding copyright
|
|
4
|
+
# ownership. Elasticsearch B.V. licenses this file to you under
|
|
5
|
+
# the Apache License, Version 2.0 (the "License"); you may
|
|
6
|
+
# not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
|
12
|
+
# software distributed under the License is distributed on an
|
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
14
|
+
# KIND, either express or implied. See the License for the
|
|
15
|
+
# specific language governing permissions and limitations
|
|
16
|
+
# under the License.
|
|
17
|
+
|
|
1
18
|
source 'https://rubygems.org'
|
|
2
19
|
|
|
3
20
|
# Specify your gem's dependencies in elasticsearch-model.gemspec
|
|
4
21
|
gemspec
|
|
22
|
+
|
|
23
|
+
group :development, :testing do
|
|
24
|
+
gem 'pry-nav'
|
|
25
|
+
gem 'rspec'
|
|
26
|
+
end
|
data/LICENSE.txt
CHANGED
|
@@ -1,13 +1,202 @@
|
|
|
1
|
-
Copyright (c) 2014 Elasticsearch
|
|
2
1
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
6
5
|
|
|
7
|
-
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
8
7
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
data/README.md
CHANGED
|
@@ -1,13 +1,22 @@
|
|
|
1
1
|
# Elasticsearch::Model
|
|
2
2
|
|
|
3
|
-
The `elasticsearch-model` library builds on top of the
|
|
4
|
-
the [`elasticsearch`](https://github.com/elasticsearch/elasticsearch-ruby) library.
|
|
3
|
+
The `elasticsearch-model` library builds on top of the the [`elasticsearch`](https://github.com/elastic/elasticsearch-ruby) library.
|
|
5
4
|
|
|
6
|
-
It aims to simplify integration of Ruby classes ("models"), commonly found
|
|
7
|
-
e.g. in [Ruby on Rails](http://rubyonrails.org) applications, with the
|
|
8
|
-
[Elasticsearch](http://www.elasticsearch.org) search and analytics engine.
|
|
5
|
+
It aims to simplify integration of Ruby classes ("models"), commonly found e.g. in [Ruby on Rails](http://rubyonrails.org) applications, with the [Elasticsearch](https://www.elastic.co) search and analytics engine.
|
|
9
6
|
|
|
10
|
-
|
|
7
|
+
## Compatibility
|
|
8
|
+
|
|
9
|
+
This library is compatible with Ruby 2.4 and higher.
|
|
10
|
+
|
|
11
|
+
The library version numbers follow the Elasticsearch major versions. The `master` branch is compatible with the latest Elasticsearch stack stable release.
|
|
12
|
+
|
|
13
|
+
| Rubygem | | Elasticsearch |
|
|
14
|
+
|:-------------:|:-:| :-----------: |
|
|
15
|
+
| 0.1 | → | 1.x |
|
|
16
|
+
| 2.x | → | 2.x |
|
|
17
|
+
| 5.x | → | 5.x |
|
|
18
|
+
| 6.x | → | 6.x |
|
|
19
|
+
| master | → | 7.x |
|
|
11
20
|
|
|
12
21
|
## Installation
|
|
13
22
|
|
|
@@ -17,11 +26,11 @@ Install the package from [Rubygems](https://rubygems.org):
|
|
|
17
26
|
|
|
18
27
|
To use an unreleased version, either add it to your `Gemfile` for [Bundler](http://bundler.io):
|
|
19
28
|
|
|
20
|
-
gem 'elasticsearch-model', git: 'git://github.com/
|
|
29
|
+
gem 'elasticsearch-model', git: 'git://github.com/elastic/elasticsearch-rails.git', branch: '5.x'
|
|
21
30
|
|
|
22
31
|
or install it from a source code checkout:
|
|
23
32
|
|
|
24
|
-
git clone https://github.com/
|
|
33
|
+
git clone https://github.com/elastic/elasticsearch-rails.git
|
|
25
34
|
cd elasticsearch-rails/elasticsearch-model
|
|
26
35
|
bundle install
|
|
27
36
|
rake install
|
|
@@ -60,9 +69,7 @@ This will extend the model with functionality related to Elasticsearch.
|
|
|
60
69
|
|
|
61
70
|
#### Feature Extraction Pattern
|
|
62
71
|
|
|
63
|
-
Instead of including the `Elasticsearch::Model` module directly in your model,
|
|
64
|
-
you can include it in a "concern" or "trait" module, which is quite common pattern in Rails applications,
|
|
65
|
-
using e.g. `ActiveSupport::Concern` as the instrumentation:
|
|
72
|
+
Instead of including the `Elasticsearch::Model` module directly in your model, you can include it in a "concern" or "trait" module, which is quite common pattern in Rails applications, using e.g. `ActiveSupport::Concern` as the instrumentation:
|
|
66
73
|
|
|
67
74
|
```ruby
|
|
68
75
|
# In: app/models/concerns/searchable.rb
|
|
@@ -109,7 +116,7 @@ See the `Elasticsearch::Model` module documentation for technical information.
|
|
|
109
116
|
|
|
110
117
|
### The Elasticsearch client
|
|
111
118
|
|
|
112
|
-
The module will set up a [client](https://github.com/
|
|
119
|
+
The module will set up a [client](https://github.com/elastic/elasticsearch-ruby/tree/master/elasticsearch),
|
|
113
120
|
connected to `localhost:9200`, by default. You can access and use it as any other `Elasticsearch::Client`:
|
|
114
121
|
|
|
115
122
|
```ruby
|
|
@@ -132,14 +139,14 @@ Elasticsearch::Model.client = Elasticsearch::Client.new log: true
|
|
|
132
139
|
You might want to do this during your application bootstrap process, e.g. in a Rails initializer.
|
|
133
140
|
|
|
134
141
|
Please refer to the
|
|
135
|
-
[`elasticsearch-transport`](https://github.com/
|
|
142
|
+
[`elasticsearch-transport`](https://github.com/elastic/elasticsearch-ruby/tree/master/elasticsearch-transport)
|
|
136
143
|
library documentation for all the configuration options, and to the
|
|
137
144
|
[`elasticsearch-api`](http://rubydoc.info/gems/elasticsearch-api) library documentation
|
|
138
145
|
for information about the Ruby client API.
|
|
139
146
|
|
|
140
147
|
### Importing the data
|
|
141
148
|
|
|
142
|
-
The first thing you'll want to do is
|
|
149
|
+
The first thing you'll want to do is import your data into the index:
|
|
143
150
|
|
|
144
151
|
```ruby
|
|
145
152
|
Article.import
|
|
@@ -241,7 +248,7 @@ response.records.order(:title).to_a
|
|
|
241
248
|
The `records` method returns the real instances of your model, which is useful when you want to access your
|
|
242
249
|
model methods -- at the expense of slowing down your application, of course.
|
|
243
250
|
In most cases, working with `results` coming from Elasticsearch is sufficient, and much faster. See the
|
|
244
|
-
[`elasticsearch-rails`](https://github.com/
|
|
251
|
+
[`elasticsearch-rails`](https://github.com/elastic/elasticsearch-rails/tree/master/elasticsearch-rails)
|
|
245
252
|
library for more information about compatibility with the Ruby on Rails framework.
|
|
246
253
|
|
|
247
254
|
When you want to access both the database `records` and search `results`, use the `each_with_hit`
|
|
@@ -277,11 +284,8 @@ NOTE: It is _not_ possible to chain other methods on top of the `records` object
|
|
|
277
284
|
|
|
278
285
|
#### Pagination
|
|
279
286
|
|
|
280
|
-
You can implement pagination with the `from` and `size` search parameters. However, search results
|
|
281
|
-
|
|
282
|
-
[`will_paginate`](https://github.com/mislav/will_paginate) gems.
|
|
283
|
-
(The pagination gems must be added before the Elasticsearch gems in your Gemfile,
|
|
284
|
-
or loaded first in your application.)
|
|
287
|
+
You can implement pagination with the `from` and `size` search parameters. However, search results can be automatically paginated with the [`kaminari`](http://rubygems.org/gems/kaminari) or [`will_paginate`](https://github.com/mislav/will_paginate) gems.
|
|
288
|
+
(The pagination gems must be added before the Elasticsearch gems in your Gemfile, or loaded first in your application.)
|
|
285
289
|
|
|
286
290
|
If Kaminari or WillPaginate is loaded, use the familiar paging methods:
|
|
287
291
|
|
|
@@ -290,7 +294,7 @@ response.page(2).results
|
|
|
290
294
|
response.page(2).records
|
|
291
295
|
```
|
|
292
296
|
|
|
293
|
-
In a Rails controller, use the
|
|
297
|
+
In a Rails controller, use the `params[:page]` parameter to paginate through results:
|
|
294
298
|
|
|
295
299
|
```ruby
|
|
296
300
|
@articles = Article.search(params[:q]).page(params[:page]).records
|
|
@@ -303,14 +307,13 @@ In a Rails controller, use the the `params[:page]` parameter to paginate through
|
|
|
303
307
|
To initialize and include the Kaminari pagination support manually:
|
|
304
308
|
|
|
305
309
|
```ruby
|
|
306
|
-
Kaminari::Hooks.init
|
|
310
|
+
Kaminari::Hooks.init if defined?(Kaminari::Hooks)
|
|
307
311
|
Elasticsearch::Model::Response::Response.__send__ :include, Elasticsearch::Model::Response::Pagination::Kaminari
|
|
308
312
|
```
|
|
309
313
|
|
|
310
314
|
#### The Elasticsearch DSL
|
|
311
315
|
|
|
312
|
-
In most
|
|
313
|
-
in the Elasticsearch [domain-specific language](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl.html) to the client:
|
|
316
|
+
In most situations, you'll want to pass the search definition in the Elasticsearch [domain-specific language](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl.html) to the client:
|
|
314
317
|
|
|
315
318
|
```ruby
|
|
316
319
|
response = Article.search query: { match: { title: "Fox Dogs" } },
|
|
@@ -320,8 +323,7 @@ response.results.first.highlight.title
|
|
|
320
323
|
# ["Quick brown <em>fox</em>"]
|
|
321
324
|
```
|
|
322
325
|
|
|
323
|
-
You can pass any object which implements a `to_hash` method,
|
|
324
|
-
to build the search definition as a JSON string:
|
|
326
|
+
You can pass any object which implements a `to_hash` method, which is called automatically, so you can use a custom class or your favourite JSON builder to build the search definition:
|
|
325
327
|
|
|
326
328
|
```ruby
|
|
327
329
|
require 'jbuilder'
|
|
@@ -341,11 +343,33 @@ response.results.first.title
|
|
|
341
343
|
# => "Quick brown fox"
|
|
342
344
|
```
|
|
343
345
|
|
|
346
|
+
Also, you can use the [**`elasticsearch-dsl`**](https://github.com/elastic/elasticsearch-ruby/tree/master/elasticsearch-dsl) library, which provides a specialized Ruby API for the Elasticsearch Query DSL:
|
|
347
|
+
|
|
348
|
+
```ruby
|
|
349
|
+
require 'elasticsearch/dsl'
|
|
350
|
+
|
|
351
|
+
query = Elasticsearch::DSL::Search.search do
|
|
352
|
+
query do
|
|
353
|
+
match :title do
|
|
354
|
+
query 'fox dogs'
|
|
355
|
+
end
|
|
356
|
+
end
|
|
357
|
+
end
|
|
358
|
+
|
|
359
|
+
response = Article.search query
|
|
360
|
+
response.results.first.title
|
|
361
|
+
# => "Quick brown fox"
|
|
362
|
+
```
|
|
363
|
+
|
|
344
364
|
### Index Configuration
|
|
345
365
|
|
|
346
366
|
For proper search engine function, it's often necessary to configure the index properly.
|
|
347
367
|
The `Elasticsearch::Model` integration provides class methods to set up index settings and mappings.
|
|
348
368
|
|
|
369
|
+
**NOTE**: Elasticsearch will automatically create an index when a document is indexed,
|
|
370
|
+
with default settings and mappings. Create the index in advance with the `create_index!`
|
|
371
|
+
method, so your index configuration is respected.
|
|
372
|
+
|
|
349
373
|
```ruby
|
|
350
374
|
class Article
|
|
351
375
|
settings index: { number_of_shards: 1 } do
|
|
@@ -390,7 +414,7 @@ Article.__elasticsearch__.refresh_index!
|
|
|
390
414
|
```
|
|
391
415
|
|
|
392
416
|
By default, index name and document type will be inferred from your class name,
|
|
393
|
-
you can set it
|
|
417
|
+
you can set it explicitly, however:
|
|
394
418
|
|
|
395
419
|
```ruby
|
|
396
420
|
class Article
|
|
@@ -459,7 +483,11 @@ class Article < ActiveRecord::Base
|
|
|
459
483
|
end
|
|
460
484
|
|
|
461
485
|
after_commit on: [:update] do
|
|
462
|
-
|
|
486
|
+
if self.published?
|
|
487
|
+
__elasticsearch__.update_document
|
|
488
|
+
else
|
|
489
|
+
__elasticsearch__.delete_document
|
|
490
|
+
end
|
|
463
491
|
end
|
|
464
492
|
|
|
465
493
|
after_commit on: [:destroy] do
|
|
@@ -499,9 +527,13 @@ class Indexer
|
|
|
499
527
|
case operation.to_s
|
|
500
528
|
when /index/
|
|
501
529
|
record = Article.find(record_id)
|
|
502
|
-
Client.index index: 'articles', type: 'article', id: record.id, body: record.as_indexed_json
|
|
530
|
+
Client.index index: 'articles', type: 'article', id: record.id, body: record.__elasticsearch__.as_indexed_json
|
|
503
531
|
when /delete/
|
|
504
|
-
|
|
532
|
+
begin
|
|
533
|
+
Client.delete index: 'articles', type: 'article', id: record_id
|
|
534
|
+
rescue Elasticsearch::Transport::Transport::Errors::NotFound
|
|
535
|
+
logger.debug "Article not found, ID: #{record_id}"
|
|
536
|
+
end
|
|
505
537
|
else raise ArgumentError, "Unknown operation '#{operation}'"
|
|
506
538
|
end
|
|
507
539
|
end
|
|
@@ -639,7 +671,7 @@ module DataMapperAdapter
|
|
|
639
671
|
#
|
|
640
672
|
module Records
|
|
641
673
|
def records
|
|
642
|
-
klass.all(id:
|
|
674
|
+
klass.all(id: ids)
|
|
643
675
|
end
|
|
644
676
|
|
|
645
677
|
# ...
|
|
@@ -685,6 +717,13 @@ response.records.records.class
|
|
|
685
717
|
More examples can be found in the `examples` folder. Please see the `Elasticsearch::Model::Adapter`
|
|
686
718
|
module and its submodules for technical information.
|
|
687
719
|
|
|
720
|
+
### Settings
|
|
721
|
+
|
|
722
|
+
The module provides a common `settings` method to customize various features.
|
|
723
|
+
|
|
724
|
+
Before version 7.0.0 of the gem, the only supported setting was `:inheritance_enabled`. This setting has been deprecated
|
|
725
|
+
and removed.
|
|
726
|
+
|
|
688
727
|
## Development and Community
|
|
689
728
|
|
|
690
729
|
For local development, clone the repository and run `bundle install`. See `rake -T` for a list of
|
|
@@ -701,20 +740,34 @@ curl -# https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticse
|
|
|
701
740
|
SERVER=start TEST_CLUSTER_COMMAND=$PWD/tmp/elasticsearch-1.0.0.RC1/bin/elasticsearch bundle exec rake test:all
|
|
702
741
|
```
|
|
703
742
|
|
|
743
|
+
### Single Table Inheritance support
|
|
744
|
+
|
|
745
|
+
Versions < 7.0.0 of this gem supported inheritance-- more specifically, `Single Table Inheritance`. With this feature,
|
|
746
|
+
elasticsearch settings (index mappings, etc) on a parent model could be inherited by a child model leading to different
|
|
747
|
+
model documents being indexed into the same Elasticsearch index. This feature depended on the ability to set a `type`
|
|
748
|
+
for a document in Elasticsearch. The Elasticsearch team has deprecated support for `types`, as is described
|
|
749
|
+
[here.](https://www.elastic.co/guide/en/elasticsearch/reference/current/removal-of-types.html)
|
|
750
|
+
This gem will also remove support for types and `Single Table Inheritance` in version 7.0 as it enables an anti-pattern.
|
|
751
|
+
Please save different model documents in separate indices. If you want to use STI, you can include an artificial
|
|
752
|
+
`type` field manually in each document and use it in other operations.
|
|
753
|
+
|
|
704
754
|
## License
|
|
705
755
|
|
|
706
756
|
This software is licensed under the Apache 2 license, quoted below.
|
|
707
757
|
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
758
|
+
Licensed to Elasticsearch B.V. under one or more contributor
|
|
759
|
+
license agreements. See the NOTICE file distributed with
|
|
760
|
+
this work for additional information regarding copyright
|
|
761
|
+
ownership. Elasticsearch B.V. licenses this file to you under
|
|
762
|
+
the Apache License, Version 2.0 (the "License"); you may
|
|
763
|
+
not use this file except in compliance with the License.
|
|
712
764
|
You may obtain a copy of the License at
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
Unless required by applicable law or agreed to in writing,
|
|
717
|
-
distributed under the License is distributed on an
|
|
718
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
719
|
-
See the License for the
|
|
720
|
-
|
|
765
|
+
|
|
766
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
767
|
+
|
|
768
|
+
Unless required by applicable law or agreed to in writing,
|
|
769
|
+
software distributed under the License is distributed on an
|
|
770
|
+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
771
|
+
KIND, either express or implied. See the License for the
|
|
772
|
+
specific language governing permissions and limitations
|
|
773
|
+
under the License.
|
data/Rakefile
CHANGED
|
@@ -1,45 +1,59 @@
|
|
|
1
|
-
|
|
1
|
+
# Licensed to Elasticsearch B.V. under one or more contributor
|
|
2
|
+
# license agreements. See the NOTICE file distributed with
|
|
3
|
+
# this work for additional information regarding copyright
|
|
4
|
+
# ownership. Elasticsearch B.V. licenses this file to you under
|
|
5
|
+
# the Apache License, Version 2.0 (the "License"); you may
|
|
6
|
+
# not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
|
12
|
+
# software distributed under the License is distributed on an
|
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
14
|
+
# KIND, either express or implied. See the License for the
|
|
15
|
+
# specific language governing permissions and limitations
|
|
16
|
+
# under the License.
|
|
2
17
|
|
|
3
|
-
|
|
4
|
-
task :default => 'test:unit'
|
|
5
|
-
task :test => 'test:unit'
|
|
18
|
+
require 'bundler/gem_tasks'
|
|
6
19
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
namespace :test do
|
|
11
|
-
task :ci_reporter do
|
|
12
|
-
ENV['CI_REPORTS'] ||= 'tmp/reports'
|
|
13
|
-
require 'ci/reporter/rake/minitest'
|
|
14
|
-
Rake::Task['ci:setup:minitest'].invoke
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
Rake::TestTask.new(:unit) do |test|
|
|
18
|
-
Rake::Task['test:ci_reporter'].invoke if ENV['CI']
|
|
19
|
-
test.libs << 'lib' << 'test'
|
|
20
|
-
test.test_files = FileList["test/unit/**/*_test.rb"]
|
|
21
|
-
# test.verbose = true
|
|
22
|
-
# test.warning = true
|
|
23
|
-
end
|
|
20
|
+
desc 'Run unit tests'
|
|
21
|
+
task default: 'test:all'
|
|
22
|
+
task test: 'test:all'
|
|
24
23
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
test.test_files = FileList["test/integration/**/*_test.rb"]
|
|
29
|
-
end
|
|
24
|
+
gemfiles = ['5.0.gemfile', '6.0.gemfile']
|
|
25
|
+
gemfiles << '4.0.gemfile' if RUBY_VERSION < '2.7'
|
|
26
|
+
GEMFILES = gemfiles.freeze
|
|
30
27
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
28
|
+
namespace :bundle do
|
|
29
|
+
desc 'Install dependencies for all the Gemfiles in /gemfiles. Optionally define env variable RAILS_VERSIONS. E.g. RAILS_VERSIONS=3.0,5.0'
|
|
30
|
+
task :install do
|
|
31
|
+
unless defined?(JRUBY_VERSION)
|
|
32
|
+
puts '-'*80
|
|
33
|
+
gemfiles = ENV['RAILS_VERSIONS'] ? ENV['RAILS_VERSIONS'].split(',').map { |v| "#{v}.gemfile"} : GEMFILES
|
|
34
|
+
gemfiles.each do |gemfile|
|
|
35
|
+
Bundler.with_clean_env do
|
|
36
|
+
sh "bundle install --gemfile #{File.expand_path('../gemfiles/'+gemfile, __FILE__)}"
|
|
37
|
+
end
|
|
38
|
+
puts '-'*80
|
|
39
|
+
end
|
|
40
|
+
end
|
|
35
41
|
end
|
|
42
|
+
end
|
|
36
43
|
|
|
37
|
-
|
|
38
|
-
task :all do
|
|
39
|
-
Rake::Task['test:ci_reporter'].invoke if ENV['CI']
|
|
44
|
+
# ----- Test tasks ------------------------------------------------------------
|
|
40
45
|
|
|
41
|
-
|
|
42
|
-
|
|
46
|
+
require 'rake/testtask'
|
|
47
|
+
namespace :test do
|
|
48
|
+
desc 'Run all tests. Optionally define env variable RAILS_VERSIONS. E.g. RAILS_VERSIONS=3.0,5.0'
|
|
49
|
+
task :all, [:rails_versions] do |task, args|
|
|
50
|
+
gemfiles = ENV['RAILS_VERSIONS'] ? ENV['RAILS_VERSIONS'].split(',').map {|v| "#{v}.gemfile"} : GEMFILES
|
|
51
|
+
puts '-' * 80
|
|
52
|
+
gemfiles.each do |gemfile|
|
|
53
|
+
sh "BUNDLE_GEMFILE='#{File.expand_path("../gemfiles/#{gemfile}", __FILE__)}' " +
|
|
54
|
+
" bundle exec rspec"
|
|
55
|
+
puts '-' * 80
|
|
56
|
+
end
|
|
43
57
|
end
|
|
44
58
|
end
|
|
45
59
|
|