elasticsearch_query_parser 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +27 -0
- data/README.md +196 -0
- data/lib/doc/ElasticsearchQueryParser/Grammar/Parser.html +108 -0
- data/lib/doc/ElasticsearchQueryParser/Grammar/Presenters/Operator/InvalidOperatorString.html +206 -0
- data/lib/doc/ElasticsearchQueryParser/Grammar/Presenters/Operator.html +209 -0
- data/lib/doc/ElasticsearchQueryParser/Grammar/Presenters/Query.html +208 -0
- data/lib/doc/ElasticsearchQueryParser/Grammar/Presenters/Term.html +203 -0
- data/lib/doc/ElasticsearchQueryParser/Grammar/Presenters.html +99 -0
- data/lib/doc/ElasticsearchQueryParser/Grammar/Transformer.html +108 -0
- data/lib/doc/ElasticsearchQueryParser/Grammar.html +99 -0
- data/lib/doc/ElasticsearchQueryParser/ParseFailedException.html +163 -0
- data/lib/doc/ElasticsearchQueryParser/Sentence.html +219 -0
- data/lib/doc/ElasticsearchQueryParser.html +238 -0
- data/lib/doc/created.rid +8 -0
- data/lib/doc/css/fonts.css +167 -0
- data/lib/doc/css/rdoc.css +619 -0
- data/lib/doc/fonts/Lato-Light.ttf +0 -0
- data/lib/doc/fonts/Lato-LightItalic.ttf +0 -0
- data/lib/doc/fonts/Lato-Regular.ttf +0 -0
- data/lib/doc/fonts/Lato-RegularItalic.ttf +0 -0
- data/lib/doc/fonts/SourceCodePro-Bold.ttf +0 -0
- data/lib/doc/fonts/SourceCodePro-Regular.ttf +0 -0
- data/lib/doc/images/add.png +0 -0
- data/lib/doc/images/arrow_up.png +0 -0
- data/lib/doc/images/brick.png +0 -0
- data/lib/doc/images/brick_link.png +0 -0
- data/lib/doc/images/bug.png +0 -0
- data/lib/doc/images/bullet_black.png +0 -0
- data/lib/doc/images/bullet_toggle_minus.png +0 -0
- data/lib/doc/images/bullet_toggle_plus.png +0 -0
- data/lib/doc/images/date.png +0 -0
- data/lib/doc/images/delete.png +0 -0
- data/lib/doc/images/find.png +0 -0
- data/lib/doc/images/loadingAnimation.gif +0 -0
- data/lib/doc/images/macFFBgHack.png +0 -0
- data/lib/doc/images/package.png +0 -0
- data/lib/doc/images/page_green.png +0 -0
- data/lib/doc/images/page_white_text.png +0 -0
- data/lib/doc/images/page_white_width.png +0 -0
- data/lib/doc/images/plugin.png +0 -0
- data/lib/doc/images/ruby.png +0 -0
- data/lib/doc/images/tag_blue.png +0 -0
- data/lib/doc/images/tag_green.png +0 -0
- data/lib/doc/images/transparent.png +0 -0
- data/lib/doc/images/wrench.png +0 -0
- data/lib/doc/images/wrench_orange.png +0 -0
- data/lib/doc/images/zoom.png +0 -0
- data/lib/doc/index.html +107 -0
- data/lib/doc/js/darkfish.js +84 -0
- data/lib/doc/js/navigation.js +105 -0
- data/lib/doc/js/navigation.js.gz +0 -0
- data/lib/doc/js/search.js +110 -0
- data/lib/doc/js/search_index.js +1 -0
- data/lib/doc/js/search_index.js.gz +0 -0
- data/lib/doc/js/searcher.js +229 -0
- data/lib/doc/js/searcher.js.gz +0 -0
- data/lib/doc/table_of_contents.html +175 -0
- data/lib/elasticsearch_query_parser/grammar/parser.rb +29 -0
- data/lib/elasticsearch_query_parser/grammar/presenters/operator.rb +41 -0
- data/lib/elasticsearch_query_parser/grammar/presenters/query.rb +45 -0
- data/lib/elasticsearch_query_parser/grammar/presenters/term.rb +21 -0
- data/lib/elasticsearch_query_parser/grammar/transformer.rb +37 -0
- data/lib/elasticsearch_query_parser/sentence.rb +55 -0
- data/lib/elasticsearch_query_parser.rb +52 -0
- metadata +135 -0
data/lib/doc/index.html
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
|
3
|
+
<html>
|
4
|
+
<head>
|
5
|
+
<meta charset="UTF-8">
|
6
|
+
|
7
|
+
<title>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="file">
|
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
|
+
|
42
|
+
<div id="search-section" role="search" class="project-section initially-hidden">
|
43
|
+
<form action="#" method="get" accept-charset="utf-8">
|
44
|
+
<div id="search-field-wrapper">
|
45
|
+
<input id="search-field" role="combobox" aria-label="Search"
|
46
|
+
aria-autocomplete="list" aria-controls="search-results"
|
47
|
+
type="text" name="search" placeholder="Search" spellcheck="false"
|
48
|
+
title="Type to search, Up and Down to navigate, Enter to load">
|
49
|
+
</div>
|
50
|
+
|
51
|
+
<ul id="search-results" aria-label="Search Results"
|
52
|
+
aria-busy="false" aria-expanded="false"
|
53
|
+
aria-atomic="false" class="initially-hidden"></ul>
|
54
|
+
</form>
|
55
|
+
</div>
|
56
|
+
|
57
|
+
</div>
|
58
|
+
|
59
|
+
<div id="project-metadata">
|
60
|
+
|
61
|
+
<div id="classindex-section" class="nav-section">
|
62
|
+
<h3>Class and Module Index</h3>
|
63
|
+
|
64
|
+
<ul class="link-list">
|
65
|
+
|
66
|
+
<li><a href="./ElasticsearchQueryParser.html">ElasticsearchQueryParser</a>
|
67
|
+
|
68
|
+
<li><a href="./ElasticsearchQueryParser/Grammar.html">ElasticsearchQueryParser::Grammar</a>
|
69
|
+
|
70
|
+
<li><a href="./ElasticsearchQueryParser/Grammar/Parser.html">ElasticsearchQueryParser::Grammar::Parser</a>
|
71
|
+
|
72
|
+
<li><a href="./ElasticsearchQueryParser/Grammar/Presenters.html">ElasticsearchQueryParser::Grammar::Presenters</a>
|
73
|
+
|
74
|
+
<li><a href="./ElasticsearchQueryParser/Grammar/Presenters/Operator.html">ElasticsearchQueryParser::Grammar::Presenters::Operator</a>
|
75
|
+
|
76
|
+
<li><a href="./ElasticsearchQueryParser/Grammar/Presenters/Operator/InvalidOperatorString.html">ElasticsearchQueryParser::Grammar::Presenters::Operator::InvalidOperatorString</a>
|
77
|
+
|
78
|
+
<li><a href="./ElasticsearchQueryParser/Grammar/Presenters/Query.html">ElasticsearchQueryParser::Grammar::Presenters::Query</a>
|
79
|
+
|
80
|
+
<li><a href="./ElasticsearchQueryParser/Grammar/Presenters/Term.html">ElasticsearchQueryParser::Grammar::Presenters::Term</a>
|
81
|
+
|
82
|
+
<li><a href="./ElasticsearchQueryParser/Grammar/Transformer.html">ElasticsearchQueryParser::Grammar::Transformer</a>
|
83
|
+
|
84
|
+
<li><a href="./ElasticsearchQueryParser/ParseFailedException.html">ElasticsearchQueryParser::ParseFailedException</a>
|
85
|
+
|
86
|
+
<li><a href="./ElasticsearchQueryParser/Sentence.html">ElasticsearchQueryParser::Sentence</a>
|
87
|
+
|
88
|
+
</ul>
|
89
|
+
</div>
|
90
|
+
|
91
|
+
</div>
|
92
|
+
</nav>
|
93
|
+
|
94
|
+
<main role="main">
|
95
|
+
|
96
|
+
<p>This is the API documentation for RDoc Documentation.
|
97
|
+
|
98
|
+
</main>
|
99
|
+
|
100
|
+
|
101
|
+
|
102
|
+
<footer id="validator-badges" role="contentinfo">
|
103
|
+
<p><a href="https://validator.w3.org/check/referer">Validate</a>
|
104
|
+
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.2.0.
|
105
|
+
<p>Based on <a href="http://deveiate.org/projects/Darkfish-RDoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
|
106
|
+
</footer>
|
107
|
+
|
@@ -0,0 +1,84 @@
|
|
1
|
+
/**
|
2
|
+
*
|
3
|
+
* Darkfish Page Functions
|
4
|
+
* $Id: darkfish.js 53 2009-01-07 02:52:03Z deveiant $
|
5
|
+
*
|
6
|
+
* Author: Michael Granger <mgranger@laika.com>
|
7
|
+
*
|
8
|
+
*/
|
9
|
+
|
10
|
+
/* Provide console simulation for firebug-less environments */
|
11
|
+
/*
|
12
|
+
if (!("console" in window) || !("firebug" in console)) {
|
13
|
+
var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml",
|
14
|
+
"group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];
|
15
|
+
|
16
|
+
window.console = {};
|
17
|
+
for (var i = 0; i < names.length; ++i)
|
18
|
+
window.console[names[i]] = function() {};
|
19
|
+
};
|
20
|
+
*/
|
21
|
+
|
22
|
+
|
23
|
+
function showSource( e ) {
|
24
|
+
var target = e.target;
|
25
|
+
while (!target.classList.contains('method-detail')) {
|
26
|
+
target = target.parentNode;
|
27
|
+
}
|
28
|
+
if (typeof target !== "undefined" && target !== null) {
|
29
|
+
target = target.querySelector('.method-source-code');
|
30
|
+
}
|
31
|
+
if (typeof target !== "undefined" && target !== null) {
|
32
|
+
target.classList.toggle('active-menu')
|
33
|
+
}
|
34
|
+
};
|
35
|
+
|
36
|
+
function hookSourceViews() {
|
37
|
+
document.querySelectorAll('.method-heading').forEach(function (codeObject) {
|
38
|
+
codeObject.addEventListener('click', showSource);
|
39
|
+
});
|
40
|
+
};
|
41
|
+
|
42
|
+
function hookSearch() {
|
43
|
+
var input = document.querySelector('#search-field');
|
44
|
+
var result = document.querySelector('#search-results');
|
45
|
+
result.classList.remove("initially-hidden");
|
46
|
+
|
47
|
+
var search_section = document.querySelector('#search-section');
|
48
|
+
search_section.classList.remove("initially-hidden");
|
49
|
+
|
50
|
+
var search = new Search(search_data, input, result);
|
51
|
+
|
52
|
+
search.renderItem = function(result) {
|
53
|
+
var li = document.createElement('li');
|
54
|
+
var html = '';
|
55
|
+
|
56
|
+
// TODO add relative path to <script> per-page
|
57
|
+
html += '<p class="search-match"><a href="' + index_rel_prefix + result.path + '">' + this.hlt(result.title);
|
58
|
+
if (result.params)
|
59
|
+
html += '<span class="params">' + result.params + '</span>';
|
60
|
+
html += '</a>';
|
61
|
+
|
62
|
+
|
63
|
+
if (result.namespace)
|
64
|
+
html += '<p class="search-namespace">' + this.hlt(result.namespace);
|
65
|
+
|
66
|
+
if (result.snippet)
|
67
|
+
html += '<div class="search-snippet">' + result.snippet + '</div>';
|
68
|
+
|
69
|
+
li.innerHTML = html;
|
70
|
+
|
71
|
+
return li;
|
72
|
+
}
|
73
|
+
|
74
|
+
search.select = function(result) {
|
75
|
+
window.location.href = result.firstChild.firstChild.href;
|
76
|
+
}
|
77
|
+
|
78
|
+
search.scrollIntoView = search.scrollInWindow;
|
79
|
+
};
|
80
|
+
|
81
|
+
document.addEventListener('DOMContentLoaded', function() {
|
82
|
+
hookSourceViews();
|
83
|
+
hookSearch();
|
84
|
+
});
|
@@ -0,0 +1,105 @@
|
|
1
|
+
/*
|
2
|
+
* Navigation allows movement using the arrow keys through the search results.
|
3
|
+
*
|
4
|
+
* When using this library you will need to set scrollIntoView to the
|
5
|
+
* appropriate function for your layout. Use scrollInWindow if the container
|
6
|
+
* is not scrollable and scrollInElement if the container is a separate
|
7
|
+
* scrolling region.
|
8
|
+
*/
|
9
|
+
Navigation = new function() {
|
10
|
+
this.initNavigation = function() {
|
11
|
+
var _this = this;
|
12
|
+
|
13
|
+
document.addEventListener('keydown', function(e) {
|
14
|
+
_this.onkeydown(e);
|
15
|
+
});
|
16
|
+
|
17
|
+
this.navigationActive = true;
|
18
|
+
}
|
19
|
+
|
20
|
+
this.setNavigationActive = function(state) {
|
21
|
+
this.navigationActive = state;
|
22
|
+
}
|
23
|
+
|
24
|
+
this.onkeydown = function(e) {
|
25
|
+
if (!this.navigationActive) return;
|
26
|
+
switch(e.keyCode) {
|
27
|
+
case 37: //Event.KEY_LEFT:
|
28
|
+
if (this.moveLeft()) e.preventDefault();
|
29
|
+
break;
|
30
|
+
case 38: //Event.KEY_UP:
|
31
|
+
if (e.keyCode == 38 || e.ctrlKey) {
|
32
|
+
if (this.moveUp()) e.preventDefault();
|
33
|
+
}
|
34
|
+
break;
|
35
|
+
case 39: //Event.KEY_RIGHT:
|
36
|
+
if (this.moveRight()) e.preventDefault();
|
37
|
+
break;
|
38
|
+
case 40: //Event.KEY_DOWN:
|
39
|
+
if (e.keyCode == 40 || e.ctrlKey) {
|
40
|
+
if (this.moveDown()) e.preventDefault();
|
41
|
+
}
|
42
|
+
break;
|
43
|
+
case 13: //Event.KEY_RETURN:
|
44
|
+
if (this.current) e.preventDefault();
|
45
|
+
this.select(this.current);
|
46
|
+
break;
|
47
|
+
}
|
48
|
+
if (e.ctrlKey && e.shiftKey) this.select(this.current);
|
49
|
+
}
|
50
|
+
|
51
|
+
this.moveRight = function() {
|
52
|
+
}
|
53
|
+
|
54
|
+
this.moveLeft = function() {
|
55
|
+
}
|
56
|
+
|
57
|
+
this.move = function(isDown) {
|
58
|
+
}
|
59
|
+
|
60
|
+
this.moveUp = function() {
|
61
|
+
return this.move(false);
|
62
|
+
}
|
63
|
+
|
64
|
+
this.moveDown = function() {
|
65
|
+
return this.move(true);
|
66
|
+
}
|
67
|
+
|
68
|
+
/*
|
69
|
+
* Scrolls to the given element in the scrollable element view.
|
70
|
+
*/
|
71
|
+
this.scrollInElement = function(element, view) {
|
72
|
+
var offset, viewHeight, viewScroll, height;
|
73
|
+
offset = element.offsetTop;
|
74
|
+
height = element.offsetHeight;
|
75
|
+
viewHeight = view.offsetHeight;
|
76
|
+
viewScroll = view.scrollTop;
|
77
|
+
|
78
|
+
if (offset - viewScroll + height > viewHeight) {
|
79
|
+
view.scrollTop = offset - viewHeight + height;
|
80
|
+
}
|
81
|
+
if (offset < viewScroll) {
|
82
|
+
view.scrollTop = offset;
|
83
|
+
}
|
84
|
+
}
|
85
|
+
|
86
|
+
/*
|
87
|
+
* Scrolls to the given element in the window. The second argument is
|
88
|
+
* ignored
|
89
|
+
*/
|
90
|
+
this.scrollInWindow = function(element, ignored) {
|
91
|
+
var offset, viewHeight, viewScroll, height;
|
92
|
+
offset = element.offsetTop;
|
93
|
+
height = element.offsetHeight;
|
94
|
+
viewHeight = window.innerHeight;
|
95
|
+
viewScroll = window.scrollY;
|
96
|
+
|
97
|
+
if (offset - viewScroll + height > viewHeight) {
|
98
|
+
window.scrollTo(window.scrollX, offset - viewHeight + height);
|
99
|
+
}
|
100
|
+
if (offset < viewScroll) {
|
101
|
+
window.scrollTo(window.scrollX, offset);
|
102
|
+
}
|
103
|
+
}
|
104
|
+
}
|
105
|
+
|
Binary file
|
@@ -0,0 +1,110 @@
|
|
1
|
+
Search = function(data, input, result) {
|
2
|
+
this.data = data;
|
3
|
+
this.input = input;
|
4
|
+
this.result = result;
|
5
|
+
|
6
|
+
this.current = null;
|
7
|
+
this.view = this.result.parentNode;
|
8
|
+
this.searcher = new Searcher(data.index);
|
9
|
+
this.init();
|
10
|
+
}
|
11
|
+
|
12
|
+
Search.prototype = Object.assign({}, Navigation, new function() {
|
13
|
+
var suid = 1;
|
14
|
+
|
15
|
+
this.init = function() {
|
16
|
+
var _this = this;
|
17
|
+
var observer = function(e) {
|
18
|
+
switch(e.keyCode) {
|
19
|
+
case 38: // Event.KEY_UP
|
20
|
+
case 40: // Event.KEY_DOWN
|
21
|
+
return;
|
22
|
+
}
|
23
|
+
_this.search(_this.input.value);
|
24
|
+
};
|
25
|
+
this.input.addEventListener('keyup', observer);
|
26
|
+
this.input.addEventListener('click', observer); // mac's clear field
|
27
|
+
|
28
|
+
this.searcher.ready(function(results, isLast) {
|
29
|
+
_this.addResults(results, isLast);
|
30
|
+
})
|
31
|
+
|
32
|
+
this.initNavigation();
|
33
|
+
this.setNavigationActive(false);
|
34
|
+
}
|
35
|
+
|
36
|
+
this.search = function(value, selectFirstMatch) {
|
37
|
+
value = value.trim().toLowerCase();
|
38
|
+
if (value) {
|
39
|
+
this.setNavigationActive(true);
|
40
|
+
} else {
|
41
|
+
this.setNavigationActive(false);
|
42
|
+
}
|
43
|
+
|
44
|
+
if (value == '') {
|
45
|
+
this.lastQuery = value;
|
46
|
+
this.result.innerHTML = '';
|
47
|
+
this.result.setAttribute('aria-expanded', 'false');
|
48
|
+
this.setNavigationActive(false);
|
49
|
+
} else if (value != this.lastQuery) {
|
50
|
+
this.lastQuery = value;
|
51
|
+
this.result.setAttribute('aria-busy', 'true');
|
52
|
+
this.result.setAttribute('aria-expanded', 'true');
|
53
|
+
this.firstRun = true;
|
54
|
+
this.searcher.find(value);
|
55
|
+
}
|
56
|
+
}
|
57
|
+
|
58
|
+
this.addResults = function(results, isLast) {
|
59
|
+
var target = this.result;
|
60
|
+
if (this.firstRun && (results.length > 0 || isLast)) {
|
61
|
+
this.current = null;
|
62
|
+
this.result.innerHTML = '';
|
63
|
+
}
|
64
|
+
|
65
|
+
for (var i=0, l = results.length; i < l; i++) {
|
66
|
+
var item = this.renderItem.call(this, results[i]);
|
67
|
+
item.setAttribute('id', 'search-result-' + target.childElementCount);
|
68
|
+
target.appendChild(item);
|
69
|
+
};
|
70
|
+
|
71
|
+
if (this.firstRun && results.length > 0) {
|
72
|
+
this.firstRun = false;
|
73
|
+
this.current = target.firstChild;
|
74
|
+
this.current.classList.add('search-selected');
|
75
|
+
}
|
76
|
+
//TODO: ECMAScript
|
77
|
+
//if (jQuery.browser.msie) this.$element[0].className += '';
|
78
|
+
|
79
|
+
if (isLast) this.result.setAttribute('aria-busy', 'false');
|
80
|
+
}
|
81
|
+
|
82
|
+
this.move = function(isDown) {
|
83
|
+
if (!this.current) return;
|
84
|
+
var next = isDown ? this.current.nextElementSibling : this.current.previousElementSibling;
|
85
|
+
if (next) {
|
86
|
+
this.current.classList.remove('search-selected');
|
87
|
+
next.classList.add('search-selected');
|
88
|
+
this.input.setAttribute('aria-activedescendant', next.getAttribute('id'));
|
89
|
+
this.scrollIntoView(next, this.view);
|
90
|
+
this.current = next;
|
91
|
+
this.input.value = next.firstChild.firstChild.text;
|
92
|
+
this.input.select();
|
93
|
+
}
|
94
|
+
return true;
|
95
|
+
}
|
96
|
+
|
97
|
+
this.hlt = function(html) {
|
98
|
+
return this.escapeHTML(html).
|
99
|
+
replace(/\u0001/g, '<em>').
|
100
|
+
replace(/\u0002/g, '</em>');
|
101
|
+
}
|
102
|
+
|
103
|
+
this.escapeHTML = function(html) {
|
104
|
+
return html.replace(/[&<>]/g, function(c) {
|
105
|
+
return '&#' + c.charCodeAt(0) + ';';
|
106
|
+
});
|
107
|
+
}
|
108
|
+
|
109
|
+
});
|
110
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
var search_data = {"index":{"searchIndex":["elasticsearchqueryparser","grammar","parser","presenters","operator","invalidoperatorstring","query","term","transformer","parsefailedexception","sentence","configuration()","configure()","message()","new()","new()","new()","new()","new()","new()","parse_query()","to_elasticsearch()","to_elasticsearch()","to_elasticsearch()","to_s()"],"longSearchIndex":["elasticsearchqueryparser","elasticsearchqueryparser::grammar","elasticsearchqueryparser::grammar::parser","elasticsearchqueryparser::grammar::presenters","elasticsearchqueryparser::grammar::presenters::operator","elasticsearchqueryparser::grammar::presenters::operator::invalidoperatorstring","elasticsearchqueryparser::grammar::presenters::query","elasticsearchqueryparser::grammar::presenters::term","elasticsearchqueryparser::grammar::transformer","elasticsearchqueryparser::parsefailedexception","elasticsearchqueryparser::sentence","elasticsearchqueryparser::configuration()","elasticsearchqueryparser::configure()","elasticsearchqueryparser::grammar::presenters::operator::invalidoperatorstring#message()","elasticsearchqueryparser::grammar::presenters::operator::new()","elasticsearchqueryparser::grammar::presenters::operator::invalidoperatorstring::new()","elasticsearchqueryparser::grammar::presenters::query::new()","elasticsearchqueryparser::grammar::presenters::term::new()","elasticsearchqueryparser::parsefailedexception::new()","elasticsearchqueryparser::sentence::new()","elasticsearchqueryparser::parse_query()","elasticsearchqueryparser::grammar::presenters::operator#to_elasticsearch()","elasticsearchqueryparser::grammar::presenters::query#to_elasticsearch()","elasticsearchqueryparser::grammar::presenters::term#to_elasticsearch()","elasticsearchqueryparser::sentence#to_s()"],"info":[["ElasticsearchQueryParser","","ElasticsearchQueryParser.html","","<p>Mail ElasticsearchQueryParser interface\n"],["ElasticsearchQueryParser::Grammar","","ElasticsearchQueryParser/Grammar.html","",""],["ElasticsearchQueryParser::Grammar::Parser","","ElasticsearchQueryParser/Grammar/Parser.html","","<p>User query grammar description (PEG tree)\n"],["ElasticsearchQueryParser::Grammar::Presenters","","ElasticsearchQueryParser/Grammar/Presenters.html","",""],["ElasticsearchQueryParser::Grammar::Presenters::Operator","","ElasticsearchQueryParser/Grammar/Presenters/Operator.html","",""],["ElasticsearchQueryParser::Grammar::Presenters::Operator::InvalidOperatorString","","ElasticsearchQueryParser/Grammar/Presenters/Operator/InvalidOperatorString.html","",""],["ElasticsearchQueryParser::Grammar::Presenters::Query","","ElasticsearchQueryParser/Grammar/Presenters/Query.html","",""],["ElasticsearchQueryParser::Grammar::Presenters::Term","","ElasticsearchQueryParser/Grammar/Presenters/Term.html","",""],["ElasticsearchQueryParser::Grammar::Transformer","","ElasticsearchQueryParser/Grammar/Transformer.html","","<p>Transform rules (accept PEG trees) from Parslet grammar and modify trees according to described rules …\n"],["ElasticsearchQueryParser::ParseFailedException","","ElasticsearchQueryParser/ParseFailedException.html","",""],["ElasticsearchQueryParser::Sentence","","ElasticsearchQueryParser/Sentence.html","","<p>Transform user query to `Left to Right` expression for parser usage\n"],["configuration","ElasticsearchQueryParser","ElasticsearchQueryParser.html#method-c-configuration","()","<p>Gem configuration object For now only contain 1 attribute: `elastic_field_name` option (by default :text) …\n"],["configure","ElasticsearchQueryParser","ElasticsearchQueryParser.html#method-c-configure","()","<p>For gem configuration For now only `elastic_field_name` can be modified. See README.md for details\n"],["message","ElasticsearchQueryParser::Grammar::Presenters::Operator::InvalidOperatorString","ElasticsearchQueryParser/Grammar/Presenters/Operator/InvalidOperatorString.html#method-i-message","()",""],["new","ElasticsearchQueryParser::Grammar::Presenters::Operator","ElasticsearchQueryParser/Grammar/Presenters/Operator.html#method-c-new","(operator)",""],["new","ElasticsearchQueryParser::Grammar::Presenters::Operator::InvalidOperatorString","ElasticsearchQueryParser/Grammar/Presenters/Operator/InvalidOperatorString.html#method-c-new","(string)",""],["new","ElasticsearchQueryParser::Grammar::Presenters::Query","ElasticsearchQueryParser/Grammar/Presenters/Query.html#method-c-new","(terms, operator, nested_query)",""],["new","ElasticsearchQueryParser::Grammar::Presenters::Term","ElasticsearchQueryParser/Grammar/Presenters/Term.html#method-c-new","(term)",""],["new","ElasticsearchQueryParser::ParseFailedException","ElasticsearchQueryParser/ParseFailedException.html#method-c-new","(parse_failure_cause)",""],["new","ElasticsearchQueryParser::Sentence","ElasticsearchQueryParser/Sentence.html#method-c-new","(sentence)","<p>Initialize with user input\n"],["parse_query","ElasticsearchQueryParser","ElasticsearchQueryParser.html#method-c-parse_query","(user_query)","<p>Parse given string into Elastic query object (see README.md for more examples) Example:\n\n<pre>>> ElasticsearchQueryParser.parse_query("London") ...</pre>\n"],["to_elasticsearch","ElasticsearchQueryParser::Grammar::Presenters::Operator","ElasticsearchQueryParser/Grammar/Presenters/Operator.html#method-i-to_elasticsearch","()",""],["to_elasticsearch","ElasticsearchQueryParser::Grammar::Presenters::Query","ElasticsearchQueryParser/Grammar/Presenters/Query.html#method-i-to_elasticsearch","(include_bool_header = true)","<p>If its `must_not` operator - just add `must_not` to root node and continue analyze nested queries Otherwise …\n"],["to_elasticsearch","ElasticsearchQueryParser::Grammar::Presenters::Term","ElasticsearchQueryParser/Grammar/Presenters/Term.html#method-i-to_elasticsearch","()",""],["to_s","ElasticsearchQueryParser::Sentence","ElasticsearchQueryParser/Sentence.html#method-i-to_s","()","<p>Return valid for parser usage user input Example:\n\n<pre>>> ElasticsearchQueryParser.new("(London AND Madrid) ...</pre>\n"]]}}
|
Binary file
|
@@ -0,0 +1,229 @@
|
|
1
|
+
Searcher = function(data) {
|
2
|
+
this.data = data;
|
3
|
+
this.handlers = [];
|
4
|
+
}
|
5
|
+
|
6
|
+
Searcher.prototype = new function() {
|
7
|
+
// search is performed in chunks of 1000 for non-blocking user input
|
8
|
+
var CHUNK_SIZE = 1000;
|
9
|
+
// do not try to find more than 100 results
|
10
|
+
var MAX_RESULTS = 100;
|
11
|
+
var huid = 1;
|
12
|
+
var suid = 1;
|
13
|
+
var runs = 0;
|
14
|
+
|
15
|
+
this.find = function(query) {
|
16
|
+
var queries = splitQuery(query);
|
17
|
+
var regexps = buildRegexps(queries);
|
18
|
+
var highlighters = buildHilighters(queries);
|
19
|
+
var state = { from: 0, pass: 0, limit: MAX_RESULTS, n: suid++};
|
20
|
+
var _this = this;
|
21
|
+
|
22
|
+
this.currentSuid = state.n;
|
23
|
+
|
24
|
+
if (!query) return;
|
25
|
+
|
26
|
+
var run = function() {
|
27
|
+
// stop current search thread if new search started
|
28
|
+
if (state.n != _this.currentSuid) return;
|
29
|
+
|
30
|
+
var results =
|
31
|
+
performSearch(_this.data, regexps, queries, highlighters, state);
|
32
|
+
var hasMore = (state.limit > 0 && state.pass < 4);
|
33
|
+
|
34
|
+
triggerResults.call(_this, results, !hasMore);
|
35
|
+
if (hasMore) {
|
36
|
+
setTimeout(run, 2);
|
37
|
+
}
|
38
|
+
runs++;
|
39
|
+
};
|
40
|
+
runs = 0;
|
41
|
+
|
42
|
+
// start search thread
|
43
|
+
run();
|
44
|
+
}
|
45
|
+
|
46
|
+
/* ----- Events ------ */
|
47
|
+
this.ready = function(fn) {
|
48
|
+
fn.huid = huid;
|
49
|
+
this.handlers.push(fn);
|
50
|
+
}
|
51
|
+
|
52
|
+
/* ----- Utilities ------ */
|
53
|
+
function splitQuery(query) {
|
54
|
+
return query.split(/(\s+|::?|\(\)?)/).filter(function(string) {
|
55
|
+
return string.match(/\S/);
|
56
|
+
});
|
57
|
+
}
|
58
|
+
|
59
|
+
function buildRegexps(queries) {
|
60
|
+
return queries.map(function(query) {
|
61
|
+
return new RegExp(query.replace(/(.)/g, '([$1])([^$1]*?)'), 'i');
|
62
|
+
});
|
63
|
+
}
|
64
|
+
|
65
|
+
function buildHilighters(queries) {
|
66
|
+
return queries.map(function(query) {
|
67
|
+
return query.split('').map(function(l, i) {
|
68
|
+
return '\u0001$' + (i*2+1) + '\u0002$' + (i*2+2);
|
69
|
+
}).join('');
|
70
|
+
});
|
71
|
+
}
|
72
|
+
|
73
|
+
// function longMatchRegexp(index, longIndex, regexps) {
|
74
|
+
// for (var i = regexps.length - 1; i >= 0; i--){
|
75
|
+
// if (!index.match(regexps[i]) && !longIndex.match(regexps[i])) return false;
|
76
|
+
// };
|
77
|
+
// return true;
|
78
|
+
// }
|
79
|
+
|
80
|
+
|
81
|
+
/* ----- Mathchers ------ */
|
82
|
+
|
83
|
+
/*
|
84
|
+
* This record matches if the index starts with queries[0] and the record
|
85
|
+
* matches all of the regexps
|
86
|
+
*/
|
87
|
+
function matchPassBeginning(index, longIndex, queries, regexps) {
|
88
|
+
if (index.indexOf(queries[0]) != 0) return false;
|
89
|
+
for (var i=1, l = regexps.length; i < l; i++) {
|
90
|
+
if (!index.match(regexps[i]) && !longIndex.match(regexps[i]))
|
91
|
+
return false;
|
92
|
+
};
|
93
|
+
return true;
|
94
|
+
}
|
95
|
+
|
96
|
+
/*
|
97
|
+
* This record matches if the longIndex starts with queries[0] and the
|
98
|
+
* longIndex matches all of the regexps
|
99
|
+
*/
|
100
|
+
function matchPassLongIndex(index, longIndex, queries, regexps) {
|
101
|
+
if (longIndex.indexOf(queries[0]) != 0) return false;
|
102
|
+
for (var i=1, l = regexps.length; i < l; i++) {
|
103
|
+
if (!longIndex.match(regexps[i]))
|
104
|
+
return false;
|
105
|
+
};
|
106
|
+
return true;
|
107
|
+
}
|
108
|
+
|
109
|
+
/*
|
110
|
+
* This record matches if the index contains queries[0] and the record
|
111
|
+
* matches all of the regexps
|
112
|
+
*/
|
113
|
+
function matchPassContains(index, longIndex, queries, regexps) {
|
114
|
+
if (index.indexOf(queries[0]) == -1) return false;
|
115
|
+
for (var i=1, l = regexps.length; i < l; i++) {
|
116
|
+
if (!index.match(regexps[i]) && !longIndex.match(regexps[i]))
|
117
|
+
return false;
|
118
|
+
};
|
119
|
+
return true;
|
120
|
+
}
|
121
|
+
|
122
|
+
/*
|
123
|
+
* This record matches if regexps[0] matches the index and the record
|
124
|
+
* matches all of the regexps
|
125
|
+
*/
|
126
|
+
function matchPassRegexp(index, longIndex, queries, regexps) {
|
127
|
+
if (!index.match(regexps[0])) return false;
|
128
|
+
for (var i=1, l = regexps.length; i < l; i++) {
|
129
|
+
if (!index.match(regexps[i]) && !longIndex.match(regexps[i]))
|
130
|
+
return false;
|
131
|
+
};
|
132
|
+
return true;
|
133
|
+
}
|
134
|
+
|
135
|
+
|
136
|
+
/* ----- Highlighters ------ */
|
137
|
+
function highlightRegexp(info, queries, regexps, highlighters) {
|
138
|
+
var result = createResult(info);
|
139
|
+
for (var i=0, l = regexps.length; i < l; i++) {
|
140
|
+
result.title = result.title.replace(regexps[i], highlighters[i]);
|
141
|
+
result.namespace = result.namespace.replace(regexps[i], highlighters[i]);
|
142
|
+
};
|
143
|
+
return result;
|
144
|
+
}
|
145
|
+
|
146
|
+
function hltSubstring(string, pos, length) {
|
147
|
+
return string.substring(0, pos) + '\u0001' + string.substring(pos, pos + length) + '\u0002' + string.substring(pos + length);
|
148
|
+
}
|
149
|
+
|
150
|
+
function highlightQuery(info, queries, regexps, highlighters) {
|
151
|
+
var result = createResult(info);
|
152
|
+
var pos = 0;
|
153
|
+
var lcTitle = result.title.toLowerCase();
|
154
|
+
|
155
|
+
pos = lcTitle.indexOf(queries[0]);
|
156
|
+
if (pos != -1) {
|
157
|
+
result.title = hltSubstring(result.title, pos, queries[0].length);
|
158
|
+
}
|
159
|
+
|
160
|
+
result.namespace = result.namespace.replace(regexps[0], highlighters[0]);
|
161
|
+
for (var i=1, l = regexps.length; i < l; i++) {
|
162
|
+
result.title = result.title.replace(regexps[i], highlighters[i]);
|
163
|
+
result.namespace = result.namespace.replace(regexps[i], highlighters[i]);
|
164
|
+
};
|
165
|
+
return result;
|
166
|
+
}
|
167
|
+
|
168
|
+
function createResult(info) {
|
169
|
+
var result = {};
|
170
|
+
result.title = info[0];
|
171
|
+
result.namespace = info[1];
|
172
|
+
result.path = info[2];
|
173
|
+
result.params = info[3];
|
174
|
+
result.snippet = info[4];
|
175
|
+
result.badge = info[6];
|
176
|
+
return result;
|
177
|
+
}
|
178
|
+
|
179
|
+
/* ----- Searching ------ */
|
180
|
+
function performSearch(data, regexps, queries, highlighters, state) {
|
181
|
+
var searchIndex = data.searchIndex;
|
182
|
+
var longSearchIndex = data.longSearchIndex;
|
183
|
+
var info = data.info;
|
184
|
+
var result = [];
|
185
|
+
var i = state.from;
|
186
|
+
var l = searchIndex.length;
|
187
|
+
var togo = CHUNK_SIZE;
|
188
|
+
var matchFunc, hltFunc;
|
189
|
+
|
190
|
+
while (state.pass < 4 && state.limit > 0 && togo > 0) {
|
191
|
+
if (state.pass == 0) {
|
192
|
+
matchFunc = matchPassBeginning;
|
193
|
+
hltFunc = highlightQuery;
|
194
|
+
} else if (state.pass == 1) {
|
195
|
+
matchFunc = matchPassLongIndex;
|
196
|
+
hltFunc = highlightQuery;
|
197
|
+
} else if (state.pass == 2) {
|
198
|
+
matchFunc = matchPassContains;
|
199
|
+
hltFunc = highlightQuery;
|
200
|
+
} else if (state.pass == 3) {
|
201
|
+
matchFunc = matchPassRegexp;
|
202
|
+
hltFunc = highlightRegexp;
|
203
|
+
}
|
204
|
+
|
205
|
+
for (; togo > 0 && i < l && state.limit > 0; i++, togo--) {
|
206
|
+
if (info[i].n == state.n) continue;
|
207
|
+
if (matchFunc(searchIndex[i], longSearchIndex[i], queries, regexps)) {
|
208
|
+
info[i].n = state.n;
|
209
|
+
result.push(hltFunc(info[i], queries, regexps, highlighters));
|
210
|
+
state.limit--;
|
211
|
+
}
|
212
|
+
};
|
213
|
+
if (searchIndex.length <= i) {
|
214
|
+
state.pass++;
|
215
|
+
i = state.from = 0;
|
216
|
+
} else {
|
217
|
+
state.from = i;
|
218
|
+
}
|
219
|
+
}
|
220
|
+
return result;
|
221
|
+
}
|
222
|
+
|
223
|
+
function triggerResults(results, isLast) {
|
224
|
+
this.handlers.forEach(function(fn) {
|
225
|
+
fn.call(this, results, isLast)
|
226
|
+
});
|
227
|
+
}
|
228
|
+
}
|
229
|
+
|
Binary file
|