fix rex specification and add tests for keyword detection
This commit is contained in:
@@ -3,9 +3,9 @@ macro
|
||||
L_BRACKET \(
|
||||
R_BRACKET \)
|
||||
SPACE \ + # Space char
|
||||
OPERATOR_OR (?i)or
|
||||
OPERATOR_AND (?i)and
|
||||
OPERATOR_NOT (?i)not
|
||||
OPERATOR_OR (?i)\bor\b
|
||||
OPERATOR_AND (?i)\band\b
|
||||
OPERATOR_NOT (?i)\bnot\b
|
||||
TERM_WITH_QUOTES "([^"]*)"
|
||||
TERM_WITHOUT_QUOTES [a-zA-Z0-9\-_]+
|
||||
COLON \:
|
||||
|
||||
@@ -255,5 +255,278 @@ class QueryLexerTester
|
||||
expect(@result[2][0]).to eq :TERM_WITH_QUOTES
|
||||
expect(@result[2][1]).to eq '"tag with or and not inside"'
|
||||
end
|
||||
|
||||
it 'tests query without column name containing AND word inside without quotes' do
|
||||
@result = @evaluator.tokenize('land')
|
||||
|
||||
expect(@result.length).to eq 1
|
||||
|
||||
expect(@result[0][0]).to eq :TERM_WITHOUT_QUOTES
|
||||
expect(@result[0][1]).to eq 'land'
|
||||
end
|
||||
|
||||
it 'tests query without column name containing AND word inside with quotes' do
|
||||
@result = @evaluator.tokenize('"land"')
|
||||
|
||||
expect(@result.length).to eq 1
|
||||
|
||||
expect(@result[0][0]).to eq :TERM_WITH_QUOTES
|
||||
expect(@result[0][1]).to eq '"land"'
|
||||
end
|
||||
|
||||
it 'tests query without column name and with word starting with AND without quotes' do
|
||||
@result = @evaluator.tokenize('andromeda')
|
||||
|
||||
expect(@result.length).to eq 1
|
||||
|
||||
expect(@result[0][0]).to eq :TERM_WITHOUT_QUOTES
|
||||
expect(@result[0][1]).to eq 'andromeda'
|
||||
end
|
||||
|
||||
it 'tests query without column name and with word starting with AND with quotes' do
|
||||
@result = @evaluator.tokenize('"andromeda"')
|
||||
|
||||
expect(@result.length).to eq 1
|
||||
|
||||
expect(@result[0][0]).to eq :TERM_WITH_QUOTES
|
||||
expect(@result[0][1]).to eq '"andromeda"'
|
||||
end
|
||||
|
||||
it 'tests query with column name containing AND word inside' do
|
||||
@result = @evaluator.tokenize('land:some-search-term')
|
||||
|
||||
expect(@result.length).to eq 3
|
||||
|
||||
expect(@result[0][0]).to eq :TERM_WITHOUT_QUOTES
|
||||
expect(@result[0][1]).to eq 'land'
|
||||
expect(@result[1][0]).to eq :COLON
|
||||
expect(@result[2][0]).to eq :TERM_WITHOUT_QUOTES
|
||||
expect(@result[2][1]).to eq 'some-search-term'
|
||||
end
|
||||
|
||||
it 'tests query with column name starting with AND' do
|
||||
@result = @evaluator.tokenize('andromeda:some-search-term')
|
||||
|
||||
expect(@result.length).to eq 3
|
||||
|
||||
expect(@result[0][0]).to eq :TERM_WITHOUT_QUOTES
|
||||
expect(@result[0][1]).to eq 'andromeda'
|
||||
expect(@result[1][0]).to eq :COLON
|
||||
expect(@result[2][0]).to eq :TERM_WITHOUT_QUOTES
|
||||
expect(@result[2][1]).to eq 'some-search-term'
|
||||
end
|
||||
|
||||
it 'tests query with search term without quotes containing AND word inside' do
|
||||
@result = @evaluator.tokenize('name:land')
|
||||
|
||||
expect(@result.length).to eq 3
|
||||
|
||||
expect(@result[0][0]).to eq :TERM_WITHOUT_QUOTES
|
||||
expect(@result[0][1]).to eq 'name'
|
||||
expect(@result[1][0]).to eq :COLON
|
||||
expect(@result[2][0]).to eq :TERM_WITHOUT_QUOTES
|
||||
expect(@result[2][1]).to eq 'land'
|
||||
end
|
||||
|
||||
it 'tests query with search term with quotes containing AND word inside' do
|
||||
@result = @evaluator.tokenize('name:"land"')
|
||||
|
||||
expect(@result.length).to eq 3
|
||||
|
||||
expect(@result[0][0]).to eq :TERM_WITHOUT_QUOTES
|
||||
expect(@result[0][1]).to eq 'name'
|
||||
expect(@result[1][0]).to eq :COLON
|
||||
expect(@result[2][0]).to eq :TERM_WITH_QUOTES
|
||||
expect(@result[2][1]).to eq '"land"'
|
||||
end
|
||||
|
||||
it 'tests query with search term without quotes and search term starting with AND without quotes' do
|
||||
@result = @evaluator.tokenize('name:andromeda')
|
||||
|
||||
expect(@result.length).to eq 3
|
||||
|
||||
expect(@result[0][0]).to eq :TERM_WITHOUT_QUOTES
|
||||
expect(@result[0][1]).to eq 'name'
|
||||
expect(@result[1][0]).to eq :COLON
|
||||
expect(@result[2][0]).to eq :TERM_WITHOUT_QUOTES
|
||||
expect(@result[2][1]).to eq 'andromeda'
|
||||
end
|
||||
|
||||
it 'tests query with search term without quotes and search term starting with AND with quotes' do
|
||||
@result = @evaluator.tokenize('name:"andrew"')
|
||||
|
||||
expect(@result.length).to eq 3
|
||||
|
||||
expect(@result[0][0]).to eq :TERM_WITHOUT_QUOTES
|
||||
expect(@result[0][1]).to eq 'name'
|
||||
expect(@result[1][0]).to eq :COLON
|
||||
expect(@result[2][0]).to eq :TERM_WITH_QUOTES
|
||||
expect(@result[2][1]).to eq '"andrew"'
|
||||
end
|
||||
|
||||
it 'tests query with search term in brackets with AND inside word' do
|
||||
@result = @evaluator.tokenize('(land)')
|
||||
|
||||
expect(@result.length).to eq 3
|
||||
|
||||
expect(@result[0][0]).to eq :L_BRACKET
|
||||
expect(@result[1][0]).to eq :TERM_WITHOUT_QUOTES
|
||||
expect(@result[1][1]).to eq 'land'
|
||||
expect(@result[2][0]).to eq :R_BRACKET
|
||||
end
|
||||
|
||||
it 'tests query with search term in brackets starting with AND' do
|
||||
@result = @evaluator.tokenize('(andromeda)')
|
||||
|
||||
expect(@result.length).to eq 3
|
||||
|
||||
expect(@result[0][0]).to eq :L_BRACKET
|
||||
expect(@result[1][0]).to eq :TERM_WITHOUT_QUOTES
|
||||
expect(@result[1][1]).to eq 'andromeda'
|
||||
expect(@result[2][0]).to eq :R_BRACKET
|
||||
end
|
||||
|
||||
it 'tests query with search term in brackets with AND inside word with quotes' do
|
||||
@result = @evaluator.tokenize('("land")')
|
||||
|
||||
expect(@result.length).to eq 3
|
||||
|
||||
expect(@result[0][0]).to eq :L_BRACKET
|
||||
expect(@result[1][0]).to eq :TERM_WITH_QUOTES
|
||||
expect(@result[1][1]).to eq '"land"'
|
||||
expect(@result[2][0]).to eq :R_BRACKET
|
||||
end
|
||||
|
||||
it 'tests query with search term in brackets starting with AND with quotes' do
|
||||
@result = @evaluator.tokenize('("andromeda")')
|
||||
|
||||
expect(@result.length).to eq 3
|
||||
|
||||
expect(@result[0][0]).to eq :L_BRACKET
|
||||
expect(@result[1][0]).to eq :TERM_WITH_QUOTES
|
||||
expect(@result[1][1]).to eq '"andromeda"'
|
||||
expect(@result[2][0]).to eq :R_BRACKET
|
||||
end
|
||||
|
||||
it 'tests query with multiple search terms with mixed and-or-not after dash and underscore' do
|
||||
@result = @evaluator.tokenize('123-and-456 -or-2 -not_not_1')
|
||||
|
||||
expect(@result.length).to eq 3
|
||||
|
||||
expect(@result[0][0]).to eq :TERM_WITHOUT_QUOTES
|
||||
expect(@result[0][1]).to eq '123-and-456'
|
||||
expect(@result[1][0]).to eq :TERM_WITHOUT_QUOTES
|
||||
expect(@result[1][1]).to eq '-or-2'
|
||||
expect(@result[2][0]).to eq :TERM_WITHOUT_QUOTES
|
||||
expect(@result[2][1]).to eq '-not_not_1'
|
||||
end
|
||||
|
||||
it 'tests query with multiple search terms starting with AND' do
|
||||
@result = @evaluator.tokenize('land andrew and andromeda or orlando')
|
||||
|
||||
expect(@result.length).to eq 6
|
||||
|
||||
expect(@result[0][0]).to eq :TERM_WITHOUT_QUOTES
|
||||
expect(@result[0][1]).to eq 'land'
|
||||
expect(@result[1][0]).to eq :TERM_WITHOUT_QUOTES
|
||||
expect(@result[1][1]).to eq 'andrew'
|
||||
expect(@result[2][0]).to eq :OPERATOR_AND
|
||||
expect(@result[3][0]).to eq :TERM_WITHOUT_QUOTES
|
||||
expect(@result[3][1]).to eq 'andromeda'
|
||||
expect(@result[4][0]).to eq :OPERATOR_OR
|
||||
expect(@result[5][0]).to eq :TERM_WITHOUT_QUOTES
|
||||
expect(@result[5][1]).to eq 'orlando'
|
||||
end
|
||||
|
||||
it 'tests query with multiple search terms with dash and underscore chars' do
|
||||
@result = @evaluator.tokenize('land 123-andrew or -andrew- and not _ornela_ or ornela')
|
||||
|
||||
expect(@result.length).to eq 9
|
||||
|
||||
expect(@result[0][0]).to eq :TERM_WITHOUT_QUOTES
|
||||
expect(@result[0][1]).to eq 'land'
|
||||
expect(@result[1][0]).to eq :TERM_WITHOUT_QUOTES
|
||||
expect(@result[1][1]).to eq '123-andrew'
|
||||
expect(@result[2][0]).to eq :OPERATOR_OR
|
||||
expect(@result[3][0]).to eq :TERM_WITHOUT_QUOTES
|
||||
expect(@result[3][1]).to eq '-andrew-'
|
||||
expect(@result[4][0]).to eq :OPERATOR_AND
|
||||
expect(@result[5][0]).to eq :OPERATOR_NOT
|
||||
expect(@result[6][0]).to eq :TERM_WITHOUT_QUOTES
|
||||
expect(@result[6][1]).to eq '_ornela_'
|
||||
expect(@result[7][0]).to eq :OPERATOR_OR
|
||||
expect(@result[8][0]).to eq :TERM_WITHOUT_QUOTES
|
||||
expect(@result[8][1]).to eq 'ornela'
|
||||
|
||||
end
|
||||
|
||||
it 'tests query with multiple search terms with dash and underscore chars under quotes' do
|
||||
@result = @evaluator.tokenize('"land" "123-andrew" or "-andrew-"')
|
||||
|
||||
expect(@result.length).to eq 4
|
||||
|
||||
expect(@result[0][0]).to eq :TERM_WITH_QUOTES
|
||||
expect(@result[0][1]).to eq '"land"'
|
||||
expect(@result[1][0]).to eq :TERM_WITH_QUOTES
|
||||
expect(@result[1][1]).to eq '"123-andrew"'
|
||||
expect(@result[2][0]).to eq :OPERATOR_OR
|
||||
expect(@result[3][0]).to eq :TERM_WITH_QUOTES
|
||||
expect(@result[3][1]).to eq '"-andrew-"'
|
||||
end
|
||||
|
||||
it 'tests query with multiple search terms with mixed and-or-not on start' do
|
||||
@result = @evaluator.tokenize('sindy andora ornoty notary')
|
||||
|
||||
expect(@result.length).to eq 4
|
||||
|
||||
expect(@result[0][0]).to eq :TERM_WITHOUT_QUOTES
|
||||
expect(@result[0][1]).to eq 'sindy'
|
||||
expect(@result[1][0]).to eq :TERM_WITHOUT_QUOTES
|
||||
expect(@result[1][1]).to eq 'andora'
|
||||
expect(@result[2][0]).to eq :TERM_WITHOUT_QUOTES
|
||||
expect(@result[2][1]).to eq 'ornoty'
|
||||
expect(@result[3][0]).to eq :TERM_WITHOUT_QUOTES
|
||||
expect(@result[3][1]).to eq 'notary'
|
||||
end
|
||||
|
||||
it 'tests query with multiple search terms with mixed and-or-not on start and with logical operators between' do
|
||||
@result = @evaluator.tokenize('sindy and andora-notary or not ornoty notary')
|
||||
|
||||
expect(@result.length).to eq 7
|
||||
|
||||
expect(@result[0][0]).to eq :TERM_WITHOUT_QUOTES
|
||||
expect(@result[0][1]).to eq 'sindy'
|
||||
expect(@result[1][0]).to eq :OPERATOR_AND
|
||||
expect(@result[2][0]).to eq :TERM_WITHOUT_QUOTES
|
||||
expect(@result[2][1]).to eq 'andora-notary'
|
||||
expect(@result[3][0]).to eq :OPERATOR_OR
|
||||
expect(@result[4][0]).to eq :OPERATOR_NOT
|
||||
expect(@result[5][0]).to eq :TERM_WITHOUT_QUOTES
|
||||
expect(@result[5][1]).to eq 'ornoty'
|
||||
expect(@result[6][0]).to eq :TERM_WITHOUT_QUOTES
|
||||
expect(@result[6][1]).to eq 'notary'
|
||||
end
|
||||
|
||||
it 'tests query with multiple search terms with mixed and-or-not on start and with logical operators between' do
|
||||
@result = @evaluator.tokenize('(sindy and andora-notary)or not(ornoty notary)')
|
||||
|
||||
expect(@result.length).to eq 11
|
||||
|
||||
expect(@result[0][0]).to eq :L_BRACKET
|
||||
expect(@result[1][0]).to eq :TERM_WITHOUT_QUOTES
|
||||
expect(@result[1][1]).to eq 'sindy'
|
||||
expect(@result[2][0]).to eq :OPERATOR_AND
|
||||
expect(@result[3][0]).to eq :TERM_WITHOUT_QUOTES
|
||||
expect(@result[3][1]).to eq 'andora-notary'
|
||||
expect(@result[4][0]).to eq :R_BRACKET
|
||||
expect(@result[5][0]).to eq :OPERATOR_OR
|
||||
expect(@result[6][0]).to eq :OPERATOR_NOT
|
||||
expect(@result[7][0]).to eq :L_BRACKET
|
||||
expect(@result[8][0]).to eq :TERM_WITHOUT_QUOTES
|
||||
expect(@result[8][1]).to eq 'ornoty'
|
||||
expect(@result[9][0]).to eq :TERM_WITHOUT_QUOTES
|
||||
expect(@result[9][1]).to eq 'notary'
|
||||
expect(@result[10][0]).to eq :R_BRACKET
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -133,7 +133,7 @@ class QueryParserTester
|
||||
expect(@result[:OPERATOR_AND]).to eq @expected_array_total
|
||||
end
|
||||
|
||||
it 'tests operator precedence' do
|
||||
it 'tests operator precedence, or - and' do
|
||||
@result1 = @evaluator.parse('tag:mta or name:JF and 12_4')
|
||||
@result2 = @evaluator.parse('tag:mta or (name:JF and 12_4)')
|
||||
|
||||
@@ -155,10 +155,469 @@ class QueryParserTester
|
||||
|
||||
end
|
||||
|
||||
# Tests to write :
|
||||
# * query with multiple column names and search terms without logical operators
|
||||
# * AND NOT, OR NOT tests
|
||||
it 'tests operator precedence, and - or' do
|
||||
@result1 = @evaluator.parse('tag:mta and name:JF or 12_4')
|
||||
@result2 = @evaluator.parse('(tag:mta and name:JF) or 12_4')
|
||||
|
||||
expect(@result1).to eq @result2
|
||||
|
||||
expect(@result1.length).to eq 1
|
||||
|
||||
@expected_array_part_2 = [
|
||||
{'tag' => 'mta'},
|
||||
{'name' => 'JF'}
|
||||
]
|
||||
|
||||
@expected_array_total = [
|
||||
{:OPERATOR_AND => @expected_array_part_2},
|
||||
{:DEFAULT_COLUMN => '12_4'}
|
||||
]
|
||||
|
||||
expect(@result1[:OPERATOR_OR]).to eq @expected_array_total
|
||||
|
||||
end
|
||||
|
||||
it 'tests simple query with not operator' do
|
||||
@result = @evaluator.parse('not -54')
|
||||
|
||||
expect(@result.length).to be 1
|
||||
expect(@result[:OPERATOR_NOT][:DEFAULT_COLUMN]).to eq '-54'
|
||||
end
|
||||
|
||||
it 'tests query with mixed NOT and AND logic operator' do
|
||||
@result = @evaluator.parse('name:"some wild name" and not -123-456')
|
||||
|
||||
@expected_and_array = [
|
||||
{'name' => '"some wild name"'},
|
||||
{:OPERATOR_NOT => {:DEFAULT_COLUMN => '-123-456'}}
|
||||
]
|
||||
|
||||
expect(@result.length).to eq 1
|
||||
expect(@result[:OPERATOR_AND]).to eq @expected_and_array
|
||||
end
|
||||
|
||||
it 'tests query with mixed NOT, AND and OR logic operators' do
|
||||
@result = @evaluator.parse('name:"some wild name" or not (tag:mta and -123-456)')
|
||||
|
||||
@expected_and_array_operands = [
|
||||
{'tag' => 'mta'},
|
||||
{:DEFAULT_COLUMN => '-123-456'}
|
||||
]
|
||||
|
||||
@expected_or_array_operands = [
|
||||
{'name' => '"some wild name"'},
|
||||
{:OPERATOR_NOT => {:OPERATOR_AND => @expected_and_array_operands}}
|
||||
]
|
||||
|
||||
expect(@result.length).to eq 1
|
||||
expect(@result[:OPERATOR_OR]).to eq @expected_or_array_operands
|
||||
end
|
||||
|
||||
it 'tests query with two default column search terms without quotes and without logical operators' do
|
||||
@result = @evaluator.parse('id-5 -456')
|
||||
|
||||
@expected_array = [
|
||||
{:DEFAULT_COLUMN => 'id-5'},
|
||||
{:DEFAULT_COLUMN => '-456'}
|
||||
]
|
||||
|
||||
expect(@result.length).to eq 1
|
||||
expect(@result[:OPERATOR_OR]).to eq @expected_array
|
||||
end
|
||||
|
||||
it 'tests query with two default column search terms with quotes and without logical operators' do
|
||||
@result = @evaluator.parse('"id-5 no Q" -456')
|
||||
|
||||
@expected_array = [
|
||||
{:DEFAULT_COLUMN => '"id-5 no Q"'},
|
||||
{:DEFAULT_COLUMN => '-456'}
|
||||
]
|
||||
|
||||
expect(@result.length).to eq 1
|
||||
expect(@result[:OPERATOR_OR]).to eq @expected_array
|
||||
end
|
||||
|
||||
it 'tests query with two default column search terms with quotes on both terms and without logical operators' do
|
||||
@result = @evaluator.parse('"id-5 no Q" "wild id -456"')
|
||||
|
||||
@expected_array = [
|
||||
{:DEFAULT_COLUMN => '"id-5 no Q"'},
|
||||
{:DEFAULT_COLUMN => '"wild id -456"'}
|
||||
]
|
||||
|
||||
expect(@result.length).to eq 1
|
||||
expect(@result[:OPERATOR_OR]).to eq @expected_array
|
||||
end
|
||||
|
||||
it 'tests query with one default column and one non defualt column, search terms without quotes and without logical operators' do
|
||||
@result = @evaluator.parse('tag:mta -456')
|
||||
|
||||
@expected_array = [
|
||||
{'tag' => 'mta'},
|
||||
{:DEFAULT_COLUMN => '-456'}
|
||||
]
|
||||
|
||||
expect(@result.length).to eq 1
|
||||
expect(@result[:OPERATOR_OR]).to eq @expected_array
|
||||
end
|
||||
|
||||
it 'tests query with one default column and one non defualt column, search terms with quotes and without logical operators' do
|
||||
@result = @evaluator.parse('-1-23 name:"WILD name"')
|
||||
|
||||
@expected_array = [
|
||||
{:DEFAULT_COLUMN => '-1-23'},
|
||||
{'name' => '"WILD name"'}
|
||||
]
|
||||
|
||||
expect(@result.length).to eq 1
|
||||
expect(@result[:OPERATOR_OR]).to eq @expected_array
|
||||
end
|
||||
|
||||
it 'tests query with two columns, search terms with quotes and without logical operators' do
|
||||
@result = @evaluator.parse('tag:-1-23 name:"WILD name"')
|
||||
|
||||
@expected_array = [
|
||||
{'tag' => '-1-23'},
|
||||
{'name' => '"WILD name"'}
|
||||
]
|
||||
|
||||
expect(@result.length).to eq 1
|
||||
expect(@result[:OPERATOR_OR]).to eq @expected_array
|
||||
end
|
||||
|
||||
it 'tests query with two columns, search terms with quotes on both and without logical operators' do
|
||||
@result = @evaluator.parse('tag:"1 2 3" name:"WILD name"')
|
||||
|
||||
@expected_array = [
|
||||
{'tag' => '"1 2 3"'},
|
||||
{'name' => '"WILD name"'}
|
||||
]
|
||||
|
||||
expect(@result.length).to eq 1
|
||||
expect(@result[:OPERATOR_OR]).to eq @expected_array
|
||||
end
|
||||
|
||||
it 'tests query with three columns, search terms with quotes on both and without logical operators' do
|
||||
@result = @evaluator.parse('tag:"1 2 3" name:"WILD name" name:"ANOTHER wild name"')
|
||||
|
||||
@expected_array = [
|
||||
{'tag' => '"1 2 3"'},
|
||||
{:OPERATOR_OR => [
|
||||
{'name' => '"WILD name"'},
|
||||
{'name' => '"ANOTHER wild name"'}
|
||||
]}
|
||||
]
|
||||
|
||||
expect(@result.length).to eq 1
|
||||
expect(@result[:OPERATOR_OR]).to eq @expected_array
|
||||
end
|
||||
|
||||
it 'tests complex query' do
|
||||
@result = @evaluator.parse('(device-id:"with space" tag:mta no-quotes-id-123)'\
|
||||
'or "id with quotes-5" and ( ("id with q 10" or "id with q 20")'\
|
||||
'and ("id with Q 30" "id with Q 40") and not id-without-Q-50)')
|
||||
|
||||
# (device-id:"with space" tag:mta no-quotes-id-123) or "id with quotes-5" and ( ("id with q 10" or "id with q 20") and ("id with Q 30" "id with Q 40") and not id-without-Q-50)
|
||||
# _____________________A___________________________ or _______B___________ and __________________________________________________C______________________________________________
|
||||
# (____A1________________ ___A2__ ______A3________) or _______B___________ and ( ____________C1____________________ and ______________C2_______________ and ______C3___________)
|
||||
|
||||
|
||||
@A = {:OPERATOR_OR => [
|
||||
{'device-id' => '"with space"'},
|
||||
{:OPERATOR_OR => [
|
||||
{'tag' => 'mta'},
|
||||
{:DEFAULT_COLUMN => 'no-quotes-id-123'}]
|
||||
}
|
||||
]}
|
||||
|
||||
@B = {:DEFAULT_COLUMN => '"id with quotes-5"'}
|
||||
|
||||
|
||||
@C1 = {:OPERATOR_OR => [
|
||||
{:DEFAULT_COLUMN => '"id with q 10"'},
|
||||
{:DEFAULT_COLUMN => '"id with q 20"'}
|
||||
]}
|
||||
|
||||
|
||||
@C2 = {:OPERATOR_OR => [
|
||||
{:DEFAULT_COLUMN => '"id with Q 30"'},
|
||||
{:DEFAULT_COLUMN => '"id with Q 40"'}
|
||||
]}
|
||||
|
||||
@C3 = {:OPERATOR_NOT => {:DEFAULT_COLUMN => 'id-without-Q-50'}}
|
||||
|
||||
@C = {:OPERATOR_AND => [
|
||||
{:OPERATOR_AND => [
|
||||
@C1,
|
||||
@C2
|
||||
]},
|
||||
@C3
|
||||
]}
|
||||
|
||||
@expected_final_array_result = [
|
||||
@A,
|
||||
{:OPERATOR_AND => [
|
||||
@B,
|
||||
@C
|
||||
]}
|
||||
]
|
||||
|
||||
expect(@result.length).to eq 1
|
||||
expect(@result[:OPERATOR_OR]).to eq @expected_final_array_result
|
||||
end
|
||||
|
||||
it 'tests query without column name containing AND word inside without quotes' do
|
||||
@result = @evaluator.parse('land')
|
||||
|
||||
expect(@result.length).to eq 1
|
||||
expect(@result[:DEFAULT_COLUMN]).to eq 'land'
|
||||
end
|
||||
|
||||
it 'tests query without column name containing AND word inside with quotes' do
|
||||
@result = @evaluator.parse('"land"')
|
||||
|
||||
expect(@result.length).to eq 1
|
||||
expect(@result[:DEFAULT_COLUMN]).to eq '"land"'
|
||||
end
|
||||
|
||||
it 'tests query without column name and with word starting with AND without quotes' do
|
||||
@result = @evaluator.parse('andromeda')
|
||||
|
||||
expect(@result.length).to eq 1
|
||||
expect(@result[:DEFAULT_COLUMN]).to eq 'andromeda'
|
||||
end
|
||||
|
||||
it 'tests query without column name and with word starting with AND with quotes' do
|
||||
@result = @evaluator.parse('"andromeda"')
|
||||
|
||||
expect(@result.length).to eq 1
|
||||
expect(@result[:DEFAULT_COLUMN]).to eq '"andromeda"'
|
||||
end
|
||||
|
||||
it 'tests query with column name containing AND word inside' do
|
||||
@result = @evaluator.parse('land:some-search-term')
|
||||
|
||||
expect(@result.length).to eq 1
|
||||
expect(@result['land']).to eq 'some-search-term'
|
||||
end
|
||||
|
||||
it 'tests query with column name starting with AND' do
|
||||
@result = @evaluator.parse('andromeda:some-search-term')
|
||||
|
||||
expect(@result.length).to eq 1
|
||||
expect(@result['andromeda']).to eq 'some-search-term'
|
||||
end
|
||||
|
||||
it 'tests query with search term without quotes containing AND word inside' do
|
||||
@result = @evaluator.parse('name:land')
|
||||
|
||||
expect(@result.length).to eq 1
|
||||
expect(@result['name']).to eq 'land'
|
||||
end
|
||||
|
||||
it 'tests query with search term with quotes containing AND word inside' do
|
||||
@result = @evaluator.parse('name:"land"')
|
||||
|
||||
expect(@result.length).to eq 1
|
||||
expect(@result['name']).to eq '"land"'
|
||||
end
|
||||
|
||||
it 'tests query with search term without quotes and search term starting with AND without quotes' do
|
||||
@result = @evaluator.parse('name:andromeda')
|
||||
|
||||
expect(@result.length).to eq 1
|
||||
expect(@result['name']).to eq 'andromeda'
|
||||
end
|
||||
|
||||
it 'tests query with search term without quotes and search term starting with AND with quotes' do
|
||||
@result = @evaluator.parse('name:"andrew"')
|
||||
|
||||
expect(@result.length).to eq 1
|
||||
expect(@result['name']).to eq '"andrew"'
|
||||
end
|
||||
|
||||
it 'tests query with search term in brackets with AND inside word' do
|
||||
@result = @evaluator.parse('(land)')
|
||||
|
||||
expect(@result.length).to eq 1
|
||||
expect(@result[:DEFAULT_COLUMN]).to eq 'land'
|
||||
end
|
||||
|
||||
it 'tests query with search term in brackets starting with AND' do
|
||||
@result = @evaluator.parse('(andromeda)')
|
||||
|
||||
expect(@result.length).to eq 1
|
||||
expect(@result[:DEFAULT_COLUMN]).to eq 'andromeda'
|
||||
end
|
||||
|
||||
it 'tests query with multiple search terms with mixed and-or-not after dash and underscore' do
|
||||
@result = @evaluator.parse('123-and-456 -or-2 -not_not_1')
|
||||
|
||||
@or_array_1 = [
|
||||
{:DEFAULT_COLUMN => '-or-2'},
|
||||
{:DEFAULT_COLUMN => '-not_not_1'}
|
||||
]
|
||||
|
||||
@last_or_array = [
|
||||
{:DEFAULT_COLUMN => '123-and-456'},
|
||||
{:OPERATOR_OR => @or_array_1}
|
||||
]
|
||||
|
||||
expect(@result.length).to eq 1
|
||||
expect(@result[:OPERATOR_OR]).to eq @last_or_array
|
||||
end
|
||||
|
||||
it 'tests query with search term in brackets with AND inside word with quotes' do
|
||||
@result = @evaluator.parse('("land")')
|
||||
|
||||
expect(@result.length).to eq 1
|
||||
expect(@result[:DEFAULT_COLUMN]).to eq '"land"'
|
||||
end
|
||||
|
||||
it 'tests query with search term in brackets starting with AND with quotes' do
|
||||
@result = @evaluator.parse('("andromeda")')
|
||||
|
||||
expect(@result.length).to eq 1
|
||||
expect(@result[:DEFAULT_COLUMN]).to eq '"andromeda"'
|
||||
end
|
||||
|
||||
it 'tests query with multiple search terms starting with AND' do
|
||||
@result = @evaluator.parse('land andrew and andromeda or orlando')
|
||||
|
||||
@and_array = [
|
||||
{:DEFAULT_COLUMN=>'andrew'},
|
||||
{:DEFAULT_COLUMN=>'andromeda'}
|
||||
]
|
||||
|
||||
@last_or_array = [
|
||||
{:OPERATOR_AND => @and_array},
|
||||
{:DEFAULT_COLUMN => 'orlando'}
|
||||
]
|
||||
|
||||
@main_or_array = [
|
||||
{:DEFAULT_COLUMN => 'land'},
|
||||
{:OPERATOR_OR => @last_or_array}
|
||||
]
|
||||
|
||||
expect(@result.length).to eq 1
|
||||
expect(@result[:OPERATOR_OR]).to eq @main_or_array
|
||||
end
|
||||
|
||||
it 'tests query with multiple search terms with dash and underscore chars' do
|
||||
@result = @evaluator.parse('land 123-andrew or -andrew- and not _ornela_ or ornela')
|
||||
|
||||
@and_array = [
|
||||
{:DEFAULT_COLUMN=>'-andrew-'},
|
||||
{:OPERATOR_NOT=>{:DEFAULT_COLUMN => '_ornela_'}}
|
||||
]
|
||||
|
||||
@intra_or_array = [
|
||||
{:DEFAULT_COLUMN => '123-andrew'},
|
||||
{:OPERATOR_AND => @and_array}
|
||||
]
|
||||
|
||||
@last_or_array = [
|
||||
{:OPERATOR_OR => @intra_or_array},
|
||||
{:DEFAULT_COLUMN => 'ornela'}
|
||||
]
|
||||
|
||||
@main_or_array = [
|
||||
{:DEFAULT_COLUMN => 'land'},
|
||||
{:OPERATOR_OR => @last_or_array}
|
||||
]
|
||||
|
||||
expect(@result.length).to eq 1
|
||||
expect(@result[:OPERATOR_OR]).to eq @main_or_array
|
||||
|
||||
end
|
||||
|
||||
it 'tests query with multiple search terms with dash and underscore chars under quotes' do
|
||||
@result = @evaluator.parse('"land" "123-andrew" or "-andrew-"')
|
||||
|
||||
|
||||
@last_or_array = [
|
||||
{:DEFAULT_COLUMN => '"123-andrew"'},
|
||||
{:DEFAULT_COLUMN => '"-andrew-"'}
|
||||
]
|
||||
|
||||
@main_or_array = [
|
||||
{:DEFAULT_COLUMN => '"land"'},
|
||||
{:OPERATOR_OR => @last_or_array}
|
||||
]
|
||||
|
||||
expect(@result.length).to eq 1
|
||||
expect(@result[:OPERATOR_OR]).to eq @main_or_array
|
||||
end
|
||||
|
||||
it 'tests query with multiple search terms with mixed and-or-not on start' do
|
||||
@result = @evaluator.parse('sindy andora ornoty notary')
|
||||
|
||||
@or_array_1 = [
|
||||
{:DEFAULT_COLUMN=>'ornoty'},
|
||||
{:DEFAULT_COLUMN=>'notary'}
|
||||
]
|
||||
|
||||
@or_array_2 = [
|
||||
{:DEFAULT_COLUMN => 'andora'},
|
||||
{:OPERATOR_OR => @or_array_1}
|
||||
]
|
||||
|
||||
@main_or_array = [
|
||||
{:DEFAULT_COLUMN => 'sindy'},
|
||||
{:OPERATOR_OR => @or_array_2}
|
||||
]
|
||||
|
||||
expect(@result.length).to eq 1
|
||||
expect(@result[:OPERATOR_OR]).to eq @main_or_array
|
||||
end
|
||||
|
||||
it 'tests query with multiple search terms with mixed and-or-not on start and with logical operators between' do
|
||||
@result = @evaluator.parse('sindy and andora-notary or not ornoty notary')
|
||||
|
||||
@and_array = [
|
||||
{:DEFAULT_COLUMN=>'sindy'},
|
||||
{:DEFAULT_COLUMN=>'andora-notary'}
|
||||
]
|
||||
|
||||
@not_or_array = [
|
||||
{:DEFAULT_COLUMN => 'ornoty'},
|
||||
{:DEFAULT_COLUMN => 'notary'}
|
||||
]
|
||||
|
||||
@main_or_array = [
|
||||
{:OPERATOR_AND => @and_array},
|
||||
{:OPERATOR_NOT => {
|
||||
:OPERATOR_OR => @not_or_array
|
||||
}}
|
||||
]
|
||||
|
||||
expect(@result.length).to eq 1
|
||||
expect(@result[:OPERATOR_OR]).to eq @main_or_array
|
||||
end
|
||||
|
||||
it 'tests query with multiple search terms with mixed and-or-not on start and with logical operators between' do
|
||||
@result = @evaluator.parse('(sindy or andora-notary)and not(ornoty notary)')
|
||||
|
||||
@or_array_1 = [
|
||||
{:DEFAULT_COLUMN=>'sindy'},
|
||||
{:DEFAULT_COLUMN=>'andora-notary'}
|
||||
]
|
||||
|
||||
@not_or_array = [
|
||||
{:DEFAULT_COLUMN => 'ornoty'},
|
||||
{:DEFAULT_COLUMN => 'notary'}
|
||||
]
|
||||
|
||||
@main_and_array = [
|
||||
{:OPERATOR_OR => @or_array_1},
|
||||
{:OPERATOR_NOT => {
|
||||
:OPERATOR_OR => @not_or_array
|
||||
}}
|
||||
]
|
||||
|
||||
expect(@result.length).to eq 1
|
||||
expect(@result[:OPERATOR_AND]).to eq @main_and_array
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user