mm_es_search 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/.project +18 -0
- data/Gemfile +4 -0
- data/Rakefile +1 -0
- data/lib/mm_es_search/api/facet/abstract_facet.rb +28 -0
- data/lib/mm_es_search/api/facet/date_histogram_facet.rb +11 -0
- data/lib/mm_es_search/api/facet/filter_facet.rb +9 -0
- data/lib/mm_es_search/api/facet/geo_distance_facet.rb +9 -0
- data/lib/mm_es_search/api/facet/histogram_facet.rb +9 -0
- data/lib/mm_es_search/api/facet/query_facet.rb +9 -0
- data/lib/mm_es_search/api/facet/range_facet.rb +36 -0
- data/lib/mm_es_search/api/facet/range_facet_row.rb +97 -0
- data/lib/mm_es_search/api/facet/range_item.rb +17 -0
- data/lib/mm_es_search/api/facet/statistical_facet.rb +33 -0
- data/lib/mm_es_search/api/facet/statistical_facet_result.rb +36 -0
- data/lib/mm_es_search/api/facet/terms_facet.rb +62 -0
- data/lib/mm_es_search/api/facet/terms_facet_row.rb +35 -0
- data/lib/mm_es_search/api/facet/terms_stats_facet.rb +9 -0
- data/lib/mm_es_search/api/highlight/result_highlight.rb +40 -0
- data/lib/mm_es_search/api/query/abstract_filter.rb +15 -0
- data/lib/mm_es_search/api/query/abstract_query.rb +48 -0
- data/lib/mm_es_search/api/query/and_filter.rb +9 -0
- data/lib/mm_es_search/api/query/bool_filter.rb +11 -0
- data/lib/mm_es_search/api/query/bool_query.rb +67 -0
- data/lib/mm_es_search/api/query/constant_score_query.rb +31 -0
- data/lib/mm_es_search/api/query/custom_filters_score_query.rb +52 -0
- data/lib/mm_es_search/api/query/custom_score_query.rb +31 -0
- data/lib/mm_es_search/api/query/dismax_query.rb +29 -0
- data/lib/mm_es_search/api/query/filtered_query.rb +30 -0
- data/lib/mm_es_search/api/query/has_child_filter.rb +11 -0
- data/lib/mm_es_search/api/query/has_child_query.rb +25 -0
- data/lib/mm_es_search/api/query/has_parent_filter.rb +11 -0
- data/lib/mm_es_search/api/query/has_parent_query.rb +25 -0
- data/lib/mm_es_search/api/query/match_all_filter.rb +11 -0
- data/lib/mm_es_search/api/query/match_all_query.rb +19 -0
- data/lib/mm_es_search/api/query/nested_filter.rb +22 -0
- data/lib/mm_es_search/api/query/nested_query.rb +62 -0
- data/lib/mm_es_search/api/query/not_filter.rb +9 -0
- data/lib/mm_es_search/api/query/or_filter.rb +9 -0
- data/lib/mm_es_search/api/query/prefix_filter.rb +11 -0
- data/lib/mm_es_search/api/query/prefix_query.rb +34 -0
- data/lib/mm_es_search/api/query/query_filter.rb +28 -0
- data/lib/mm_es_search/api/query/query_string_query.rb +37 -0
- data/lib/mm_es_search/api/query/range_filter.rb +11 -0
- data/lib/mm_es_search/api/query/range_query.rb +57 -0
- data/lib/mm_es_search/api/query/scored_filter.rb +29 -0
- data/lib/mm_es_search/api/query/single_bool_filter.rb +66 -0
- data/lib/mm_es_search/api/query/term_filter.rb +11 -0
- data/lib/mm_es_search/api/query/term_query.rb +34 -0
- data/lib/mm_es_search/api/query/terms_filter.rb +11 -0
- data/lib/mm_es_search/api/query/terms_query.rb +58 -0
- data/lib/mm_es_search/api/query/text_query.rb +42 -0
- data/lib/mm_es_search/api/query/top_children_query.rb +28 -0
- data/lib/mm_es_search/api/sort/root_sort.rb +36 -0
- data/lib/mm_es_search/models/abstract_facet_model.rb +23 -0
- data/lib/mm_es_search/models/abstract_query_model.rb +21 -0
- data/lib/mm_es_search/models/abstract_range_facet_model.rb +365 -0
- data/lib/mm_es_search/models/abstract_search_model.OLD +538 -0
- data/lib/mm_es_search/models/abstract_search_model.rb +521 -0
- data/lib/mm_es_search/models/abstract_sort_model.rb +13 -0
- data/lib/mm_es_search/models/abstract_terms_facet_model.rb +87 -0
- data/lib/mm_es_search/models/root_sort_model.rb +20 -0
- data/lib/mm_es_search/models/virtual_field_sort.rb +52 -0
- data/lib/mm_es_search/utils/facet_row_utils.rb +86 -0
- data/lib/mm_es_search/utils/search_logger.rb +10 -0
- data/lib/mm_es_search/version.rb +3 -0
- data/lib/mm_es_search.rb +124 -0
- data/mm_es_search.gemspec +24 -0
- metadata +132 -0
@@ -0,0 +1,86 @@
|
|
1
|
+
module MmEsSearch
|
2
|
+
module Utils
|
3
|
+
|
4
|
+
module FacetRowUtils
|
5
|
+
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
key :show_missing, Boolean
|
10
|
+
end
|
11
|
+
|
12
|
+
def required?
|
13
|
+
required
|
14
|
+
end
|
15
|
+
|
16
|
+
def used_or_required?
|
17
|
+
used? || required?
|
18
|
+
end
|
19
|
+
|
20
|
+
def used?
|
21
|
+
checked_rows.any? || show_missing
|
22
|
+
end
|
23
|
+
|
24
|
+
def unused?
|
25
|
+
!used?
|
26
|
+
end
|
27
|
+
|
28
|
+
def find_row_by_params(params)
|
29
|
+
rows.detect do |row|
|
30
|
+
required_row_fields.all? {|field| row[field] == params[field]}
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def checked_rows
|
35
|
+
return [] if rows.empty?
|
36
|
+
rows.select {|row| row.checked?}
|
37
|
+
end
|
38
|
+
|
39
|
+
def positively_checked_rows
|
40
|
+
return [] if rows.empty?
|
41
|
+
rows.select {|row| ["and", "or"].include?(row.checked)}
|
42
|
+
end
|
43
|
+
|
44
|
+
def rows_checked_and
|
45
|
+
return [] if rows.empty?
|
46
|
+
rows.select {|row| row.checked == 'and'}
|
47
|
+
end
|
48
|
+
|
49
|
+
def rows_checked_or
|
50
|
+
return [] if rows.empty?
|
51
|
+
rows.select {|row| row.checked == 'or'}
|
52
|
+
end
|
53
|
+
|
54
|
+
def rows_checked_not
|
55
|
+
return [] if rows.empty?
|
56
|
+
rows.select {|row| row.checked == 'not'}
|
57
|
+
end
|
58
|
+
|
59
|
+
def unchecked_rows
|
60
|
+
return [] if rows.empty?
|
61
|
+
rows.select {|row| row.checked? == false}
|
62
|
+
end
|
63
|
+
|
64
|
+
def to_filter
|
65
|
+
|
66
|
+
if show_missing
|
67
|
+
build_filter
|
68
|
+
else
|
69
|
+
used_rows = checked_rows
|
70
|
+
return nil if used_rows.empty?
|
71
|
+
|
72
|
+
and_array = get_checked_row_params('and')
|
73
|
+
or_array = get_checked_row_params('or')
|
74
|
+
not_array = get_checked_row_params('not')
|
75
|
+
build_filter(and_array, or_array, not_array)
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
def get_checked_row_params(check_mark)
|
81
|
+
checked_rows.select {|row| row.checked == check_mark} .map {|row| row.attributes.only(*required_row_fields)}
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
data/lib/mm_es_search.rb
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
require_relative "mm_es_search/version"
|
2
|
+
require 'active_support/core_ext'
|
3
|
+
|
4
|
+
module MmEsSearch
|
5
|
+
|
6
|
+
def self.root
|
7
|
+
@root ||= File.expand_path(File.dirname(__FILE__))
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.smart_load(path)
|
11
|
+
|
12
|
+
unless @load_mode_detected
|
13
|
+
if @dev_mode = defined?(Rails) and Rails.env == "development"
|
14
|
+
ActiveSupport::Dependencies.autoload_paths << root
|
15
|
+
ActiveSupport::Dependencies.explicitly_unloadable_constants << 'MmEsSearch'
|
16
|
+
end
|
17
|
+
@load_mode_detected = true
|
18
|
+
end
|
19
|
+
|
20
|
+
full_path = File.join(root, "#{path}.rb")
|
21
|
+
|
22
|
+
if @dev_mode
|
23
|
+
load full_path
|
24
|
+
else
|
25
|
+
require full_path
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
smart_load "mm_es_search/utils/search_logger"
|
31
|
+
smart_load "mm_es_search/utils/facet_row_utils"
|
32
|
+
|
33
|
+
smart_load "mm_es_search/api/query/abstract_query"
|
34
|
+
smart_load "mm_es_search/api/query/bool_query"
|
35
|
+
smart_load "mm_es_search/api/query/constant_score_query"
|
36
|
+
smart_load "mm_es_search/api/query/custom_filters_score_query"
|
37
|
+
smart_load "mm_es_search/api/query/custom_score_query"
|
38
|
+
smart_load "mm_es_search/api/query/dismax_query"
|
39
|
+
smart_load "mm_es_search/api/query/filtered_query"
|
40
|
+
smart_load "mm_es_search/api/query/has_child_query"
|
41
|
+
smart_load "mm_es_search/api/query/has_parent_query"
|
42
|
+
smart_load "mm_es_search/api/query/match_all_query"
|
43
|
+
smart_load "mm_es_search/api/query/nested_query"
|
44
|
+
smart_load "mm_es_search/api/query/prefix_query"
|
45
|
+
smart_load "mm_es_search/api/query/query_string_query"
|
46
|
+
smart_load "mm_es_search/api/query/range_query"
|
47
|
+
smart_load "mm_es_search/api/query/term_query"
|
48
|
+
smart_load "mm_es_search/api/query/terms_query"
|
49
|
+
smart_load "mm_es_search/api/query/text_query"
|
50
|
+
smart_load "mm_es_search/api/query/top_children_query"
|
51
|
+
|
52
|
+
smart_load "mm_es_search/api/query/abstract_filter"
|
53
|
+
smart_load "mm_es_search/api/query/single_bool_filter"
|
54
|
+
|
55
|
+
smart_load "mm_es_search/api/query/and_filter"
|
56
|
+
smart_load "mm_es_search/api/query/bool_filter"
|
57
|
+
smart_load "mm_es_search/api/query/has_child_filter"
|
58
|
+
smart_load "mm_es_search/api/query/has_parent_filter"
|
59
|
+
smart_load "mm_es_search/api/query/match_all_filter"
|
60
|
+
smart_load "mm_es_search/api/query/nested_filter"
|
61
|
+
smart_load "mm_es_search/api/query/not_filter"
|
62
|
+
smart_load "mm_es_search/api/query/or_filter"
|
63
|
+
smart_load "mm_es_search/api/query/prefix_filter"
|
64
|
+
smart_load "mm_es_search/api/query/query_filter"
|
65
|
+
smart_load "mm_es_search/api/query/range_filter"
|
66
|
+
smart_load "mm_es_search/api/query/scored_filter"
|
67
|
+
smart_load "mm_es_search/api/query/term_filter"
|
68
|
+
smart_load "mm_es_search/api/query/terms_filter"
|
69
|
+
|
70
|
+
smart_load "mm_es_search/api/facet/terms_facet_row"
|
71
|
+
smart_load "mm_es_search/api/facet/abstract_facet"
|
72
|
+
smart_load "mm_es_search/api/facet/date_histogram_facet"
|
73
|
+
smart_load "mm_es_search/api/facet/filter_facet"
|
74
|
+
smart_load "mm_es_search/api/facet/geo_distance_facet"
|
75
|
+
smart_load "mm_es_search/api/facet/histogram_facet"
|
76
|
+
smart_load "mm_es_search/api/facet/query_facet"
|
77
|
+
smart_load "mm_es_search/api/facet/range_facet"
|
78
|
+
smart_load "mm_es_search/api/facet/range_facet_row"
|
79
|
+
smart_load "mm_es_search/api/facet/range_item"
|
80
|
+
smart_load "mm_es_search/api/facet/statistical_facet"
|
81
|
+
smart_load "mm_es_search/api/facet/statistical_facet_result"
|
82
|
+
smart_load "mm_es_search/api/facet/terms_facet"
|
83
|
+
smart_load "mm_es_search/api/facet/terms_stats_facet"
|
84
|
+
|
85
|
+
smart_load "mm_es_search/api/sort/root_sort"
|
86
|
+
|
87
|
+
smart_load "mm_es_search/api/highlight/result_highlight"
|
88
|
+
|
89
|
+
smart_load "mm_es_search/models/abstract_facet_model"
|
90
|
+
smart_load "mm_es_search/models/abstract_query_model"
|
91
|
+
smart_load "mm_es_search/models/abstract_range_facet_model"
|
92
|
+
smart_load "mm_es_search/models/abstract_search_model"
|
93
|
+
smart_load "mm_es_search/models/abstract_sort_model"
|
94
|
+
smart_load "mm_es_search/models/abstract_terms_facet_model"
|
95
|
+
smart_load "mm_es_search/models/root_sort_model"
|
96
|
+
smart_load "mm_es_search/models/virtual_field_sort"
|
97
|
+
|
98
|
+
def self.directories
|
99
|
+
[
|
100
|
+
"mm_es_search/utils",
|
101
|
+
"mm_es_search/api/query",
|
102
|
+
"mm_es_search/api/facet",
|
103
|
+
"mm_es_search/api/sort",
|
104
|
+
"mm_es_search/api/highlight",
|
105
|
+
"mm_es_search/models"
|
106
|
+
]
|
107
|
+
end
|
108
|
+
|
109
|
+
def self.each_file
|
110
|
+
|
111
|
+
directories.each do |dir, array|
|
112
|
+
dir_constants = dir.split('/').map(&:classify)
|
113
|
+
Dir[File.join(root, dir, "**/*.rb")].sort.each do |fname|
|
114
|
+
basename = File.basename(fname, '.rb')
|
115
|
+
constant = basename.classify.to_sym
|
116
|
+
qualified_constant = (dir_constants + [constant]).join('::')
|
117
|
+
path = fname.chomp File.extname(fname)
|
118
|
+
yield qualified_constant, constant, fname, path, basename
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "mm_es_search/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "mm_es_search"
|
7
|
+
s.version = MmEsSearch::VERSION
|
8
|
+
s.authors = ["Jonathan Chambers"]
|
9
|
+
s.email = ["j.chambers@gmx.net"]
|
10
|
+
s.homepage = "https://github.com/jmchambers/mm_es_search"
|
11
|
+
s.summary = %q{Tools to build a mongomapper model that stores and executes complex elasticsearch queries.}
|
12
|
+
s.description = %q{Provides modules that can form the basis of a mongomapper class implementing a search model.}
|
13
|
+
|
14
|
+
s.rubyforge_project = "mm_es_search"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
# s.add_development_dependency "rspec"
|
23
|
+
# s.add_runtime_dependency "rest-client"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mm_es_search
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Jonathan Chambers
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2012-12-21 00:00:00 +00:00
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: Provides modules that can form the basis of a mongomapper class implementing a search model.
|
22
|
+
email:
|
23
|
+
- j.chambers@gmx.net
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files: []
|
29
|
+
|
30
|
+
files:
|
31
|
+
- .gitignore
|
32
|
+
- .project
|
33
|
+
- Gemfile
|
34
|
+
- Rakefile
|
35
|
+
- lib/mm_es_search.rb
|
36
|
+
- lib/mm_es_search/api/facet/abstract_facet.rb
|
37
|
+
- lib/mm_es_search/api/facet/date_histogram_facet.rb
|
38
|
+
- lib/mm_es_search/api/facet/filter_facet.rb
|
39
|
+
- lib/mm_es_search/api/facet/geo_distance_facet.rb
|
40
|
+
- lib/mm_es_search/api/facet/histogram_facet.rb
|
41
|
+
- lib/mm_es_search/api/facet/query_facet.rb
|
42
|
+
- lib/mm_es_search/api/facet/range_facet.rb
|
43
|
+
- lib/mm_es_search/api/facet/range_facet_row.rb
|
44
|
+
- lib/mm_es_search/api/facet/range_item.rb
|
45
|
+
- lib/mm_es_search/api/facet/statistical_facet.rb
|
46
|
+
- lib/mm_es_search/api/facet/statistical_facet_result.rb
|
47
|
+
- lib/mm_es_search/api/facet/terms_facet.rb
|
48
|
+
- lib/mm_es_search/api/facet/terms_facet_row.rb
|
49
|
+
- lib/mm_es_search/api/facet/terms_stats_facet.rb
|
50
|
+
- lib/mm_es_search/api/highlight/result_highlight.rb
|
51
|
+
- lib/mm_es_search/api/query/abstract_filter.rb
|
52
|
+
- lib/mm_es_search/api/query/abstract_query.rb
|
53
|
+
- lib/mm_es_search/api/query/and_filter.rb
|
54
|
+
- lib/mm_es_search/api/query/bool_filter.rb
|
55
|
+
- lib/mm_es_search/api/query/bool_query.rb
|
56
|
+
- lib/mm_es_search/api/query/constant_score_query.rb
|
57
|
+
- lib/mm_es_search/api/query/custom_filters_score_query.rb
|
58
|
+
- lib/mm_es_search/api/query/custom_score_query.rb
|
59
|
+
- lib/mm_es_search/api/query/dismax_query.rb
|
60
|
+
- lib/mm_es_search/api/query/filtered_query.rb
|
61
|
+
- lib/mm_es_search/api/query/has_child_filter.rb
|
62
|
+
- lib/mm_es_search/api/query/has_child_query.rb
|
63
|
+
- lib/mm_es_search/api/query/has_parent_filter.rb
|
64
|
+
- lib/mm_es_search/api/query/has_parent_query.rb
|
65
|
+
- lib/mm_es_search/api/query/match_all_filter.rb
|
66
|
+
- lib/mm_es_search/api/query/match_all_query.rb
|
67
|
+
- lib/mm_es_search/api/query/nested_filter.rb
|
68
|
+
- lib/mm_es_search/api/query/nested_query.rb
|
69
|
+
- lib/mm_es_search/api/query/not_filter.rb
|
70
|
+
- lib/mm_es_search/api/query/or_filter.rb
|
71
|
+
- lib/mm_es_search/api/query/prefix_filter.rb
|
72
|
+
- lib/mm_es_search/api/query/prefix_query.rb
|
73
|
+
- lib/mm_es_search/api/query/query_filter.rb
|
74
|
+
- lib/mm_es_search/api/query/query_string_query.rb
|
75
|
+
- lib/mm_es_search/api/query/range_filter.rb
|
76
|
+
- lib/mm_es_search/api/query/range_query.rb
|
77
|
+
- lib/mm_es_search/api/query/scored_filter.rb
|
78
|
+
- lib/mm_es_search/api/query/single_bool_filter.rb
|
79
|
+
- lib/mm_es_search/api/query/term_filter.rb
|
80
|
+
- lib/mm_es_search/api/query/term_query.rb
|
81
|
+
- lib/mm_es_search/api/query/terms_filter.rb
|
82
|
+
- lib/mm_es_search/api/query/terms_query.rb
|
83
|
+
- lib/mm_es_search/api/query/text_query.rb
|
84
|
+
- lib/mm_es_search/api/query/top_children_query.rb
|
85
|
+
- lib/mm_es_search/api/sort/root_sort.rb
|
86
|
+
- lib/mm_es_search/models/abstract_facet_model.rb
|
87
|
+
- lib/mm_es_search/models/abstract_query_model.rb
|
88
|
+
- lib/mm_es_search/models/abstract_range_facet_model.rb
|
89
|
+
- lib/mm_es_search/models/abstract_search_model.OLD
|
90
|
+
- lib/mm_es_search/models/abstract_search_model.rb
|
91
|
+
- lib/mm_es_search/models/abstract_sort_model.rb
|
92
|
+
- lib/mm_es_search/models/abstract_terms_facet_model.rb
|
93
|
+
- lib/mm_es_search/models/root_sort_model.rb
|
94
|
+
- lib/mm_es_search/models/virtual_field_sort.rb
|
95
|
+
- lib/mm_es_search/utils/facet_row_utils.rb
|
96
|
+
- lib/mm_es_search/utils/search_logger.rb
|
97
|
+
- lib/mm_es_search/version.rb
|
98
|
+
- mm_es_search.gemspec
|
99
|
+
has_rdoc: true
|
100
|
+
homepage: https://github.com/jmchambers/mm_es_search
|
101
|
+
licenses: []
|
102
|
+
|
103
|
+
post_install_message:
|
104
|
+
rdoc_options: []
|
105
|
+
|
106
|
+
require_paths:
|
107
|
+
- lib
|
108
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
109
|
+
none: false
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
segments:
|
114
|
+
- 0
|
115
|
+
version: "0"
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
none: false
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
segments:
|
122
|
+
- 0
|
123
|
+
version: "0"
|
124
|
+
requirements: []
|
125
|
+
|
126
|
+
rubyforge_project: mm_es_search
|
127
|
+
rubygems_version: 1.3.7
|
128
|
+
signing_key:
|
129
|
+
specification_version: 3
|
130
|
+
summary: Tools to build a mongomapper model that stores and executes complex elasticsearch queries.
|
131
|
+
test_files: []
|
132
|
+
|