elasticsearch-model 5.1.0 → 6.1.0
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 +4 -4
- data/Gemfile +5 -0
- data/README.md +18 -11
- data/Rakefile +27 -36
- data/elasticsearch-model.gemspec +5 -5
- data/examples/activerecord_custom_analyzer.rb +135 -0
- data/examples/activerecord_mapping_completion.rb +3 -18
- data/examples/datamapper_article.rb +11 -1
- data/gemfiles/3.0.gemfile +6 -1
- data/gemfiles/4.0.gemfile +7 -1
- data/gemfiles/5.0.gemfile +7 -1
- data/lib/elasticsearch/model/adapters/active_record.rb +7 -23
- data/lib/elasticsearch/model/adapters/mongoid.rb +10 -3
- data/lib/elasticsearch/model/importing.rb +1 -1
- data/lib/elasticsearch/model/indexing.rb +6 -4
- data/lib/elasticsearch/model/naming.rb +9 -2
- data/lib/elasticsearch/model/response/aggregations.rb +1 -1
- data/lib/elasticsearch/model/response/base.rb +3 -2
- data/lib/elasticsearch/model/response/pagination/kaminari.rb +109 -0
- data/lib/elasticsearch/model/response/pagination/will_paginate.rb +95 -0
- data/lib/elasticsearch/model/response/pagination.rb +2 -192
- data/lib/elasticsearch/model/response/result.rb +1 -1
- data/lib/elasticsearch/model/response/suggestions.rb +1 -1
- data/lib/elasticsearch/model/response.rb +11 -10
- data/lib/elasticsearch/model/version.rb +1 -1
- data/lib/elasticsearch/model.rb +15 -8
- data/spec/elasticsearch/model/adapter_spec.rb +119 -0
- data/spec/elasticsearch/model/adapters/active_record/associations_spec.rb +334 -0
- data/spec/elasticsearch/model/adapters/active_record/basic_spec.rb +340 -0
- data/spec/elasticsearch/model/adapters/active_record/dynamic_index_name_spec.rb +18 -0
- data/spec/elasticsearch/model/adapters/active_record/import_spec.rb +187 -0
- data/spec/elasticsearch/model/adapters/active_record/multi_model_spec.rb +110 -0
- data/spec/elasticsearch/model/adapters/active_record/namespaced_model_spec.rb +38 -0
- data/spec/elasticsearch/model/adapters/active_record/pagination_spec.rb +315 -0
- data/spec/elasticsearch/model/adapters/active_record/parent_child_spec.rb +75 -0
- data/spec/elasticsearch/model/adapters/active_record/serialization_spec.rb +61 -0
- data/spec/elasticsearch/model/adapters/active_record_spec.rb +207 -0
- data/spec/elasticsearch/model/adapters/default_spec.rb +41 -0
- data/spec/elasticsearch/model/adapters/mongoid/basic_spec.rb +267 -0
- data/spec/elasticsearch/model/adapters/mongoid/multi_model_spec.rb +66 -0
- data/spec/elasticsearch/model/adapters/mongoid_spec.rb +235 -0
- data/spec/elasticsearch/model/adapters/multiple_spec.rb +125 -0
- data/spec/elasticsearch/model/callbacks_spec.rb +33 -0
- data/spec/elasticsearch/model/client_spec.rb +66 -0
- data/spec/elasticsearch/model/hash_wrapper_spec.rb +12 -0
- data/spec/elasticsearch/model/importing_spec.rb +214 -0
- data/spec/elasticsearch/model/indexing_spec.rb +918 -0
- data/spec/elasticsearch/model/module_spec.rb +101 -0
- data/spec/elasticsearch/model/multimodel_spec.rb +55 -0
- data/spec/elasticsearch/model/naming_inheritance_spec.rb +184 -0
- data/spec/elasticsearch/model/naming_spec.rb +186 -0
- data/spec/elasticsearch/model/proxy_spec.rb +107 -0
- data/spec/elasticsearch/model/response/aggregations_spec.rb +66 -0
- data/spec/elasticsearch/model/response/base_spec.rb +90 -0
- data/spec/elasticsearch/model/response/pagination/kaminari_spec.rb +410 -0
- data/spec/elasticsearch/model/response/pagination/will_paginate_spec.rb +262 -0
- data/spec/elasticsearch/model/response/records_spec.rb +118 -0
- data/spec/elasticsearch/model/response/response_spec.rb +131 -0
- data/spec/elasticsearch/model/response/result_spec.rb +122 -0
- data/spec/elasticsearch/model/response/results_spec.rb +56 -0
- data/spec/elasticsearch/model/searching_search_request_spec.rb +112 -0
- data/spec/elasticsearch/model/searching_spec.rb +49 -0
- data/spec/elasticsearch/model/serializing_spec.rb +22 -0
- data/spec/spec_helper.rb +161 -0
- data/spec/support/app/answer.rb +33 -0
- data/spec/support/app/article.rb +22 -0
- data/spec/support/app/article_for_pagination.rb +12 -0
- data/spec/support/app/article_with_custom_serialization.rb +13 -0
- data/spec/support/app/article_with_dynamic_index_name.rb +15 -0
- data/spec/support/app/author.rb +9 -0
- data/spec/support/app/authorship.rb +4 -0
- data/spec/support/app/category.rb +3 -0
- data/spec/support/app/comment.rb +3 -0
- data/spec/support/app/episode.rb +11 -0
- data/spec/support/app/image.rb +19 -0
- data/spec/support/app/import_article.rb +12 -0
- data/spec/support/app/mongoid_article.rb +21 -0
- data/spec/support/app/namespaced_book.rb +10 -0
- data/spec/support/app/parent_and_child_searchable.rb +24 -0
- data/spec/support/app/post.rb +14 -0
- data/spec/support/app/question.rb +27 -0
- data/spec/support/app/searchable.rb +48 -0
- data/spec/support/app/series.rb +11 -0
- data/spec/support/app.rb +21 -0
- data/spec/support/model.json +1 -0
- metadata +134 -90
- data/test/integration/active_record_associations_parent_child_test.rb +0 -147
- data/test/integration/active_record_associations_test.rb +0 -339
- data/test/integration/active_record_basic_test.rb +0 -251
- data/test/integration/active_record_custom_serialization_test.rb +0 -67
- data/test/integration/active_record_import_test.rb +0 -115
- data/test/integration/active_record_namespaced_model_test.rb +0 -54
- data/test/integration/active_record_pagination_test.rb +0 -149
- data/test/integration/dynamic_index_name_test.rb +0 -52
- data/test/integration/mongoid_basic_test.rb +0 -176
- data/test/integration/multiple_models_test.rb +0 -176
- data/test/support/model.json +0 -1
- data/test/test_helper.rb +0 -92
- 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/hash_wrapper_test.rb +0 -13
- data/test/unit/importing_test.rb +0 -203
- data/test/unit/indexing_test.rb +0 -687
- data/test/unit/module_test.rb +0 -68
- data/test/unit/multimodel_test.rb +0 -38
- data/test/unit/naming_inheritance_test.rb +0 -94
- data/test/unit/naming_test.rb +0 -103
- data/test/unit/proxy_test.rb +0 -98
- data/test/unit/response_aggregations_test.rb +0 -46
- 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
- /data/{test → spec}/support/model.yml +0 -0
data/spec/support/app.rb
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require 'active_record'
|
|
2
|
+
|
|
3
|
+
require 'support/app/question'
|
|
4
|
+
require 'support/app/answer'
|
|
5
|
+
require 'support/app/parent_and_child_searchable'
|
|
6
|
+
require 'support/app/article_with_custom_serialization'
|
|
7
|
+
require 'support/app/import_article'
|
|
8
|
+
require 'support/app/namespaced_book'
|
|
9
|
+
require 'support/app/article_for_pagination'
|
|
10
|
+
require 'support/app/article_with_dynamic_index_name'
|
|
11
|
+
require 'support/app/episode'
|
|
12
|
+
require 'support/app/image'
|
|
13
|
+
require 'support/app/series'
|
|
14
|
+
require 'support/app/mongoid_article'
|
|
15
|
+
require 'support/app/article'
|
|
16
|
+
require 'support/app/searchable'
|
|
17
|
+
require 'support/app/category'
|
|
18
|
+
require 'support/app/author'
|
|
19
|
+
require 'support/app/authorship'
|
|
20
|
+
require 'support/app/comment'
|
|
21
|
+
require 'support/app/post'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "laz": "qux" }
|
metadata
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: elasticsearch-model
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 6.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Karel Minarik
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2019-08-12 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: elasticsearch
|
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
|
16
16
|
requirements:
|
|
17
|
-
- - "
|
|
17
|
+
- - ">"
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '
|
|
19
|
+
version: '1'
|
|
20
20
|
type: :runtime
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
|
-
- - "
|
|
24
|
+
- - ">"
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: '
|
|
26
|
+
version: '1'
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
28
|
name: activesupport
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -56,16 +56,16 @@ dependencies:
|
|
|
56
56
|
name: bundler
|
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
|
58
58
|
requirements:
|
|
59
|
-
- - "
|
|
59
|
+
- - ">="
|
|
60
60
|
- !ruby/object:Gem::Version
|
|
61
|
-
version: '
|
|
61
|
+
version: '0'
|
|
62
62
|
type: :development
|
|
63
63
|
prerelease: false
|
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
|
65
65
|
requirements:
|
|
66
|
-
- - "
|
|
66
|
+
- - ">="
|
|
67
67
|
- !ruby/object:Gem::Version
|
|
68
|
-
version: '
|
|
68
|
+
version: '0'
|
|
69
69
|
- !ruby/object:Gem::Dependency
|
|
70
70
|
name: rake
|
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -336,6 +336,7 @@ files:
|
|
|
336
336
|
- elasticsearch-model.gemspec
|
|
337
337
|
- examples/activerecord_article.rb
|
|
338
338
|
- examples/activerecord_associations.rb
|
|
339
|
+
- examples/activerecord_custom_analyzer.rb
|
|
339
340
|
- examples/activerecord_mapping_completion.rb
|
|
340
341
|
- examples/activerecord_mapping_edge_ngram.rb
|
|
341
342
|
- examples/couchbase_article.rb
|
|
@@ -365,6 +366,8 @@ files:
|
|
|
365
366
|
- lib/elasticsearch/model/response/aggregations.rb
|
|
366
367
|
- lib/elasticsearch/model/response/base.rb
|
|
367
368
|
- lib/elasticsearch/model/response/pagination.rb
|
|
369
|
+
- lib/elasticsearch/model/response/pagination/kaminari.rb
|
|
370
|
+
- lib/elasticsearch/model/response/pagination/will_paginate.rb
|
|
368
371
|
- lib/elasticsearch/model/response/records.rb
|
|
369
372
|
- lib/elasticsearch/model/response/result.rb
|
|
370
373
|
- lib/elasticsearch/model/response/results.rb
|
|
@@ -372,45 +375,66 @@ files:
|
|
|
372
375
|
- lib/elasticsearch/model/searching.rb
|
|
373
376
|
- lib/elasticsearch/model/serializing.rb
|
|
374
377
|
- lib/elasticsearch/model/version.rb
|
|
375
|
-
-
|
|
376
|
-
-
|
|
377
|
-
-
|
|
378
|
-
-
|
|
379
|
-
-
|
|
380
|
-
-
|
|
381
|
-
-
|
|
382
|
-
-
|
|
383
|
-
-
|
|
384
|
-
-
|
|
385
|
-
-
|
|
386
|
-
-
|
|
387
|
-
-
|
|
388
|
-
-
|
|
389
|
-
-
|
|
390
|
-
-
|
|
391
|
-
-
|
|
392
|
-
-
|
|
393
|
-
-
|
|
394
|
-
-
|
|
395
|
-
-
|
|
396
|
-
-
|
|
397
|
-
-
|
|
398
|
-
-
|
|
399
|
-
-
|
|
400
|
-
-
|
|
401
|
-
-
|
|
402
|
-
-
|
|
403
|
-
-
|
|
404
|
-
-
|
|
405
|
-
-
|
|
406
|
-
-
|
|
407
|
-
-
|
|
408
|
-
-
|
|
409
|
-
-
|
|
410
|
-
-
|
|
411
|
-
-
|
|
412
|
-
-
|
|
413
|
-
-
|
|
378
|
+
- spec/elasticsearch/model/adapter_spec.rb
|
|
379
|
+
- spec/elasticsearch/model/adapters/active_record/associations_spec.rb
|
|
380
|
+
- spec/elasticsearch/model/adapters/active_record/basic_spec.rb
|
|
381
|
+
- spec/elasticsearch/model/adapters/active_record/dynamic_index_name_spec.rb
|
|
382
|
+
- spec/elasticsearch/model/adapters/active_record/import_spec.rb
|
|
383
|
+
- spec/elasticsearch/model/adapters/active_record/multi_model_spec.rb
|
|
384
|
+
- spec/elasticsearch/model/adapters/active_record/namespaced_model_spec.rb
|
|
385
|
+
- spec/elasticsearch/model/adapters/active_record/pagination_spec.rb
|
|
386
|
+
- spec/elasticsearch/model/adapters/active_record/parent_child_spec.rb
|
|
387
|
+
- spec/elasticsearch/model/adapters/active_record/serialization_spec.rb
|
|
388
|
+
- spec/elasticsearch/model/adapters/active_record_spec.rb
|
|
389
|
+
- spec/elasticsearch/model/adapters/default_spec.rb
|
|
390
|
+
- spec/elasticsearch/model/adapters/mongoid/basic_spec.rb
|
|
391
|
+
- spec/elasticsearch/model/adapters/mongoid/multi_model_spec.rb
|
|
392
|
+
- spec/elasticsearch/model/adapters/mongoid_spec.rb
|
|
393
|
+
- spec/elasticsearch/model/adapters/multiple_spec.rb
|
|
394
|
+
- spec/elasticsearch/model/callbacks_spec.rb
|
|
395
|
+
- spec/elasticsearch/model/client_spec.rb
|
|
396
|
+
- spec/elasticsearch/model/hash_wrapper_spec.rb
|
|
397
|
+
- spec/elasticsearch/model/importing_spec.rb
|
|
398
|
+
- spec/elasticsearch/model/indexing_spec.rb
|
|
399
|
+
- spec/elasticsearch/model/module_spec.rb
|
|
400
|
+
- spec/elasticsearch/model/multimodel_spec.rb
|
|
401
|
+
- spec/elasticsearch/model/naming_inheritance_spec.rb
|
|
402
|
+
- spec/elasticsearch/model/naming_spec.rb
|
|
403
|
+
- spec/elasticsearch/model/proxy_spec.rb
|
|
404
|
+
- spec/elasticsearch/model/response/aggregations_spec.rb
|
|
405
|
+
- spec/elasticsearch/model/response/base_spec.rb
|
|
406
|
+
- spec/elasticsearch/model/response/pagination/kaminari_spec.rb
|
|
407
|
+
- spec/elasticsearch/model/response/pagination/will_paginate_spec.rb
|
|
408
|
+
- spec/elasticsearch/model/response/records_spec.rb
|
|
409
|
+
- spec/elasticsearch/model/response/response_spec.rb
|
|
410
|
+
- spec/elasticsearch/model/response/result_spec.rb
|
|
411
|
+
- spec/elasticsearch/model/response/results_spec.rb
|
|
412
|
+
- spec/elasticsearch/model/searching_search_request_spec.rb
|
|
413
|
+
- spec/elasticsearch/model/searching_spec.rb
|
|
414
|
+
- spec/elasticsearch/model/serializing_spec.rb
|
|
415
|
+
- spec/spec_helper.rb
|
|
416
|
+
- spec/support/app.rb
|
|
417
|
+
- spec/support/app/answer.rb
|
|
418
|
+
- spec/support/app/article.rb
|
|
419
|
+
- spec/support/app/article_for_pagination.rb
|
|
420
|
+
- spec/support/app/article_with_custom_serialization.rb
|
|
421
|
+
- spec/support/app/article_with_dynamic_index_name.rb
|
|
422
|
+
- spec/support/app/author.rb
|
|
423
|
+
- spec/support/app/authorship.rb
|
|
424
|
+
- spec/support/app/category.rb
|
|
425
|
+
- spec/support/app/comment.rb
|
|
426
|
+
- spec/support/app/episode.rb
|
|
427
|
+
- spec/support/app/image.rb
|
|
428
|
+
- spec/support/app/import_article.rb
|
|
429
|
+
- spec/support/app/mongoid_article.rb
|
|
430
|
+
- spec/support/app/namespaced_book.rb
|
|
431
|
+
- spec/support/app/parent_and_child_searchable.rb
|
|
432
|
+
- spec/support/app/post.rb
|
|
433
|
+
- spec/support/app/question.rb
|
|
434
|
+
- spec/support/app/searchable.rb
|
|
435
|
+
- spec/support/app/series.rb
|
|
436
|
+
- spec/support/model.json
|
|
437
|
+
- spec/support/model.yml
|
|
414
438
|
homepage: https://github.com/elasticsearch/elasticsearch-rails/
|
|
415
439
|
licenses:
|
|
416
440
|
- Apache 2
|
|
@@ -431,48 +455,68 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
431
455
|
- !ruby/object:Gem::Version
|
|
432
456
|
version: '0'
|
|
433
457
|
requirements: []
|
|
434
|
-
|
|
435
|
-
rubygems_version: 2.7.6
|
|
458
|
+
rubygems_version: 3.0.4
|
|
436
459
|
signing_key:
|
|
437
460
|
specification_version: 4
|
|
438
461
|
summary: ActiveModel/Record integrations for Elasticsearch.
|
|
439
462
|
test_files:
|
|
440
|
-
-
|
|
441
|
-
-
|
|
442
|
-
-
|
|
443
|
-
-
|
|
444
|
-
-
|
|
445
|
-
-
|
|
446
|
-
-
|
|
447
|
-
-
|
|
448
|
-
-
|
|
449
|
-
-
|
|
450
|
-
-
|
|
451
|
-
-
|
|
452
|
-
-
|
|
453
|
-
-
|
|
454
|
-
-
|
|
455
|
-
-
|
|
456
|
-
-
|
|
457
|
-
-
|
|
458
|
-
-
|
|
459
|
-
-
|
|
460
|
-
-
|
|
461
|
-
-
|
|
462
|
-
-
|
|
463
|
-
-
|
|
464
|
-
-
|
|
465
|
-
-
|
|
466
|
-
-
|
|
467
|
-
-
|
|
468
|
-
-
|
|
469
|
-
-
|
|
470
|
-
-
|
|
471
|
-
-
|
|
472
|
-
-
|
|
473
|
-
-
|
|
474
|
-
-
|
|
475
|
-
-
|
|
476
|
-
-
|
|
477
|
-
-
|
|
478
|
-
-
|
|
463
|
+
- spec/elasticsearch/model/adapter_spec.rb
|
|
464
|
+
- spec/elasticsearch/model/adapters/active_record/associations_spec.rb
|
|
465
|
+
- spec/elasticsearch/model/adapters/active_record/basic_spec.rb
|
|
466
|
+
- spec/elasticsearch/model/adapters/active_record/dynamic_index_name_spec.rb
|
|
467
|
+
- spec/elasticsearch/model/adapters/active_record/import_spec.rb
|
|
468
|
+
- spec/elasticsearch/model/adapters/active_record/multi_model_spec.rb
|
|
469
|
+
- spec/elasticsearch/model/adapters/active_record/namespaced_model_spec.rb
|
|
470
|
+
- spec/elasticsearch/model/adapters/active_record/pagination_spec.rb
|
|
471
|
+
- spec/elasticsearch/model/adapters/active_record/parent_child_spec.rb
|
|
472
|
+
- spec/elasticsearch/model/adapters/active_record/serialization_spec.rb
|
|
473
|
+
- spec/elasticsearch/model/adapters/active_record_spec.rb
|
|
474
|
+
- spec/elasticsearch/model/adapters/default_spec.rb
|
|
475
|
+
- spec/elasticsearch/model/adapters/mongoid/basic_spec.rb
|
|
476
|
+
- spec/elasticsearch/model/adapters/mongoid/multi_model_spec.rb
|
|
477
|
+
- spec/elasticsearch/model/adapters/mongoid_spec.rb
|
|
478
|
+
- spec/elasticsearch/model/adapters/multiple_spec.rb
|
|
479
|
+
- spec/elasticsearch/model/callbacks_spec.rb
|
|
480
|
+
- spec/elasticsearch/model/client_spec.rb
|
|
481
|
+
- spec/elasticsearch/model/hash_wrapper_spec.rb
|
|
482
|
+
- spec/elasticsearch/model/importing_spec.rb
|
|
483
|
+
- spec/elasticsearch/model/indexing_spec.rb
|
|
484
|
+
- spec/elasticsearch/model/module_spec.rb
|
|
485
|
+
- spec/elasticsearch/model/multimodel_spec.rb
|
|
486
|
+
- spec/elasticsearch/model/naming_inheritance_spec.rb
|
|
487
|
+
- spec/elasticsearch/model/naming_spec.rb
|
|
488
|
+
- spec/elasticsearch/model/proxy_spec.rb
|
|
489
|
+
- spec/elasticsearch/model/response/aggregations_spec.rb
|
|
490
|
+
- spec/elasticsearch/model/response/base_spec.rb
|
|
491
|
+
- spec/elasticsearch/model/response/pagination/kaminari_spec.rb
|
|
492
|
+
- spec/elasticsearch/model/response/pagination/will_paginate_spec.rb
|
|
493
|
+
- spec/elasticsearch/model/response/records_spec.rb
|
|
494
|
+
- spec/elasticsearch/model/response/response_spec.rb
|
|
495
|
+
- spec/elasticsearch/model/response/result_spec.rb
|
|
496
|
+
- spec/elasticsearch/model/response/results_spec.rb
|
|
497
|
+
- spec/elasticsearch/model/searching_search_request_spec.rb
|
|
498
|
+
- spec/elasticsearch/model/searching_spec.rb
|
|
499
|
+
- spec/elasticsearch/model/serializing_spec.rb
|
|
500
|
+
- spec/spec_helper.rb
|
|
501
|
+
- spec/support/app.rb
|
|
502
|
+
- spec/support/app/answer.rb
|
|
503
|
+
- spec/support/app/article.rb
|
|
504
|
+
- spec/support/app/article_for_pagination.rb
|
|
505
|
+
- spec/support/app/article_with_custom_serialization.rb
|
|
506
|
+
- spec/support/app/article_with_dynamic_index_name.rb
|
|
507
|
+
- spec/support/app/author.rb
|
|
508
|
+
- spec/support/app/authorship.rb
|
|
509
|
+
- spec/support/app/category.rb
|
|
510
|
+
- spec/support/app/comment.rb
|
|
511
|
+
- spec/support/app/episode.rb
|
|
512
|
+
- spec/support/app/image.rb
|
|
513
|
+
- spec/support/app/import_article.rb
|
|
514
|
+
- spec/support/app/mongoid_article.rb
|
|
515
|
+
- spec/support/app/namespaced_book.rb
|
|
516
|
+
- spec/support/app/parent_and_child_searchable.rb
|
|
517
|
+
- spec/support/app/post.rb
|
|
518
|
+
- spec/support/app/question.rb
|
|
519
|
+
- spec/support/app/searchable.rb
|
|
520
|
+
- spec/support/app/series.rb
|
|
521
|
+
- spec/support/model.json
|
|
522
|
+
- spec/support/model.yml
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
require 'test_helper'
|
|
2
|
-
require 'active_record'
|
|
3
|
-
|
|
4
|
-
# Needed for ActiveRecord 3.x ?
|
|
5
|
-
ActiveRecord::Base.establish_connection( :adapter => 'sqlite3', :database => ":memory:" ) unless ActiveRecord::Base.connected?
|
|
6
|
-
|
|
7
|
-
::ActiveRecord::Base.raise_in_transactional_callbacks = true if ::ActiveRecord::Base.respond_to?(:raise_in_transactional_callbacks) && ::ActiveRecord::VERSION::MAJOR.to_s < '5'
|
|
8
|
-
|
|
9
|
-
class Question < ActiveRecord::Base
|
|
10
|
-
include Elasticsearch::Model
|
|
11
|
-
|
|
12
|
-
has_many :answers, dependent: :destroy
|
|
13
|
-
|
|
14
|
-
index_name 'questions_and_answers'
|
|
15
|
-
|
|
16
|
-
mapping do
|
|
17
|
-
indexes :title
|
|
18
|
-
indexes :text
|
|
19
|
-
indexes :author
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
after_commit lambda { __elasticsearch__.index_document }, on: :create
|
|
23
|
-
after_commit lambda { __elasticsearch__.update_document }, on: :update
|
|
24
|
-
after_commit lambda { __elasticsearch__.delete_document }, on: :destroy
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
class Answer < ActiveRecord::Base
|
|
28
|
-
include Elasticsearch::Model
|
|
29
|
-
|
|
30
|
-
belongs_to :question
|
|
31
|
-
|
|
32
|
-
index_name 'questions_and_answers'
|
|
33
|
-
|
|
34
|
-
mapping _parent: { type: 'question' }, _routing: { required: true } do
|
|
35
|
-
indexes :text
|
|
36
|
-
indexes :author
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
after_commit lambda { __elasticsearch__.index_document(parent: question_id) }, on: :create
|
|
40
|
-
after_commit lambda { __elasticsearch__.update_document(parent: question_id) }, on: :update
|
|
41
|
-
after_commit lambda { __elasticsearch__.delete_document(parent: question_id) }, on: :destroy
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
module ParentChildSearchable
|
|
45
|
-
INDEX_NAME = 'questions_and_answers'
|
|
46
|
-
|
|
47
|
-
def create_index!(options={})
|
|
48
|
-
client = Question.__elasticsearch__.client
|
|
49
|
-
client.indices.delete index: INDEX_NAME rescue nil if options[:force]
|
|
50
|
-
|
|
51
|
-
settings = Question.settings.to_hash.merge Answer.settings.to_hash
|
|
52
|
-
mappings = Question.mappings.to_hash.merge Answer.mappings.to_hash
|
|
53
|
-
|
|
54
|
-
client.indices.create index: INDEX_NAME,
|
|
55
|
-
body: {
|
|
56
|
-
settings: settings.to_hash,
|
|
57
|
-
mappings: mappings.to_hash }
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
extend self
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
module Elasticsearch
|
|
64
|
-
module Model
|
|
65
|
-
class ActiveRecordAssociationsParentChildIntegrationTest < Elasticsearch::Test::IntegrationTestCase
|
|
66
|
-
|
|
67
|
-
context "ActiveRecord associations with parent/child modelling" do
|
|
68
|
-
setup do
|
|
69
|
-
ActiveRecord::Schema.define(version: 1) do
|
|
70
|
-
create_table :questions do |t|
|
|
71
|
-
t.string :title
|
|
72
|
-
t.text :text
|
|
73
|
-
t.string :author
|
|
74
|
-
t.timestamps null: false
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
create_table :answers do |t|
|
|
78
|
-
t.text :text
|
|
79
|
-
t.string :author
|
|
80
|
-
t.references :question
|
|
81
|
-
t.timestamps null: false
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
add_index(:answers, :question_id) unless index_exists?(:answers, :question_id)
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
Question.delete_all
|
|
88
|
-
ParentChildSearchable.create_index! force: true
|
|
89
|
-
|
|
90
|
-
q_1 = Question.create! title: 'First Question', author: 'John'
|
|
91
|
-
q_2 = Question.create! title: 'Second Question', author: 'Jody'
|
|
92
|
-
|
|
93
|
-
q_1.answers.create! text: 'Lorem Ipsum', author: 'Adam'
|
|
94
|
-
q_1.answers.create! text: 'Dolor Sit', author: 'Ryan'
|
|
95
|
-
|
|
96
|
-
q_2.answers.create! text: 'Amet Et', author: 'John'
|
|
97
|
-
|
|
98
|
-
Question.__elasticsearch__.refresh_index!
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
should "find questions by matching answers" do
|
|
102
|
-
response = Question.search(
|
|
103
|
-
{ query: {
|
|
104
|
-
has_child: {
|
|
105
|
-
type: 'answer',
|
|
106
|
-
query: {
|
|
107
|
-
match: {
|
|
108
|
-
author: 'john'
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
})
|
|
114
|
-
|
|
115
|
-
assert_equal 'Second Question', response.records.first.title
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
should "find answers for matching questions" do
|
|
119
|
-
response = Answer.search(
|
|
120
|
-
{ query: {
|
|
121
|
-
has_parent: {
|
|
122
|
-
parent_type: 'question',
|
|
123
|
-
query: {
|
|
124
|
-
match: {
|
|
125
|
-
author: 'john'
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
})
|
|
131
|
-
|
|
132
|
-
assert_same_elements ['Adam', 'Ryan'], response.records.map(&:author)
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
should "delete answers when the question is deleted" do
|
|
136
|
-
Question.where(title: 'First Question').each(&:destroy)
|
|
137
|
-
Question.__elasticsearch__.refresh_index!
|
|
138
|
-
|
|
139
|
-
response = Answer.search query: { match_all: {} }
|
|
140
|
-
|
|
141
|
-
assert_equal 1, response.results.total
|
|
142
|
-
end
|
|
143
|
-
end
|
|
144
|
-
|
|
145
|
-
end
|
|
146
|
-
end
|
|
147
|
-
end
|