@@ -4,59 +4,66 @@ class OpensearchTest < ActiveSupport::TestCase
44 test 'matches citation' do
55 os = Opensearch . new
66 os . instance_variable_set ( :@params , { citation : 'foo' } )
7- assert os . matches . select { |m | m [ :citation ] == 'foo' }
7+
8+ assert ( os . matches . to_json . include? ( '{"match":{"citation":"foo"}}' ) )
89 end
910
1011 test 'matches title' do
1112 os = Opensearch . new
1213 os . instance_variable_set ( :@params , { title : 'foo' } )
13- assert os . matches . select { |m | m [ :title ] == 'foo' }
14+
15+ assert ( os . matches . to_json . include? ( '{"match":{"title":"foo"}}' ) )
1416 end
1517
1618 test 'matches contributors' do
1719 os = Opensearch . new
1820 os . instance_variable_set ( :@params , { contributors : 'foo' } )
19- assert os . matches . select { |m | m [ 'contributors.value' ] == 'foo' }
21+
22+ assert ( os . matches . to_json . include? ( '{"match":{"contributors.value":"foo"}}' ) )
2023 end
2124
2225 test 'matches funding_information' do
2326 os = Opensearch . new
2427 os . instance_variable_set ( :@params , { funding_information : 'foo' } )
25- assert os . matches . select { |m | m [ 'funding_information.funder_name' ] == 'foo' }
28+
29+ assert ( os . matches . to_json . include? ( '{"match":{"funding_information.funder_name":"foo"}}' ) )
2630 end
2731
2832 test 'matches identifiers' do
2933 os = Opensearch . new
3034 os . instance_variable_set ( :@params , { identifiers : 'foo' } )
31- assert os . matches . select { |m | m [ 'identifiers.value' ] == 'foo' }
35+
36+ assert ( os . matches . to_json . include? ( '{"match":{"identifiers.value":"foo"}}' ) )
3237 end
3338
3439 test 'matches locations' do
3540 os = Opensearch . new
3641 os . instance_variable_set ( :@params , { locations : 'foo' } )
37- assert os . matches . select { |m | m [ 'locations.value' ] == 'foo' }
42+
43+ assert ( os . matches . to_json . include? ( '{"match":{"locations.value":"foo"}}' ) )
3844 end
3945
4046 test 'matches subjects' do
4147 os = Opensearch . new
4248 os . instance_variable_set ( :@params , { subjects : 'foo' } )
43- assert os . matches . select { |m | m [ 'subjects.value' ] == 'foo' }
49+
50+ assert ( os . matches . to_json . include? ( '{"match":{"subjects.value":"foo"}}' ) )
4451 end
4552
4653 test 'matches everything' do
4754 os = Opensearch . new
4855 os . instance_variable_set ( :@params , { q : 'this' , citation : 'here' , title : 'is' , contributors : 'a' ,
4956 funding_information : 'real' , identifiers : 'search' , locations : 'rest' ,
5057 subjects : 'assured,' } )
51- matches = os . matches
52- assert matches . select { | m | m [ :q ] == ' this' }
53- assert matches . select { | m | m [ : citation] == ' here' }
54- assert matches . select { | m | m [ : title] == 'is' }
55- assert matches . select { | m | m [ ' contributors.value' ] == 'a' }
56- assert matches . select { | m | m [ ' funding_information.funder_name' ] == ' real' }
57- assert matches . select { | m | m [ ' identifiers.value' ] == ' search' }
58- assert matches . select { | m | m [ ' locations.value' ] == ' rest' }
59- assert matches . select { | m | m [ ' subjects.value' ] == ' assured' }
58+
59+ assert ( os . matches . to_json . include? ( '{"multi_match":{"query":" this","fields":' ) )
60+ assert ( os . matches . to_json . include? ( '{"match":{" citation":" here"}}' ) )
61+ assert ( os . matches . to_json . include? ( '{"match":{" title":"is"}}' ) )
62+ assert ( os . matches . to_json . include? ( '{"match":{" contributors.value":"a"}}' ) )
63+ assert ( os . matches . to_json . include? ( '{"match":{" funding_information.funder_name":" real"}}' ) )
64+ assert ( os . matches . to_json . include? ( '{"match":{" identifiers.value":" search"}}' ) )
65+ assert ( os . matches . to_json . include? ( '{"match":{" locations.value":" rest"}}' ) )
66+ assert ( os . matches . to_json . include? ( '{"match":{" subjects.value":" assured,"}}' ) )
6067 end
6168
6269 test 'can override index' do
@@ -266,4 +273,27 @@ class OpensearchTest < ActiveSupport::TestCase
266273
267274 refute ( os . build_query ( 0 ) . include? ( 'highlight' ) )
268275 end
276+
277+ test 'can search by geopoint' do
278+ os = Opensearch . new
279+ os . instance_variable_set ( :@params ,
280+ { geodistance : { latitude : '42.361145' , longitude : '-71.057083' , distance : '50mi' } } )
281+
282+ assert (
283+ os . query . to_json . include? ( '{"distance":"50mi","locations.geoshape":{"lat":"42.361145","lon":"-71.057083"}}' )
284+ )
285+ end
286+
287+ test 'can search for combination of geopoint and keyword' do
288+ os = Opensearch . new
289+ os . instance_variable_set ( :@params ,
290+ { geodistance : { latitude : '42.361145' , longitude : '-71.057083' , distance : '50mi' } ,
291+ q : 'rail stations' } )
292+
293+ assert ( os . matches . to_json . include? ( '{"multi_match":{"query":"rail stations","fields":' ) )
294+
295+ assert (
296+ os . query . to_json . include? ( '{"distance":"50mi","locations.geoshape":{"lat":"42.361145","lon":"-71.057083"}}' )
297+ )
298+ end
269299end
0 commit comments