elasticsearch_query_parser 0.0.4

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 (66) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +27 -0
  3. data/README.md +196 -0
  4. data/lib/doc/ElasticsearchQueryParser/Grammar/Parser.html +108 -0
  5. data/lib/doc/ElasticsearchQueryParser/Grammar/Presenters/Operator/InvalidOperatorString.html +206 -0
  6. data/lib/doc/ElasticsearchQueryParser/Grammar/Presenters/Operator.html +209 -0
  7. data/lib/doc/ElasticsearchQueryParser/Grammar/Presenters/Query.html +208 -0
  8. data/lib/doc/ElasticsearchQueryParser/Grammar/Presenters/Term.html +203 -0
  9. data/lib/doc/ElasticsearchQueryParser/Grammar/Presenters.html +99 -0
  10. data/lib/doc/ElasticsearchQueryParser/Grammar/Transformer.html +108 -0
  11. data/lib/doc/ElasticsearchQueryParser/Grammar.html +99 -0
  12. data/lib/doc/ElasticsearchQueryParser/ParseFailedException.html +163 -0
  13. data/lib/doc/ElasticsearchQueryParser/Sentence.html +219 -0
  14. data/lib/doc/ElasticsearchQueryParser.html +238 -0
  15. data/lib/doc/created.rid +8 -0
  16. data/lib/doc/css/fonts.css +167 -0
  17. data/lib/doc/css/rdoc.css +619 -0
  18. data/lib/doc/fonts/Lato-Light.ttf +0 -0
  19. data/lib/doc/fonts/Lato-LightItalic.ttf +0 -0
  20. data/lib/doc/fonts/Lato-Regular.ttf +0 -0
  21. data/lib/doc/fonts/Lato-RegularItalic.ttf +0 -0
  22. data/lib/doc/fonts/SourceCodePro-Bold.ttf +0 -0
  23. data/lib/doc/fonts/SourceCodePro-Regular.ttf +0 -0
  24. data/lib/doc/images/add.png +0 -0
  25. data/lib/doc/images/arrow_up.png +0 -0
  26. data/lib/doc/images/brick.png +0 -0
  27. data/lib/doc/images/brick_link.png +0 -0
  28. data/lib/doc/images/bug.png +0 -0
  29. data/lib/doc/images/bullet_black.png +0 -0
  30. data/lib/doc/images/bullet_toggle_minus.png +0 -0
  31. data/lib/doc/images/bullet_toggle_plus.png +0 -0
  32. data/lib/doc/images/date.png +0 -0
  33. data/lib/doc/images/delete.png +0 -0
  34. data/lib/doc/images/find.png +0 -0
  35. data/lib/doc/images/loadingAnimation.gif +0 -0
  36. data/lib/doc/images/macFFBgHack.png +0 -0
  37. data/lib/doc/images/package.png +0 -0
  38. data/lib/doc/images/page_green.png +0 -0
  39. data/lib/doc/images/page_white_text.png +0 -0
  40. data/lib/doc/images/page_white_width.png +0 -0
  41. data/lib/doc/images/plugin.png +0 -0
  42. data/lib/doc/images/ruby.png +0 -0
  43. data/lib/doc/images/tag_blue.png +0 -0
  44. data/lib/doc/images/tag_green.png +0 -0
  45. data/lib/doc/images/transparent.png +0 -0
  46. data/lib/doc/images/wrench.png +0 -0
  47. data/lib/doc/images/wrench_orange.png +0 -0
  48. data/lib/doc/images/zoom.png +0 -0
  49. data/lib/doc/index.html +107 -0
  50. data/lib/doc/js/darkfish.js +84 -0
  51. data/lib/doc/js/navigation.js +105 -0
  52. data/lib/doc/js/navigation.js.gz +0 -0
  53. data/lib/doc/js/search.js +110 -0
  54. data/lib/doc/js/search_index.js +1 -0
  55. data/lib/doc/js/search_index.js.gz +0 -0
  56. data/lib/doc/js/searcher.js +229 -0
  57. data/lib/doc/js/searcher.js.gz +0 -0
  58. data/lib/doc/table_of_contents.html +175 -0
  59. data/lib/elasticsearch_query_parser/grammar/parser.rb +29 -0
  60. data/lib/elasticsearch_query_parser/grammar/presenters/operator.rb +41 -0
  61. data/lib/elasticsearch_query_parser/grammar/presenters/query.rb +45 -0
  62. data/lib/elasticsearch_query_parser/grammar/presenters/term.rb +21 -0
  63. data/lib/elasticsearch_query_parser/grammar/transformer.rb +37 -0
  64. data/lib/elasticsearch_query_parser/sentence.rb +55 -0
  65. data/lib/elasticsearch_query_parser.rb +52 -0
  66. metadata +135 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6c23d8074f9260bd26bf623701beeb91875157a163ee7737b0694d7426d9b9f3
4
+ data.tar.gz: 21d2f8ae94b1f1831ed53a3cc6a475dc820dcbc44c048b6ccc4fb49de2af5ec9
5
+ SHA512:
6
+ metadata.gz: c16fb5af9ae5e50af78d0df43700175fcf3ff7e81c8d843959c60d832462c1eab3b77645be2a6b0d137bcf8f9284c18b365ce2b6d1331088d6a147e73d56a0a3
7
+ data.tar.gz: 2bc6b81b3fb1cd976101b919480815b2d2545230b0f2c2b3a05222e49008944d914039037116d5158a34ba7ed6b599cdad01b2190e8f329f8befc6b6f2368bae
data/LICENSE ADDED
@@ -0,0 +1,27 @@
1
+ // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2
+ //
3
+ // Redistribution and use in source and binary forms, with or without
4
+ // modification, are permitted provided that the following conditions are
5
+ // met:
6
+ //
7
+ // * Redistributions of source code must retain the above copyright
8
+ // notice, this list of conditions and the following disclaimer.
9
+ // * Redistributions in binary form must reproduce the above
10
+ // copyright notice, this list of conditions and the following disclaimer
11
+ // in the documentation and/or other materials provided with the
12
+ // distribution.
13
+ // * Neither the name of Google Inc. nor the names of its
14
+ // contributors may be used to endorse or promote products derived from
15
+ // this software without specific prior written permission.
16
+ //
17
+ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18
+ // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19
+ // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20
+ // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21
+ // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22
+ // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23
+ // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24
+ // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25
+ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
+ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
+ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,196 @@
1
+ # Elasticsearch query parser
2
+
3
+ [![Build Status](https://semaphoreci.com/api/v1/khabibullin_ruslan/elasticsearch_query_parser/branches/master/badge.svg)](https://semaphoreci.com/khabibullin_ruslan/elasticsearch_query_parser)
4
+ [![Gem Version](https://badge.fury.io/rb/elasticsearch_query_parser.svg)](https://badge.fury.io/rb/elasticsearch_query_parser)
5
+
6
+ - I can search “London” and it will return everyone with “London”
7
+ - And then a complex example could be a boolean search such as: ((('London' OR 'Paris') OR 'Madrid') AND 'Venture Capital') NOT VC
8
+
9
+ ## Hot to install
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem "elasticsearch_query_parser"
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ ```sh
20
+ $ bundle
21
+ ```
22
+
23
+ ## How to use
24
+
25
+ ```ruby
26
+ require "elasticsearch_query_parser"
27
+
28
+ ElasticsearchQueryParser.parse_query("London")
29
+ # => { query: { bool: { should: [{ match: { text: { query: "London", operator: "and" } } }] } } }
30
+
31
+ ElasticsearchQueryParser.parse_query("London Madrid")
32
+ =begin
33
+ {
34
+ query: {
35
+ bool: {
36
+ should: [
37
+ { match: { text: { query: "London", operator: "and" } } },
38
+ { match: { text: { query: "Madrid", operator: "and" } } }
39
+ ]
40
+ }
41
+ }
42
+ }
43
+ =end
44
+
45
+ ElasticsearchQueryParser.parse_query("London OR Madrid")
46
+ =begin
47
+ {
48
+ query: {
49
+ bool: {
50
+ should: [
51
+ { match: { text: { query: "London", operator: "and" } } },
52
+ { match: { text: { query: "Madrid", operator: "and" } } }
53
+ ]
54
+ }
55
+ }
56
+ }
57
+ =end
58
+
59
+ ElasticsearchQueryParser.parse_query("(London OR Madrid) AND Paris")
60
+ =begin
61
+ {
62
+ query: {
63
+ bool: {
64
+ must: [
65
+ { match: { text: { query: "Paris", operator: "and" } } },
66
+ {
67
+ bool: {
68
+ should:[
69
+ { match: { text: { query: "Madrid", operator: "and" } } },
70
+ { match: { text: { query: "London", operator:"and" } } }
71
+ ]
72
+ }
73
+ }
74
+ ]
75
+ }
76
+ }
77
+ }
78
+ =end
79
+
80
+ ElasticsearchQueryParser.parse_query("(((London OR Paris) OR Madrid) AND 'Venture Capital') NOT VC")
81
+ =begin
82
+ {
83
+ query: {
84
+ bool: {
85
+ must: [
86
+ { match: { text: { query: "Venture Capital", operator: "and" } } },
87
+ {
88
+ bool: {
89
+ should: [
90
+ { match: { text: { query: "Madrid", operator: "and" } } },
91
+ {
92
+ bool: {
93
+ should: [
94
+ { match: { text: { query: "Paris", operator: "and" }}},
95
+ { match: { text: { query: "London", operator: "and" } } }
96
+ ]
97
+ }
98
+ }
99
+ ]
100
+ }
101
+ }
102
+ ],
103
+ must_not:[{ match: { text: { query: "VC", operator: "and" } } }]
104
+ }
105
+ }
106
+ }
107
+ =end
108
+
109
+ ElasticsearchQueryParser.parse_query("Paris AND (London OR Madrid)")
110
+ =begin
111
+ {
112
+ query:{
113
+ bool: {
114
+ must:[
115
+ { match: { text: { query: "Paris", operator: "and" } } },
116
+ {
117
+ bool: {
118
+ should:[
119
+ { match: { text: { query: "London", operator: "and" } } },
120
+ { match: { text: { query: "Madrid", operator: "and" } } }
121
+ ]
122
+ }
123
+ }
124
+ ]
125
+ }
126
+ }
127
+ }
128
+ =end
129
+
130
+ ElasticsearchQueryParser.parse_query("VC AND ('Venture Capital' AND (Madrid OR (Paris AND London)))")
131
+ =begin
132
+ {
133
+ query: {
134
+ bool: {
135
+ must:[
136
+ { match: { text: { query: "VC", operator: "and" } } },
137
+ {
138
+ bool: {
139
+ must: [
140
+ { match: { text: { query: "Venture Capital", operator: "and" } } },
141
+ {
142
+ bool: {
143
+ should:[
144
+ { match: { text: { query: "Madrid", operator: "and" } } },
145
+ {
146
+ bool: {
147
+ must: [
148
+ { match: { text: { query: "Paris", operator: "and" } } },
149
+ { match: { text: { query: "London", operator: "and" } } }
150
+ ]
151
+ }
152
+ }
153
+ ]
154
+ }
155
+ }
156
+ ]
157
+ }
158
+ }
159
+ ]
160
+ }
161
+ }
162
+ }
163
+ =end
164
+
165
+ ElasticsearchQueryParser.parse_query("((London OR Madrid) NOT VC) NOT 'Venture Capital'")
166
+ =begin
167
+ {
168
+ query: {
169
+ bool: {
170
+ should: [
171
+ { match: { text: { query: "Madrid", operator: "and" } } },
172
+ { match: { text: { query: "London", operator: "and" } } }
173
+ ],
174
+ must_not: [
175
+ { match: { text: { query: "VC", operator: "and" } } },
176
+ { match: { text: { query: "Venture Capital", operator: "and" } } }
177
+ ]
178
+ }
179
+ }
180
+ }
181
+ =end
182
+ ```
183
+
184
+ ## How to change Elastic field name
185
+
186
+ By default `#parse_query` generates elastic query with `text` attribute. You can customize field name via config:
187
+
188
+ ```ruby
189
+ ElasticsearchQueryParser.configure do |config|
190
+ # elastic_field_name can accepts symbol or string
191
+ config.elastic_field_name = "title"
192
+ end
193
+
194
+ ElasticsearchQueryParser.parse_query("London")
195
+ # => { query: { bool: { should: [{ match: { "title": { query: "London", operator: "and" } } }] } } }
196
+ ```
@@ -0,0 +1,108 @@
1
+ <!DOCTYPE html>
2
+
3
+ <html>
4
+ <head>
5
+ <meta charset="UTF-8">
6
+
7
+ <title>class ElasticsearchQueryParser::Grammar::Parser - RDoc Documentation</title>
8
+
9
+ <script type="text/javascript">
10
+ var rdoc_rel_prefix = "../../";
11
+ var index_rel_prefix = "../../";
12
+ </script>
13
+
14
+ <script src="../../js/navigation.js" defer></script>
15
+ <script src="../../js/search.js" defer></script>
16
+ <script src="../../js/search_index.js" defer></script>
17
+ <script src="../../js/searcher.js" defer></script>
18
+ <script src="../../js/darkfish.js" defer></script>
19
+
20
+ <link href="../../css/fonts.css" rel="stylesheet">
21
+ <link href="../../css/rdoc.css" rel="stylesheet">
22
+
23
+
24
+
25
+
26
+ <body id="top" role="document" class="class">
27
+ <nav role="navigation">
28
+ <div id="project-navigation">
29
+ <div id="home-section" role="region" title="Quick navigation" class="nav-section">
30
+ <h2>
31
+ <a href="../../index.html" rel="home">Home</a>
32
+ </h2>
33
+
34
+ <div id="table-of-contents-navigation">
35
+ <a href="../../table_of_contents.html#pages">Pages</a>
36
+ <a href="../../table_of_contents.html#classes">Classes</a>
37
+ <a href="../../table_of_contents.html#methods">Methods</a>
38
+ </div>
39
+ </div>
40
+
41
+ <div id="search-section" role="search" class="project-section initially-hidden">
42
+ <form action="#" method="get" accept-charset="utf-8">
43
+ <div id="search-field-wrapper">
44
+ <input id="search-field" role="combobox" aria-label="Search"
45
+ aria-autocomplete="list" aria-controls="search-results"
46
+ type="text" name="search" placeholder="Search" spellcheck="false"
47
+ title="Type to search, Up and Down to navigate, Enter to load">
48
+ </div>
49
+
50
+ <ul id="search-results" aria-label="Search Results"
51
+ aria-busy="false" aria-expanded="false"
52
+ aria-atomic="false" class="initially-hidden"></ul>
53
+ </form>
54
+ </div>
55
+
56
+ </div>
57
+
58
+
59
+
60
+ <div id="class-metadata">
61
+
62
+ <div id="parent-class-section" class="nav-section">
63
+ <h3>Parent</h3>
64
+
65
+
66
+ <p class="link">Parslet::Parser
67
+
68
+ </div>
69
+
70
+
71
+
72
+
73
+ </div>
74
+ </nav>
75
+
76
+ <main role="main" aria-labelledby="class-ElasticsearchQueryParser::Grammar::Parser">
77
+ <h1 id="class-ElasticsearchQueryParser::Grammar::Parser" class="class">
78
+ class ElasticsearchQueryParser::Grammar::Parser
79
+ </h1>
80
+
81
+ <section class="description">
82
+
83
+ <p>User query grammar description (PEG tree)</p>
84
+
85
+ </section>
86
+
87
+
88
+ <section id="5Buntitled-5D" class="documentation-section">
89
+
90
+
91
+
92
+
93
+
94
+
95
+
96
+
97
+
98
+ </section>
99
+
100
+ </main>
101
+
102
+
103
+ <footer id="validator-badges" role="contentinfo">
104
+ <p><a href="https://validator.w3.org/check/referer">Validate</a>
105
+ <p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.2.0.
106
+ <p>Based on <a href="http://deveiate.org/projects/Darkfish-RDoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
107
+ </footer>
108
+
@@ -0,0 +1,206 @@
1
+ <!DOCTYPE html>
2
+
3
+ <html>
4
+ <head>
5
+ <meta charset="UTF-8">
6
+
7
+ <title>class ElasticsearchQueryParser::Grammar::Presenters::Operator::InvalidOperatorString - RDoc Documentation</title>
8
+
9
+ <script type="text/javascript">
10
+ var rdoc_rel_prefix = "../../../../";
11
+ var index_rel_prefix = "../../../../";
12
+ </script>
13
+
14
+ <script src="../../../../js/navigation.js" defer></script>
15
+ <script src="../../../../js/search.js" defer></script>
16
+ <script src="../../../../js/search_index.js" defer></script>
17
+ <script src="../../../../js/searcher.js" defer></script>
18
+ <script src="../../../../js/darkfish.js" defer></script>
19
+
20
+ <link href="../../../../css/fonts.css" rel="stylesheet">
21
+ <link href="../../../../css/rdoc.css" rel="stylesheet">
22
+
23
+
24
+
25
+
26
+ <body id="top" role="document" class="class">
27
+ <nav role="navigation">
28
+ <div id="project-navigation">
29
+ <div id="home-section" role="region" title="Quick navigation" class="nav-section">
30
+ <h2>
31
+ <a href="../../../../index.html" rel="home">Home</a>
32
+ </h2>
33
+
34
+ <div id="table-of-contents-navigation">
35
+ <a href="../../../../table_of_contents.html#pages">Pages</a>
36
+ <a href="../../../../table_of_contents.html#classes">Classes</a>
37
+ <a href="../../../../table_of_contents.html#methods">Methods</a>
38
+ </div>
39
+ </div>
40
+
41
+ <div id="search-section" role="search" class="project-section initially-hidden">
42
+ <form action="#" method="get" accept-charset="utf-8">
43
+ <div id="search-field-wrapper">
44
+ <input id="search-field" role="combobox" aria-label="Search"
45
+ aria-autocomplete="list" aria-controls="search-results"
46
+ type="text" name="search" placeholder="Search" spellcheck="false"
47
+ title="Type to search, Up and Down to navigate, Enter to load">
48
+ </div>
49
+
50
+ <ul id="search-results" aria-label="Search Results"
51
+ aria-busy="false" aria-expanded="false"
52
+ aria-atomic="false" class="initially-hidden"></ul>
53
+ </form>
54
+ </div>
55
+
56
+ </div>
57
+
58
+
59
+
60
+ <div id="class-metadata">
61
+
62
+ <div id="parent-class-section" class="nav-section">
63
+ <h3>Parent</h3>
64
+
65
+
66
+ <p class="link">StandardError
67
+
68
+ </div>
69
+
70
+
71
+
72
+ <!-- Method Quickref -->
73
+ <div id="method-list-section" class="nav-section">
74
+ <h3>Methods</h3>
75
+
76
+ <ul class="link-list" role="directory">
77
+
78
+ <li class="calls-super" ><a href="#method-c-new">::new</a>
79
+
80
+ <li ><a href="#method-i-message">#message</a>
81
+
82
+ </ul>
83
+ </div>
84
+
85
+ </div>
86
+ </nav>
87
+
88
+ <main role="main" aria-labelledby="class-ElasticsearchQueryParser::Grammar::Presenters::Operator::InvalidOperatorString">
89
+ <h1 id="class-ElasticsearchQueryParser::Grammar::Presenters::Operator::InvalidOperatorString" class="class">
90
+ class ElasticsearchQueryParser::Grammar::Presenters::Operator::InvalidOperatorString
91
+ </h1>
92
+
93
+ <section class="description">
94
+
95
+ </section>
96
+
97
+
98
+ <section id="5Buntitled-5D" class="documentation-section">
99
+
100
+
101
+
102
+
103
+
104
+
105
+
106
+
107
+
108
+ <section id="public-class-5Buntitled-5D-method-details" class="method-section">
109
+ <header>
110
+ <h3>Public Class Methods</h3>
111
+ </header>
112
+
113
+
114
+ <div id="method-c-new" class="method-detail ">
115
+
116
+ <div class="method-heading">
117
+ <span class="method-name">new</span><span
118
+ class="method-args">(string)</span>
119
+
120
+ <span class="method-click-advice">click to toggle source</span>
121
+
122
+ </div>
123
+
124
+
125
+ <div class="method-description">
126
+
127
+
128
+
129
+
130
+ <div class="method-calls-super">
131
+ Calls superclass method
132
+
133
+ </div>
134
+
135
+
136
+
137
+ <div class="method-source-code" id="new-source">
138
+ <pre><span class="ruby-comment"># File elasticsearch_query_parser/grammar/presenters/operator.rb, line 9</span>
139
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">initialize</span>(<span class="ruby-identifier">string</span>)
140
+ <span class="ruby-ivar">@string</span> = <span class="ruby-identifier">string</span>
141
+ <span class="ruby-keyword">super</span>
142
+ <span class="ruby-keyword">end</span></pre>
143
+ </div>
144
+
145
+ </div>
146
+
147
+
148
+
149
+
150
+ </div>
151
+
152
+
153
+ </section>
154
+
155
+ <section id="public-instance-5Buntitled-5D-method-details" class="method-section">
156
+ <header>
157
+ <h3>Public Instance Methods</h3>
158
+ </header>
159
+
160
+
161
+ <div id="method-i-message" class="method-detail ">
162
+
163
+ <div class="method-heading">
164
+ <span class="method-name">message</span><span
165
+ class="method-args">()</span>
166
+
167
+ <span class="method-click-advice">click to toggle source</span>
168
+
169
+ </div>
170
+
171
+
172
+ <div class="method-description">
173
+
174
+
175
+
176
+
177
+
178
+
179
+ <div class="method-source-code" id="message-source">
180
+ <pre><span class="ruby-comment"># File elasticsearch_query_parser/grammar/presenters/operator.rb, line 14</span>
181
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">message</span>
182
+ <span class="ruby-node">&quot;Invalid operator: #{string}&quot;</span>
183
+ <span class="ruby-keyword">end</span></pre>
184
+ </div>
185
+
186
+ </div>
187
+
188
+
189
+
190
+
191
+ </div>
192
+
193
+
194
+ </section>
195
+
196
+ </section>
197
+
198
+ </main>
199
+
200
+
201
+ <footer id="validator-badges" role="contentinfo">
202
+ <p><a href="https://validator.w3.org/check/referer">Validate</a>
203
+ <p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.2.0.
204
+ <p>Based on <a href="http://deveiate.org/projects/Darkfish-RDoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
205
+ </footer>
206
+