indexes 4.0.0.2 → 4.0.0.3

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.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. metadata +11 -198
  3. data/MIT-LICENSE +0 -20
  4. data/README.md +0 -265
  5. data/Rakefile +0 -19
  6. data/lib/generators/index/index_generator.rb +0 -15
  7. data/lib/generators/index/templates/index.rb +0 -12
  8. data/lib/generators/indexes/install/install_generator.rb +0 -15
  9. data/lib/generators/indexes/install/templates/initializer.rb +0 -10
  10. data/lib/indexes.rb +0 -85
  11. data/lib/indexes/collection.rb +0 -186
  12. data/lib/indexes/concern.rb +0 -23
  13. data/lib/indexes/configuration.rb +0 -39
  14. data/lib/indexes/definitions.rb +0 -24
  15. data/lib/indexes/dsl/api.rb +0 -90
  16. data/lib/indexes/dsl/mappings.rb +0 -14
  17. data/lib/indexes/dsl/search.rb +0 -27
  18. data/lib/indexes/dsl/serialization.rb +0 -17
  19. data/lib/indexes/index.rb +0 -147
  20. data/lib/indexes/pagination.rb +0 -33
  21. data/lib/indexes/proxy.rb +0 -17
  22. data/lib/indexes/railtie.rb +0 -15
  23. data/lib/indexes/version.rb +0 -5
  24. data/lib/tasks/indexes.rake +0 -11
  25. data/test/dsl_test.rb +0 -128
  26. data/test/dummy/Rakefile +0 -5
  27. data/test/dummy/app/assets/javascripts/application.js +0 -13
  28. data/test/dummy/app/assets/stylesheets/application.css +0 -15
  29. data/test/dummy/app/controllers/application_controller.rb +0 -5
  30. data/test/dummy/app/helpers/application_helper.rb +0 -2
  31. data/test/dummy/app/indexes/products_index.rb +0 -51
  32. data/test/dummy/app/indexes/shops_index.rb +0 -28
  33. data/test/dummy/app/models/product.rb +0 -5
  34. data/test/dummy/app/models/shop.rb +0 -5
  35. data/test/dummy/app/views/layouts/application.html.erb +0 -12
  36. data/test/dummy/bin/bundle +0 -4
  37. data/test/dummy/bin/rails +0 -5
  38. data/test/dummy/bin/rake +0 -5
  39. data/test/dummy/bin/setup +0 -30
  40. data/test/dummy/config.ru +0 -4
  41. data/test/dummy/config/application.rb +0 -25
  42. data/test/dummy/config/boot.rb +0 -5
  43. data/test/dummy/config/database.yml +0 -7
  44. data/test/dummy/config/database.yml.travis +0 -3
  45. data/test/dummy/config/environment.rb +0 -5
  46. data/test/dummy/config/environments/development.rb +0 -41
  47. data/test/dummy/config/environments/production.rb +0 -79
  48. data/test/dummy/config/environments/test.rb +0 -42
  49. data/test/dummy/config/initializers/assets.rb +0 -11
  50. data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
  51. data/test/dummy/config/initializers/cookies_serializer.rb +0 -3
  52. data/test/dummy/config/initializers/filter_parameter_logging.rb +0 -4
  53. data/test/dummy/config/initializers/indexes.rb +0 -67
  54. data/test/dummy/config/initializers/inflections.rb +0 -16
  55. data/test/dummy/config/initializers/mime_types.rb +0 -4
  56. data/test/dummy/config/initializers/session_store.rb +0 -3
  57. data/test/dummy/config/initializers/wrap_parameters.rb +0 -14
  58. data/test/dummy/config/locales/en.yml +0 -23
  59. data/test/dummy/config/routes.rb +0 -56
  60. data/test/dummy/config/secrets.yml +0 -22
  61. data/test/dummy/db/migrate/20161104164148_create_products.rb +0 -14
  62. data/test/dummy/db/migrate/20161104182219_create_shops.rb +0 -9
  63. data/test/dummy/db/schema.rb +0 -36
  64. data/test/dummy/log/development.log +0 -38
  65. data/test/dummy/log/test.log +0 -3643
  66. data/test/dummy/public/404.html +0 -61
  67. data/test/dummy/public/422.html +0 -61
  68. data/test/dummy/public/500.html +0 -60
  69. data/test/dummy/public/favicon.ico +0 -0
  70. data/test/generator_test.rb +0 -25
  71. data/test/index_test.rb +0 -46
  72. data/test/record_test.rb +0 -25
  73. data/test/search_test.rb +0 -164
  74. data/test/task_test.rb +0 -25
  75. data/test/test_helper.rb +0 -14
@@ -1,14 +0,0 @@
1
- module Indexes
2
- module Dsl
3
- class Mappings < Api
4
-
5
- def properties(*names)
6
- @parent[:properties] ||= {}
7
- names.each do |name|
8
- @parent[:properties][name] = Indexes.configuration.mappings[name]
9
- end
10
- end
11
-
12
- end
13
- end
14
- end
@@ -1,27 +0,0 @@
1
- module Indexes
2
- module Dsl
3
- class Search < Api
4
-
5
- private
6
-
7
- def add_block(name, args, options, &block)
8
- if %i(functions must must_not should).include?(name)
9
- child = []
10
- @parent[name] = child
11
- self.class.new [], child, &block
12
- else
13
- super
14
- end
15
- end
16
-
17
- def add_argument(name, args, options)
18
- if name == :query && args.first.is_a?(Symbol)
19
- @parent[name] = Indexes.definitions.find(args.first).search([options]).query[:query]
20
- else
21
- super
22
- end
23
- end
24
-
25
- end
26
- end
27
- end
@@ -1,17 +0,0 @@
1
- module Indexes
2
- module Dsl
3
- class Serialization < Api
4
-
5
- def extract(record, *names)
6
- names.each do |name|
7
- send name, record.send(name)
8
- end
9
- end
10
-
11
- def transliterate(value)
12
- ActiveSupport::Inflector.transliterate value
13
- end
14
-
15
- end
16
- end
17
- end
@@ -1,147 +0,0 @@
1
- module Indexes
2
- class Index
3
- include Comparable
4
-
5
- attr_reader :name, :type, :options
6
-
7
- def initialize(name, options={})
8
- @name = name
9
- @type = @name.to_s.singularize
10
- @options = options
11
- indexify_model
12
- end
13
-
14
- def mappings
15
- @mappings ||= Dsl::Mappings.new(&options[:mappings]).to_h
16
- end
17
-
18
- def model
19
- (options[:class_name] || type.classify).constantize
20
- end
21
-
22
- def has_parent?
23
- mappings.has_key? :_parent
24
- end
25
-
26
- def <=>(other)
27
- if has_parent? && other.has_parent?
28
- 0
29
- elsif other.has_parent?
30
- 1
31
- else
32
- -1
33
- end
34
- end
35
-
36
- def any?(*args)
37
- search(*args).count > 0
38
- end
39
-
40
- def none?(*args)
41
- !any?(*args)
42
- end
43
-
44
- def search(*args)
45
- Collection.new self, *args, &options[:search]
46
- end
47
-
48
- def raw_search(query)
49
- client.search(
50
- index: namespace,
51
- type: type,
52
- body: query
53
- )
54
- end
55
-
56
- def exists?(record)
57
- client.exists?(
58
- with_parent(
59
- record,
60
- index: namespace,
61
- type: type,
62
- id: record.id
63
- )
64
- )
65
- end
66
-
67
- def index(record)
68
- client.create(
69
- with_parent(
70
- record,
71
- index: namespace,
72
- type: type,
73
- id: record.id,
74
- body: serialize(record)
75
- )
76
- )
77
- end
78
-
79
- def reindex(record)
80
- client.bulk(
81
- index: namespace,
82
- type: type,
83
- body: [
84
- { delete: with_parent(record, _id: record.id) },
85
- { index: with_parent(record, _id: record.id, data: serialize(record)) }
86
- ]
87
- )
88
- end
89
-
90
- def unindex(record)
91
- client.delete(
92
- with_parent(
93
- record,
94
- index: namespace,
95
- type: type,
96
- id: record.id
97
- )
98
- )
99
- end
100
-
101
- def build
102
- client.indices.put_mapping(
103
- index: namespace,
104
- type: type,
105
- body: mappings
106
- )
107
- model.find_in_batches do |records|
108
- client.bulk(
109
- index: namespace,
110
- type: type,
111
- body: records.map do |record|
112
- { index: with_parent(record, _id: record.id, data: serialize(record)) }
113
- end
114
- )
115
- end
116
- end
117
-
118
- private
119
-
120
- %i(client namespace).each do |name|
121
- define_method name do
122
- Indexes.send name
123
- end
124
- end
125
-
126
- def with_parent(record, hash)
127
- if has_parent?
128
- hash.merge parent: record.send("#{mappings[:_parent][:type].singularize}_id")
129
- else
130
- hash
131
- end
132
- end
133
-
134
- def serialize(record)
135
- Dsl::Serialization.new(record, &options[:serialization]).to_h
136
- end
137
-
138
- def indexify_model
139
- index = self
140
- model.include Indexes::Concern
141
- model.define_singleton_method :index do
142
- index
143
- end
144
- end
145
-
146
- end
147
- end
@@ -1,33 +0,0 @@
1
- module Indexes
2
- module Pagination
3
-
4
- def total_pages
5
- @total_pages ||= [(total_count.to_f / page_length).ceil, 1].max
6
- end
7
-
8
- def previous_page
9
- @previous_page ||= (current_page > 1 ? (current_page - 1) : nil)
10
- end
11
-
12
- def next_page
13
- @next_page ||= (current_page < total_pages ? (current_page + 1) : nil)
14
- end
15
-
16
- def first_page
17
- 1
18
- end
19
-
20
- def last_page
21
- total_pages
22
- end
23
-
24
- def out_of_bounds?
25
- @out_of_bounds ||= (current_page > total_pages || current_page < first_page)
26
- end
27
-
28
- def total_count
29
- @total_count ||= (response['hits']['total'].to_i - padding)
30
- end
31
-
32
- end
33
- end
@@ -1,17 +0,0 @@
1
- module Indexes
2
- class Proxy
3
-
4
- def initialize(name, options={}, &block)
5
- @options = options
6
- instance_eval &block
7
- Indexes.definitions.add name, @options
8
- end
9
-
10
- %i(mappings serialization search).each do |name|
11
- define_method name do |&block|
12
- @options[name] = block
13
- end
14
- end
15
-
16
- end
17
- end
@@ -1,15 +0,0 @@
1
- module Indexes
2
- class Railtie < Rails::Railtie
3
-
4
- config.after_initialize do
5
- Dir[Rails.root.join('app/indexes/*')].each do |file|
6
- load file
7
- end
8
- end
9
-
10
- rake_tasks do
11
- load 'tasks/indexes.rake'
12
- end
13
-
14
- end
15
- end
@@ -1,5 +0,0 @@
1
- module Indexes
2
-
3
- VERSION = '4.0.0.2'
4
-
5
- end
@@ -1,11 +0,0 @@
1
- namespace :indexes do
2
- desc 'Build all indexes.'
3
- task build: :environment do
4
- Indexes.build
5
- end
6
-
7
- desc 'Rebuild all indexes.'
8
- task rebuild: :environment do
9
- Indexes.rebuild
10
- end
11
- end
@@ -1,128 +0,0 @@
1
- require 'test_helper'
2
-
3
- class DslTest < ActiveSupport::TestCase
4
-
5
- test 'search' do
6
- shop = Shop.create
7
- seed = rand
8
- days = [1,2,3]
9
- opens_at = Time.now.to_i
10
- closes_at = (Time.now + 1.day).to_i
11
- assert_equal(
12
- {
13
- query: {
14
- function_score: {
15
- functions: [
16
- { random_score: { seed: seed } },
17
- {
18
- weight: 400,
19
- filter: {
20
- bool: {
21
- must: [
22
- { term: {} }
23
- ]
24
- }
25
- }
26
- }
27
- ]
28
- },
29
- query: {
30
- filtered: {
31
- filter: {
32
- bool: {
33
- should: [
34
- { term: { :'schedules.days' => days } }
35
- ],
36
- must: [
37
- { range: { :'schedules.opens_at' => { lte: opens_at } } }
38
- ],
39
- must_not: [
40
- {
41
- has_parent: {
42
- type: 'products',
43
- query: {
44
- filtered: {
45
- filter: {
46
- bool: {
47
- must: [
48
- {
49
- term: {
50
- _parent: shop.id
51
- }
52
- }
53
- ]
54
- }
55
- },
56
- query: {
57
- match_all: {}
58
- }
59
- }
60
- }
61
- }
62
- }
63
- ]
64
- }
65
- }
66
- }
67
- }
68
- },
69
- sort: [
70
- { name: 'asc' }
71
- ],
72
- size: {}
73
- },
74
- build(:search) do
75
- query do
76
- function_score do
77
- functions do
78
- random_score do
79
- seed seed
80
- end
81
- filter weight: 400 do
82
- bool do
83
- must do
84
- term
85
- end
86
- end
87
- end
88
- end
89
- end
90
- query do
91
- filtered do
92
- filter do
93
- bool do
94
- should do
95
- term 'schedules.days' => days
96
- end
97
- must do
98
- range 'schedules.opens_at' do
99
- lte opens_at
100
- end
101
- end
102
- must_not do
103
- has_parent do
104
- type 'products'
105
- query :products, shop: shop
106
- end
107
- end
108
- end
109
- end
110
- end
111
- end
112
- end
113
- sort %w(asc) do |order|
114
- name order
115
- end
116
- size
117
- end
118
- )
119
- end
120
-
121
- private
122
-
123
- def build(type, &block)
124
- klass = Indexes::Dsl.const_get(type.to_s.classify)
125
- klass.new(&block).to_h
126
- end
127
-
128
- end
@@ -1,5 +0,0 @@
1
- # Add your own tasks in files placed in lib/tasks ending in .rake,
2
- # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
-
4
- require File.expand_path('../config/application', __FILE__)
5
- Rails.application.load_tasks
@@ -1,13 +0,0 @@
1
- // This is a manifest file that'll be compiled into application.js, which will include all the files
2
- // listed below.
3
- //
4
- // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
- // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
- //
7
- // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
- // compiled file.
9
- //
10
- // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
- // about supported directives.
12
- //
13
- //= require_tree .