@@ -872,7 +872,7 @@ class GraphqlControllerTest < ActionDispatch::IntegrationTest
872872 initial_hits_count = json_dataset [ 'data' ] [ 'search' ] [ 'hits' ]
873873 initial_still_images_count = json_dataset [ 'data' ] [ 'search' ] [ 'aggregations' ] [ 'contentType' ] . find do |x |
874874 x [ 'key' ] == 'still image'
875- end [ 'docCount' ]
875+ end [ 'docCount' ]
876876
877877 post '/graphql' , params : { query :
878878 '{
@@ -940,7 +940,7 @@ class GraphqlControllerTest < ActionDispatch::IntegrationTest
940940
941941 test 'graphql search respects perPage argument' do
942942 VCR . use_cassette ( 'opensearch_init' ) do
943- VCR . use_cassette ( 'graphql_search_per_page_5' , match_requests_on : [ : method, : uri] ) do
943+ VCR . use_cassette ( 'graphql_search_per_page_5' , match_requests_on : %i[ method uri ] ) do
944944 post '/graphql' , params : { query : '{
945945 search(perPage:5) {
946946 hits
@@ -1140,4 +1140,88 @@ class GraphqlControllerTest < ActionDispatch::IntegrationTest
11401140 end
11411141 end
11421142 end
1143+
1144+ test 'graphql search with useGlobalScoring true passes search_type to opensearch' do
1145+ mock_response = {
1146+ 'hits' => {
1147+ 'total' => { 'value' => 1 } ,
1148+ 'hits' => [
1149+ {
1150+ '_source' => {
1151+ 'title' => 'Data analytics and big data'
1152+ }
1153+ }
1154+ ]
1155+ }
1156+ }
1157+ # Verify that when useGlobalScoring is true, the search_type parameter is set
1158+ Opensearch . any_instance . expects ( :search ) . with do |_from , _params , _client , **kwargs |
1159+ kwargs [ :use_global_scoring ] == true
1160+ end . returns ( mock_response )
1161+
1162+ post '/graphql' , params : { query : '{
1163+ search(searchterm: "data analytics", useGlobalScoring: true) {
1164+ records {
1165+ title
1166+ }
1167+ }
1168+ }' }
1169+ assert_equal ( 200 , response . status )
1170+ end
1171+
1172+ test 'graphql search with useGlobalScoring false passes use_global_scoring false to opensearch' do
1173+ mock_response = {
1174+ 'hits' => {
1175+ 'total' => { 'value' => 1 } ,
1176+ 'hits' => [
1177+ {
1178+ '_source' => {
1179+ 'title' => 'Data analytics and big data'
1180+ }
1181+ }
1182+ ]
1183+ }
1184+ }
1185+ # Verify that when useGlobalScoring is false (or omitted), use_global_scoring is false
1186+ Opensearch . any_instance . expects ( :search ) . with do |_from , _params , _client , **kwargs |
1187+ kwargs [ :use_global_scoring ] == false
1188+ end . returns ( mock_response )
1189+
1190+ post '/graphql' , params : { query : '{
1191+ search(searchterm: "data analytics", useGlobalScoring: false) {
1192+ records {
1193+ title
1194+ }
1195+ }
1196+ }' }
1197+ assert_equal ( 200 , response . status )
1198+ end
1199+
1200+ test 'graphql search useGlobalScoring defaults to false' do
1201+ mock_response = {
1202+ 'hits' => {
1203+ 'total' => { 'value' => 1 } ,
1204+ 'hits' => [
1205+ {
1206+ '_source' => {
1207+ 'title' => 'Data analytics and big data'
1208+ }
1209+ }
1210+ ]
1211+ }
1212+ }
1213+ # Verify that when useGlobalScoring is not specified, use_global_scoring defaults to false
1214+ Opensearch . any_instance . expects ( :search ) . with do |_from , _params , _client , **kwargs |
1215+ kwargs [ :use_global_scoring ] == false
1216+ end . returns ( mock_response )
1217+
1218+ post '/graphql' , params : { query : '{
1219+ search(searchterm: "data analytics") {
1220+ records {
1221+ title
1222+ }
1223+ }
1224+ }' }
1225+ assert_equal ( 200 , response . status )
1226+ end
11431227end
0 commit comments