add query generator tests for keyword detection
This commit is contained in:
@@ -21,7 +21,7 @@ class SqlGeneratorTester
|
||||
end
|
||||
|
||||
it 'tests simple search term without column name and with quotes' do
|
||||
@query = TextToSqlQuery.new('ab', [:'players.title', :'players.tag', :'players.device_id'], :'players.device_id')
|
||||
@query = TextToSqlQuery.new('"ab"', [:'players.title', :'players.tag', :'players.device_id'], :'players.device_id')
|
||||
|
||||
expect(@query.where_clause).to eq ['players.device_id ILIKE ?', '%ab%']
|
||||
end
|
||||
@@ -128,5 +128,132 @@ class SqlGeneratorTester
|
||||
|
||||
expect(@query.where_clause).to eq [result_expression, result_params].flatten
|
||||
end
|
||||
|
||||
it 'tests query without column name containing AND word inside without quotes' do
|
||||
@query = TextToSqlQuery.new('land', [:'players.title', :'players.tag', :'players.device_id'], :'players.device_id')
|
||||
|
||||
expect(@query.where_clause).to eq ['players.device_id ILIKE ?', '%land%']
|
||||
end
|
||||
|
||||
it 'tests query without column name containing AND word inside with quotes' do
|
||||
@query = TextToSqlQuery.new('"land"', [:'players.title', :'players.tag', :'players.device_id'], :'players.device_id')
|
||||
|
||||
expect(@query.where_clause).to eq ['players.device_id ILIKE ?', '%land%']
|
||||
end
|
||||
|
||||
it 'tests query without column name and with word starting with AND without quotes' do
|
||||
@query = TextToSqlQuery.new('andromeda', [:'players.title', :'players.tag', :'players.device_id'], :'players.device_id')
|
||||
|
||||
expect(@query.where_clause).to eq ['players.device_id ILIKE ?', '%andromeda%']
|
||||
end
|
||||
|
||||
it 'tests query without column name and with word starting with AND with quotes' do
|
||||
@query = TextToSqlQuery.new('"andromeda"', [:'players.title', :'players.tag', :'players.device_id'], :'players.device_id')
|
||||
|
||||
expect(@query.where_clause).to eq ['players.device_id ILIKE ?', '%andromeda%']
|
||||
end
|
||||
|
||||
it 'tests query with column name containing AND word inside' do
|
||||
@query = TextToSqlQuery.new('land:some-search-term', [:'players.title', :'players.tag', :'players.device_id', :'players.land'], :'players.device_id')
|
||||
|
||||
expect(@query.where_clause).to eq ['players.land ILIKE ?', '%some-search-term%']
|
||||
end
|
||||
|
||||
it 'tests query with column name starting with AND' do
|
||||
@query = TextToSqlQuery.new('andromeda:some-search-term', [:'players.title', :'players.tag', :'players.device_id', :'players.andromeda'], :'players.device_id')
|
||||
|
||||
expect(@query.where_clause).to eq ['players.andromeda ILIKE ?', '%some-search-term%']
|
||||
end
|
||||
|
||||
it 'tests query with search term without quotes containing AND word inside' do
|
||||
@query = TextToSqlQuery.new('title:land', [:'players.title', :'players.tag', :'players.device_id'], :'players.device_id')
|
||||
|
||||
expect(@query.where_clause).to eq ['players.title ILIKE ?', '%land%']
|
||||
end
|
||||
|
||||
it 'tests query with search term with quotes containing AND word inside' do
|
||||
@query = TextToSqlQuery.new('title:"land"', [:'players.title', :'players.tag', :'players.device_id'], :'players.device_id')
|
||||
|
||||
expect(@query.where_clause).to eq ['players.title ILIKE ?', '%land%']
|
||||
end
|
||||
|
||||
it 'tests query with search term without quotes and search term starting with AND without quotes' do
|
||||
@query = TextToSqlQuery.new('title:andromeda', [:'players.title', :'players.tag', :'players.device_id'], :'players.device_id')
|
||||
|
||||
expect(@query.where_clause).to eq ['players.title ILIKE ?', '%andromeda%']
|
||||
end
|
||||
|
||||
it 'tests query with search term without quotes and search term starting with AND with quotes' do
|
||||
@query = TextToSqlQuery.new('title:"andrew"', [:'players.title', :'players.tag', :'players.device_id'], :'players.device_id')
|
||||
|
||||
expect(@query.where_clause).to eq ['players.title ILIKE ?', '%andrew%']
|
||||
end
|
||||
|
||||
it 'tests query with search term in brackets with AND inside word' do
|
||||
@query = TextToSqlQuery.new('(land)', [:'players.title', :'players.tag', :'players.device_id'], :'players.device_id')
|
||||
|
||||
expect(@query.where_clause).to eq ['players.device_id ILIKE ?', '%land%']
|
||||
end
|
||||
|
||||
it 'tests query with search term in brackets starting with AND' do
|
||||
@query = TextToSqlQuery.new('(andromeda)', [:'players.title', :'players.tag', :'players.device_id'], :'players.device_id')
|
||||
|
||||
expect(@query.where_clause).to eq ['players.device_id ILIKE ?', '%andromeda%']
|
||||
end
|
||||
|
||||
it 'tests query with multiple search terms with mixed and-or-not after dash and underscore' do
|
||||
@query = TextToSqlQuery.new('123-and-456 -or-2 -not_not_1', [:'players.title', :'players.tag', :'players.device_id'], :'players.device_id')
|
||||
|
||||
expect(@query.where_clause).to eq ['(players.device_id ILIKE ? OR (players.device_id ILIKE ? OR players.device_id ILIKE ?))', '%123-and-456%', '%-or-2%', '%-not\_not\_1%']
|
||||
end
|
||||
|
||||
it 'tests query with search term in brackets with AND inside word with quotes' do
|
||||
@query = TextToSqlQuery.new('("land")', [:'players.title', :'players.tag', :'players.device_id'], :'players.device_id')
|
||||
|
||||
expect(@query.where_clause).to eq ['players.device_id ILIKE ?', '%land%']
|
||||
end
|
||||
|
||||
it 'tests query with search term in brackets starting with AND with quotes' do
|
||||
@query = TextToSqlQuery.new('("andromeda")', [:'players.title', :'players.tag', :'players.device_id'], :'players.device_id')
|
||||
|
||||
expect(@query.where_clause).to eq ['players.device_id ILIKE ?', '%andromeda%']
|
||||
end
|
||||
|
||||
it 'tests query with multiple search terms starting with AND' do
|
||||
@query = TextToSqlQuery.new('land andrew and andromeda or orlando', [:'players.title', :'players.tag', :'players.device_id'], :'players.device_id')
|
||||
|
||||
expect(@query.where_clause).to eq ['(players.device_id ILIKE ? OR ((players.device_id ILIKE ? AND players.device_id ILIKE ?) OR players.device_id ILIKE ?))', '%land%', '%andrew%', '%andromeda%', '%orlando%']
|
||||
end
|
||||
|
||||
it 'tests query with multiple search terms with dash and underscore chars' do
|
||||
@query = TextToSqlQuery.new('land 123-andrew or -andrew- and not _ornela_ or ornela', [:'players.title', :'players.tag', :'players.device_id'], :'players.device_id')
|
||||
|
||||
expect(@query.where_clause).to eq ['(players.device_id ILIKE ? OR ((players.device_id ILIKE ? OR (players.device_id ILIKE ? AND NOT players.device_id ILIKE ?)) OR players.device_id ILIKE ?))', '%land%', '%123-andrew%', '%-andrew-%', '%\_ornela\_%', '%ornela%']
|
||||
end
|
||||
|
||||
it 'tests query with multiple search terms with dash and underscore chars under quotes' do
|
||||
@query = TextToSqlQuery.new('"land" "123-andrew" or "-andrew-"', [:'players.title', :'players.tag', :'players.device_id'], :'players.device_id')
|
||||
|
||||
expect(@query.where_clause).to eq ['(players.device_id ILIKE ? OR (players.device_id ILIKE ? OR players.device_id ILIKE ?))', '%land%', '%123-andrew%', '%-andrew-%']
|
||||
end
|
||||
|
||||
it 'tests query with multiple search terms with mixed and-or-not on start' do
|
||||
@query = TextToSqlQuery.new('sindy andora ornoty notary', [:'players.title', :'players.tag', :'players.device_id'], :'players.device_id')
|
||||
|
||||
expect(@query.where_clause).to eq ['(players.device_id ILIKE ? OR (players.device_id ILIKE ? OR (players.device_id ILIKE ? OR players.device_id ILIKE ?)))', '%sindy%', '%andora%', '%ornoty%', '%notary%']
|
||||
end
|
||||
|
||||
it 'tests query with multiple search terms with mixed and-or-not on start and with logical operators between' do
|
||||
@query = TextToSqlQuery.new('sindy and andora-notary or not ornoty notary', [:'players.title', :'players.tag', :'players.device_id'], :'players.device_id')
|
||||
|
||||
expect(@query.where_clause).to eq ['((players.device_id ILIKE ? AND players.device_id ILIKE ?) OR NOT (players.device_id ILIKE ? OR players.device_id ILIKE ?))', '%sindy%', '%andora-notary%', '%ornoty%', '%notary%']
|
||||
end
|
||||
|
||||
it 'tests query with multiple search terms with mixed and-or-not on start and with logical operators between' do
|
||||
@query = TextToSqlQuery.new('(sindy or andora-notary)and not(ornoty notary)', [:'players.title', :'players.tag', :'players.device_id'], :'players.device_id')
|
||||
|
||||
expect(@query.where_clause).to eq ['((players.device_id ILIKE ? OR players.device_id ILIKE ?) AND NOT (players.device_id ILIKE ? OR players.device_id ILIKE ?))', '%sindy%', '%andora-notary%', '%ornoty%', '%notary%']
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user