Skip to content

Commit

Permalink
Moved <> back in the term
Browse files Browse the repository at this point in the history
This reverts commit 17a1186.
  • Loading branch information
bastien committed Jul 2, 2015
1 parent 22afde8 commit 70cd016
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 77 deletions.
52 changes: 17 additions & 35 deletions lib/lucene-query-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ module.exports = (function(){
"paren_exp": parse_paren_exp,
"field_exp": parse_field_exp,
"fieldname": parse_fieldname,
"separator": parse_separator,
"term": parse_term,
"unquoted_term": parse_unquoted_term,
"term_char": parse_term_char,
Expand Down Expand Up @@ -443,12 +442,7 @@ module.exports = (function(){
range['field'] =
fieldname == ''
? "<implicit>"
: fieldname['name'];

range['separator'] =
fieldname == ''
? null
: fieldname['separator'];
: fieldname;

return range;
})(pos0, result0[0], result0[1]);
Expand All @@ -474,8 +468,7 @@ module.exports = (function(){
}
if (result0 !== null) {
result0 = (function(offset, fieldname, node) {
node['field']= fieldname['name'];
node['separator']= fieldname['separator'];
node['field']= fieldname;
return node;
})(pos0, result0[0], result0[1]);
}
Expand Down Expand Up @@ -505,11 +498,7 @@ module.exports = (function(){
'field':
fieldname == ''
? "<implicit>"
: fieldname['name'],
'separator':
fieldname == ''
? null
: fieldname['separator']
: fieldname
};

for(var key in term)
Expand All @@ -534,7 +523,15 @@ module.exports = (function(){
pos1 = pos;
result0 = parse_unquoted_term();
if (result0 !== null) {
result1 = parse_separator();
if (/^[:]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[:]");
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
Expand All @@ -546,31 +543,16 @@ module.exports = (function(){
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, fieldname, separator) {
return {'name': fieldname, 'separator': separator}
})(pos0, result0[0], result0[1]);
result0 = (function(offset, fieldname) {
return fieldname;
})(pos0, result0[0]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}

function parse_separator() {
var result0;

if (/^[>:<]/.test(input.charAt(pos))) {
result0 = input.charAt(pos);
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("[>:<]");
}
}
return result0;
}

function parse_term() {
var result0, result1, result2, result3, result4, result5;
var pos0, pos1;
Expand Down Expand Up @@ -745,13 +727,13 @@ module.exports = (function(){
}
}
if (result0 === null) {
if (/^[^: <>\t\r\n\f{}()"\/^~[\]]/.test(input.charAt(pos))) {
if (/^[^: \t\r\n\f{}()"\/^~[\]]/.test(input.charAt(pos))) {
result0 = input.charAt(pos);
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("[^: <>\\t\\r\\n\\f{}()\"\\/^~[\\]]");
matchFailed("[^: \\t\\r\\n\\f{}()\"\\/^~[\\]]");
}
}
}
Expand Down
26 changes: 6 additions & 20 deletions lib/lucene-query.grammar
Original file line number Diff line number Diff line change
Expand Up @@ -138,19 +138,13 @@ field_exp
range['field'] =
fieldname == ''
? "<implicit>"
: fieldname['name'];

range['separator'] =
fieldname == ''
? null
: fieldname['separator'];
: fieldname;

return range;
}
/ fieldname:fieldname node:paren_exp
{
node['field']= fieldname['name'];
node['separator']= fieldname['separator'];
node['field']= fieldname;
return node;
}
/ fieldname:fieldname? term:term
Expand All @@ -159,11 +153,7 @@ field_exp
'field':
fieldname == ''
? "<implicit>"
: fieldname['name'],
'separator':
fieldname == ''
? null
: fieldname['separator']
: fieldname
};

for(var key in term)
Expand All @@ -173,14 +163,11 @@ field_exp
}

fieldname
= fieldname:unquoted_term separator:separator
= fieldname:unquoted_term [:]
{
return {'name': fieldname, 'separator': separator}
return fieldname;
}

separator
= [>:<]

term
= op:prefix_operator_exp? term:quoted_term proximity:proximity_modifier? boost:boost_modifier? _*
{
Expand Down Expand Up @@ -226,8 +213,7 @@ unquoted_term
}

term_char
= '.' / [^: <>\t\r\n\f\{\}()"/^~\[\]]

= '.' / [^: \t\r\n\f\{\}()"/^~\[\]]

quoted_term
= '"' term:[^"]+ '"'
Expand Down
26 changes: 4 additions & 22 deletions spec/lucene-query-parser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ describe("lucenequeryparser: term parsing", function() {
});

it("accepts terms with '-'", function() {
var results = lucenequeryparser.parse('created_at>now-5d');
var results = lucenequeryparser.parse('created_at:>now-5d');

expect(results['left']['term']).toBe('now-5d');
expect(results['left']['term']).toBe('>now-5d');
});

it("accepts terms with '+'", function() {
var results = lucenequeryparser.parse('published_at>now+5d');
var results = lucenequeryparser.parse('published_at:>now+5d');

expect(results['left']['term']).toBe('now+5d');
expect(results['left']['term']).toBe('>now+5d');
});
});

Expand Down Expand Up @@ -261,24 +261,6 @@ describe("lucenequeryparser: range expressions", function() {
});
});

describe("lucenequeryparser: term seperator", function() {
it("accepts > as field/term separator", function() {
var results = lucenequeryparser.parse('created_at>yesterday');

expect(results['left']['field']).toBe('created_at');
expect(results['left']['term']).toBe('yesterday');
expect(results['left']['separator']).toBe('>');
});

it("accepts < as field/term separator", function() {
var results = lucenequeryparser.parse('created_at<today');

expect(results['left']['field']).toBe('created_at');
expect(results['left']['term']).toBe('today');
expect(results['left']['separator']).toBe('<');
});
});

describe("lucenequeryparser: Lucene Query syntax documentation examples", function() {

/*
Expand Down

0 comments on commit 70cd016

Please sign in to comment.