package pipelines

import (
	"encoding/json"
	"testing"

	. "github.com/smartystreets/goconvey/convey"
)

func TestSolrStage(t *testing.T) {
	// Build the RSInputs
	rsInputs := map[string]interface{}{
		"backend": "solr",
	}
	rsInputsInBytes, _ := json.Marshal(rsInputs)
	rsInputsAsString := string(rsInputsInBytes)

	rsStage := ReactiveSearchQuery

	/*Convey("Solr: index input value", t, func() {
		inputMap := map[string]interface{}{
			"host":       "us-east-8-11.solrcluster.com",
			"collection": "appbase_demo",
			"headers": map[string]interface{}{
				"Authorization": "Basic b3BlbnNvbHI6MjdhZmMyNmJhNDdjOTE5YjYyYWQ5OTVmMTUzMmY1NTc=",
			},
			"query": "q=address:southwest",
		}
		inputInBytes, _ := json.Marshal(inputMap)
		inputAsString := string(inputInBytes)

		solrQueryStage := SolrQuery
		False := false

		stages := []ESPipelineStage{
			{
				Use:             &solrQueryStage,
				Inputs:          &inputAsString,
				ContinueOnError: &False,
			},
		}
		pipeline := ESPipelineDoc{
			Stages: &stages,
		}

		pipelineExecutionContext := PipelineExecutionContext{
			envs: make(map[string]interface{}),
			request: PipelineExecutionRequest{
				Body:    []byte(""),
				Headers: make(map[string]string),
			},
		}
		res, _ := pipeline.executePipeline(pipelineExecutionContext, nil, false, nil, false, false, false, nil)
		resInBytes, _ := json.Marshal(res)

		resMap := make(map[string]interface{})
		json.Unmarshal(resInBytes, &resMap)

		resBody := resMap["response"].(map[string]interface{})["body"].(string)

		updatedResBody := jsonparser.Delete([]byte(resBody), "responseHeader", "QTime")

		expectedResponse := "{\"response\":{\"docs\":[{\"_root_\":\"752055129\",\"address\":\"4761 Southwest Martha Street, Portland, OR 97221, USA \",\"golden\":true,\"house_types\":\"private_house\",\"house_types_confidence\":1,\"house_types_gold\":\"private_house\",\"house_types_gold_reason\":\"There seems to be single entry or door per family or household (individual house, private house, townhouse etc)\",\"id\":\"752055129\",\"lat\":\"45.4852149\",\"location\":\"-122.726314 45.4852149\",\"long\":\"-122.726314\",\"residential_yes\":\"yes\",\"residential_yes_confidence\":1,\"residential_yes_gold\":\"yes\",\"residential_yes_gold_reason\":\"You can mostly see houses where people live\",\"sidewalk_ok\":\"no\",\"sidewalk_ok_confidence\":0.961,\"sidewalk_ok_gold\":\"no\",\"sidewalk_ok_gold_reason\":\"The sidewalk/pedestrian path is not safe for wheelchairs ��� it is not continuous or not wide enough or there seems to be other issues with the sidewalk\",\"trusted_judgments\":26,\"unit_state\":\"golden\",\"url\":\"http://maps.google.com/maps?cbll=45.4852149,-122.726314\\u0026layer=c\"},{\"_root_\":\"752055130\",\"address\":\"1545 Southwest Nancy Drive, Gresham, OR 97080, USA \",\"golden\":true,\"house_types\":\"private_house\",\"house_types_confidence\":0.9642,\"house_types_gold\":\"private_house\",\"house_types_gold_reason\":\"There seems to be single entry or door per family or household (individual house, private house, townhouse etc)\",\"id\":\"752055130\",\"lat\":\"45.484122\",\"location\":\"-122.472306 45.484122\",\"long\":\"-122.472306\",\"residential_yes\":\"yes\",\"residential_yes_confidence\":0.9642,\"residential_yes_gold\":\"yes\",\"residential_yes_gold_reason\":\"You can mostly see houses where people live\",\"sidewalk_ok\":\"yes\",\"sidewalk_ok_confidence\":0.9642,\"sidewalk_ok_gold\":\"yes\",\"sidewalk_ok_gold_reason\":\"There is a sidewalk available, it does look safe and wide enough\",\"trusted_judgments\":25,\"unit_state\":\"golden\",\"url\":\"http://maps.google.com/maps?cbll=45.484122,-122.472306\\u0026layer=c\"},{\"_root_\":\"752055132\",\"address\":\"2089 Southwest Nancy Drive, Gresham, OR 97080, USA \",\"golden\":true,\"house_types\":\"private_house\",\"house_types_confidence\":0.9174,\"house_types_gold\":\"private_house\",\"house_types_gold_reason\":\"There seems to be single entry or door per family or household (individual house, private house, townhouse etc)\",\"id\":\"752055132\",\"lat\":\"45.4822119\",\"location\":\"-122.476723 45.4822119\",\"long\":\"-122.476723\",\"residential_yes\":\"yes\",\"residential_yes_confidence\":0.9174,\"residential_yes_gold\":\"yes\",\"residential_yes_gold_reason\":\"You can mostly see houses where people live\",\"sidewalk_ok\":\"yes\",\"sidewalk_ok_confidence\":0.8304,\"trusted_judgments\":22,\"unit_state\":\"golden\",\"url\":\"http://maps.google.com/maps?cbll=45.4822119,-122.476723\\u0026layer=c\"},{\"_root_\":\"752055140\",\"address\":\"3255 Southwest Willamette Avenue, Corvallis, OR 97333, USA \",\"golden\":true,\"house_types\":\"private_house\",\"house_types_confidence\":1,\"house_types_gold\":\"private_house\",\"house_types_gold_reason\":\"There seems to be single entry or door per family or household (individual house, private house, townhouse etc)\",\"id\":\"752055140\",\"lat\":\"44.5468192\",\"location\":\"-123.2855851 44.5468192\",\"long\":\"-123.2855851\",\"residential_yes\":\"yes\",\"residential_yes_confidence\":1,\"residential_yes_gold\":\"yes\",\"residential_yes_gold_reason\":\"You can mostly see houses where people live\",\"sidewalk_ok\":\"yes\",\"sidewalk_ok_confidence\":0.9581,\"sidewalk_ok_gold_reason\":\"There is a sidewalk available, it does look safe and wide enough\",\"trusted_judgments\":26,\"unit_state\":\"golden\",\"url\":\"http://maps.google.com/maps?cbll=44.5468192,-123.2855851\\u0026layer=c\"},{\"_root_\":\"752055162\",\"address\":\"2345 Southwest Roxbury Avenue, Portland, OR 97225, USA \",\"golden\":true,\"house_types\":\"private_house\",\"house_types_confidence\":1,\"house_types_gold\":\"private_house\",\"house_types_gold_reason\":\"There seems to be single entry or door per family or household (individual house, private house, townhouse etc)\",\"id\":\"752055162\",\"lat\":\"45.503084\",\"location\":\"-122.788185 45.503084\",\"long\":\"-122.788185\",\"residential_yes\":\"yes\",\"residential_yes_confidence\":1,\"residential_yes_gold\":\"yes\",\"residential_yes_gold_reason\":\"You can mostly see houses where people live\",\"sidewalk_ok\":\"yes\",\"sidewalk_ok_confidence\":1,\"sidewalk_ok_gold\":\"yes\",\"sidewalk_ok_gold_reason\":\"There is a sidewalk available, it does look safe and wide enough\",\"trusted_judgments\":24,\"unit_state\":\"golden\",\"url\":\"http://maps.google.com/maps?cbll=45.503084,-122.788185\\u0026layer=c\"},{\"_root_\":\"752055163\",\"address\":\"11650 Southwest Riverwood Road, Portland, OR 97219, USA \",\"golden\":true,\"id\":\"752055163\",\"lat\":\"45.440947\",\"location\":\"-122.648567 45.440947\",\"long\":\"-122.648567\",\"residential_yes\":\"not_avail\",\"residential_yes_confidence\":1,\"residential_yes_gold\":\"not_avail\",\"residential_yes_gold_reason\":\"No street view\",\"trusted_judgments\":38,\"unit_state\":\"golden\",\"url\":\"http://maps.google.com/maps?cbll=45.440947,-122.648567\\u0026layer=c\"},{\"_root_\":\"752055164\",\"address\":\"10505 Southwest Clydesdale Place, Tigard, OR 97223, USA \",\"golden\":true,\"house_types\":\"private_house\",\"house_types_confidence\":1,\"house_types_gold\":\"private_house\",\"house_types_gold_reason\":\"There seems to be single entry or door per family or household (individual house, private house, townhouse etc)\",\"id\":\"752055164\",\"lat\":\"45.432026\",\"location\":\"-122.784792 45.432026\",\"long\":\"-122.784792\",\"residential_yes\":\"yes\",\"residential_yes_confidence\":1,\"residential_yes_gold\":\"yes\",\"residential_yes_gold_reason\":\"You can mostly see houses where people live\",\"sidewalk_ok\":\"yes\",\"sidewalk_ok_confidence\":0.9224,\"sidewalk_ok_gold\":\"yes\",\"sidewalk_ok_gold_reason\":\"There is a sidewalk available, it does look safe and wide enough\",\"trusted_judgments\":31,\"unit_state\":\"golden\",\"url\":\"http://maps.google.com/maps?cbll=45.432026,-122.784792\\u0026layer=c\"},{\"_root_\":\"752055167\",\"address\":\"7715 Southwest Nyberg Street, Tualatin, OR 97062, USA \",\"golden\":true,\"id\":\"752055167\",\"lat\":\"45.3830787\",\"location\":\"-122.7568875 45.3830787\",\"long\":\"-122.7568875\",\"residential_yes\":\"no\",\"residential_yes_confidence\":0.9629,\"residential_yes_gold\":\"no\\r\\nnot_avail\",\"trusted_judgments\":31,\"unit_state\":\"golden\",\"url\":\"http://maps.google.com/maps?cbll=45.3830787,-122.7568875\\u0026layer=c\"},{\"_root_\":\"752055171\",\"address\":\"1620 Southwest Walters Drive, Gresham, OR 97080, USA \",\"golden\":true,\"id\":\"752055171\",\"lat\":\"45.484963\",\"location\":\"-122.440431 45.484963\",\"long\":\"-122.440431\",\"residential_yes\":\"not_avail\",\"residential_yes_confidence\":0.9622,\"residential_yes_gold\":\"not_avail\",\"residential_yes_gold_reason\":\"No street view\",\"trusted_judgments\":24,\"unit_state\":\"golden\",\"url\":\"http://maps.google.com/maps?cbll=45.484963,-122.440431\\u0026layer=c\"},{\"_root_\":\"752055173\",\"address\":\"10735 Southwest Wakefield Street, Portland, OR 97225, USA \",\"golden\":true,\"house_types\":\"private_house\",\"house_types_confidence\":1,\"house_types_gold\":\"private_house\",\"house_types_gold_reason\":\"There seems to be single entry or door per family or household (individual house, private house, townhouse etc)\",\"id\":\"752055173\",\"lat\":\"45.505646\",\"location\":\"-122.787249 45.505646\",\"long\":\"-122.787249\",\"residential_yes\":\"yes\",\"residential_yes_confidence\":1,\"residential_yes_gold\":\"yes\",\"residential_yes_gold_reason\":\"You can mostly see houses where people live\",\"sidewalk_ok\":\"yes\",\"sidewalk_ok_confidence\":0.927,\"sidewalk_ok_gold\":\"yes\",\"sidewalk_ok_gold_reason\":\"There is a sidewalk available, it does look safe and wide enough\",\"trusted_judgments\":34,\"unit_state\":\"golden\",\"url\":\"http://maps.google.com/maps?cbll=45.505646,-122.787249\\u0026layer=c\"},{\"_root_\":\"752055192\",\"address\":\"590 Southwest Brookwood Avenue, Hillsboro, OR 97123, USA\",\"golden\":true,\"id\":\"752055192\",\"lat\":\"45.515796\",\"location\":\"-122.934329 45.515796\",\"long\":\"-122.934329\",\"residential_yes\":\"not_avail\",\"residential_yes_confidence\":1,\"residential_yes_gold\":\"not_avail\",\"trusted_judgments\":30,\"unit_state\":\"golden\",\"url\":\"http://maps.google.com/maps?cbll=45.515796,-122.934329\\u0026layer=c\"},{\"_root_\":\"752055196\",\"address\":\"8790 Southwest Reiling Street, Tigard, OR 97224, USA\",\"golden\":true,\"house_types\":\"private_house\",\"house_types_confidence\":1,\"house_types_gold\":\"private_house\",\"house_types_gold_reason\":\"There seems to be single entry or door per family or household (individual house, private house, townhouse etc)\",\"id\":\"752055196\",\"lat\":\"45.411288\",\"location\":\"-122.76592 45.411288\",\"long\":\"-122.76592\",\"residential_yes\":\"yes\",\"residential_yes_confidence\":1,\"residential_yes_gold\":\"yes\",\"residential_yes_gold_reason\":\"No street view\",\"sidewalk_ok\":\"yes\",\"sidewalk_ok_confidence\":0.9637,\"sidewalk_ok_gold\":\"yes\",\"sidewalk_ok_gold_reason\":\"There is a sidewalk available, it does look safe and wide enough\",\"trusted_judgments\":32,\"unit_state\":\"golden\",\"url\":\"http://maps.google.com/maps?cbll=45.411288,-122.765920\\u0026layer=c\"},{\"_root_\":\"752055559\",\"address\":\"11001 Hackamore Avenue Southwest, Albuquerque, NM 87121, USA\",\"golden\":false,\"house_types\":\"private_house\",\"house_types_confidence\":1,\"id\":\"752055559\",\"last_judgment_at\":\"2015-07-09T06:41:00Z\",\"lat\":\"35.06045951\",\"location\":\"-106.7538155 35.06045951\",\"long\":\"-106.7538155\",\"residential_yes\":\"yes\",\"residential_yes_confidence\":1,\"sidewalk_ok\":\"yes\",\"sidewalk_ok_confidence\":1,\"trusted_judgments\":1,\"unit_state\":\"finalized\",\"url\":\"http://maps.google.com/maps?cbll=35.060460,-106.753816\\u0026layer=c\"},{\"_root_\":\"752056470\",\"address\":\"5680 Southwest Glenbrook Road, Beaverton, OR 97007, USA\",\"golden\":false,\"house_types\":\"private_house\",\"house_types_confidence\":1,\"id\":\"752056470\",\"last_judgment_at\":\"2015-07-09T06:39:00Z\",\"lat\":\"45.47865193\",\"location\":\"-122.8340754 45.47865193\",\"long\":\"-122.8340754\",\"residential_yes\":\"yes\",\"residential_yes_confidence\":1,\"sidewalk_ok\":\"yes\",\"sidewalk_ok_confidence\":1,\"trusted_judgments\":1,\"unit_state\":\"finalized\",\"url\":\"http://maps.google.com/maps?cbll=45.478652,-122.834075\\u0026layer=c\"},{\"_root_\":\"752056578\",\"address\":\"Southwest 65th Terrace, Miami, FL 33183, USA\",\"golden\":false,\"id\":\"752056578\",\"last_judgment_at\":\"2015-07-09T06:42:00Z\",\"lat\":\"25.70679975\",\"location\":\"-80.41635363 25.70679975\",\"long\":\"-80.41635363\",\"residential_yes\":\"not_avail\",\"residential_yes_confidence\":1,\"trusted_judgments\":1,\"unit_state\":\"finalized\",\"url\":\"http://maps.google.com/maps?cbll=25.706800,-80.416354\\u0026layer=c\"},{\"_root_\":\"752055128\",\"address\":\"4210 Southwest 167th Avenue, Beaverton, OR 97007, USA \",\"golden\":true,\"house_types\":\"private_house\",\"house_types_confidence\":1,\"house_types_gold\":\"private_house\",\"house_types_gold_reason\":\"There seems to be single entry or door per family or household (individual house, private house, townhouse etc)\",\"id\":\"752055128\",\"lat\":\"45.489486\",\"location\":\"-122.848955 45.489486\",\"long\":\"-122.848955\",\"residential_yes\":\"yes\",\"residential_yes_confidence\":1,\"residential_yes_gold\":\"yes\",\"residential_yes_gold_reason\":\"You can mostly see houses where people live\",\"sidewalk_ok\":\"yes\",\"sidewalk_ok_confidence\":0.9225,\"sidewalk_ok_gold\":\"yes\",\"sidewalk_ok_gold_reason\":\"There is a sidewalk available, it does look safe and wide enough\",\"trusted_judgments\":25,\"unit_state\":\"golden\",\"url\":\"http://maps.google.com/maps?cbll=45.489486,-122.848955\\u0026layer=c\"},{\"_root_\":\"752055131\",\"address\":\"4990 Southwest 188th Place, Aloha, OR 97007, USA \",\"golden\":true,\"house_types\":\"private_house\",\"house_types_confidence\":1,\"house_types_gold\":\"private_house\",\"house_types_gold_reason\":\"There seems to be single entry or door per family or household (individual house, private house, townhouse etc)\",\"id\":\"752055131\",\"lat\":\"45.483409\",\"location\":\"-122.870494 45.483409\",\"long\":\"-122.870494\",\"residential_yes\":\"yes\",\"residential_yes_confidence\":1,\"residential_yes_gold\":\"yes\",\"residential_yes_gold_reason\":\"You can mostly see houses where people live\",\"sidewalk_ok\":\"yes\",\"sidewalk_ok_confidence\":0.9611,\"sidewalk_ok_gold_reason\":\"There is a sidewalk available, it does look safe and wide enough\",\"trusted_judgments\":23,\"unit_state\":\"golden\",\"url\":\"http://maps.google.com/maps?cbll=45.483409,-122.870494\\u0026layer=c\"},{\"_root_\":\"752055183\",\"address\":\"5900 Southwest Prosperity Park Road, Tualatin, OR 97062, USA \",\"golden\":true,\"id\":\"752055183\",\"lat\":\"45.367782\",\"location\":\"-122.736988 45.367782\",\"long\":\"-122.736988\",\"residential_yes\":\"not_avail\",\"residential_yes_confidence\":1,\"residential_yes_gold\":\"not_avail\",\"trusted_judgments\":23,\"unit_state\":\"golden\",\"url\":\"http://maps.google.com/maps?cbll=45.367782,-122.736988\\u0026layer=c\"},{\"_root_\":\"752055188\",\"address\":\"13201 Southwest 17th Court, Miramar, FL 33027, USA\",\"golden\":true,\"house_types\":\"private_house\",\"house_types_confidence\":1,\"house_types_gold\":\"private_house\",\"house_types_gold_reason\":\"There seems to be single entry or door per family or household (individual house, private house, townhouse etc)\",\"id\":\"752055188\",\"lat\":\"25.992766\",\"location\":\"-80.322621 25.992766\",\"long\":\"-80.322621\",\"residential_yes\":\"yes\",\"residential_yes_confidence\":1,\"residential_yes_gold\":\"yes\",\"residential_yes_gold_reason\":\"You can mostly see houses where people live\",\"sidewalk_ok\":\"yes\",\"sidewalk_ok_confidence\":1,\"sidewalk_ok_gold\":\"yes\",\"sidewalk_ok_gold_reason\":\"There is a sidewalk available, it does look safe and wide enough\",\"trusted_judgments\":33,\"unit_state\":\"golden\",\"url\":\"http://maps.google.com/maps?cbll=25.992766,-80.322621\\u0026layer=c\"},{\"_root_\":\"752055304\",\"address\":\"10441 Southwest 46th Street, Miami, FL 33165, USA\",\"golden\":false,\"house_types\":\"private_house\",\"house_types_confidence\":1,\"id\":\"752055304\",\"last_judgment_at\":\"2015-07-09T06:45:00Z\",\"lat\":\"25.7251367\",\"location\":\"-80.36462556 25.7251367\",\"long\":\"-80.36462556\",\"residential_yes\":\"yes\",\"residential_yes_confidence\":1,\"sidewalk_ok\":\"yes\",\"sidewalk_ok_confidence\":1,\"trusted_judgments\":1,\"unit_state\":\"finalized\",\"url\":\"http://maps.google.com/maps?cbll=25.725137,-80.364626\\u0026layer=c\"},{\"_root_\":\"752055305\",\"address\":\"4301 Southwest 107th Avenue, Miami, FL 33165, USA\",\"golden\":false,\"house_types\":\"private_house\",\"house_types_confidence\":1,\"id\":\"752055305\",\"last_judgment_at\":\"2015-07-09T06:39:00Z\",\"lat\":\"25.72730827\",\"location\":\"-80.36669022 25.72730827\",\"long\":\"-80.36669022\",\"residential_yes\":\"yes\",\"residential_yes_confidence\":1,\"sidewalk_ok\":\"yes\",\"sidewalk_ok_confidence\":1,\"trusted_judgments\":1,\"unit_state\":\"finalized\",\"url\":\"http://maps.google.com/maps?cbll=25.727308,-80.366690\\u0026layer=c\"},{\"_root_\":\"752055558\",\"address\":\"1612 Silver Sky Drive Southwest, Albuquerque, NM 87121, USA\",\"golden\":false,\"house_types\":\"private_house\",\"house_types_confidence\":1,\"id\":\"752055558\",\"last_judgment_at\":\"2015-07-09T06:50:00Z\",\"lat\":\"35.0484229\",\"location\":\"-106.7364489 35.0484229\",\"long\":\"-106.7364489\",\"residential_yes\":\"yes\",\"residential_yes_confidence\":1,\"sidewalk_ok\":\"yes\",\"sidewalk_ok_confidence\":1,\"trusted_judgments\":1,\"unit_state\":\"finalized\",\"url\":\"http://maps.google.com/maps?cbll=35.048423,-106.736449\\u0026layer=c\"},{\"_root_\":\"752056471\",\"address\":\"6360 Southwest 154th Place, Beaverton, OR 97007, USA\",\"golden\":false,\"house_types\":\"private_house\",\"house_types_confidence\":1,\"id\":\"752056471\",\"last_judgment_at\":\"2015-07-09T06:30:00Z\",\"lat\":\"45.47374371\",\"location\":\"-122.8361185 45.47374371\",\"long\":\"-122.8361185\",\"residential_yes\":\"yes\",\"residential_yes_confidence\":1,\"sidewalk_ok\":\"yes\",\"sidewalk_ok_confidence\":1,\"trusted_judgments\":1,\"unit_state\":\"finalized\",\"url\":\"http://maps.google.com/maps?cbll=45.473744,-122.836118\\u0026layer=c\"},{\"_root_\":\"752056576\",\"address\":\"5015 Southwest 114th Avenue, Miami, FL 33165, USA\",\"golden\":false,\"house_types\":\"private_house\",\"house_types_confidence\":1,\"id\":\"752056576\",\"last_judgment_at\":\"2015-07-09T06:58:00Z\",\"lat\":\"25.72032098\",\"location\":\"-80.37921526 25.72032098\",\"long\":\"-80.37921526\",\"residential_yes\":\"yes\",\"residential_yes_confidence\":1,\"sidewalk_ok\":\"yes\",\"sidewalk_ok_confidence\":1,\"trusted_judgments\":1,\"unit_state\":\"finalized\",\"url\":\"http://maps.google.com/maps?cbll=25.720321,-80.379215\\u0026layer=c\"},{\"_root_\":\"752056577\",\"address\":\"11171 Southwest 57th Terrace, Miami, FL 33173, USA\",\"golden\":false,\"house_types\":\"private_house\",\"house_types_confidence\":1,\"id\":\"752056577\",\"last_judgment_at\":\"2015-07-09T07:01:00Z\",\"lat\":\"25.71392911\",\"location\":\"-80.37413524 25.71392911\",\"long\":\"-80.37413524\",\"residential_yes\":\"yes\",\"residential_yes_confidence\":1,\"sidewalk_ok\":\"yes\",\"sidewalk_ok_confidence\":1,\"trusted_judgments\":1,\"unit_state\":\"finalized\",\"url\":\"http://maps.google.com/maps?cbll=25.713929,-80.374135\\u0026layer=c\"},{\"_root_\":\"752056579\",\"address\":\"11893 Southwest 56th Street, Miami, FL 33175, USA\",\"golden\":false,\"id\":\"752056579\",\"last_judgment_at\":\"2015-07-09T06:32:00Z\",\"lat\":\"25.71584582\",\"location\":\"-80.38476238 25.71584582\",\"long\":\"-80.38476238\",\"residential_yes\":\"no\",\"residential_yes_confidence\":1,\"trusted_judgments\":1,\"unit_state\":\"finalized\",\"url\":\"http://maps.google.com/maps?cbll=25.715846,-80.384762\\u0026layer=c\"},{\"_root_\":\"752056580\",\"address\":\"6025 Southwest 123rd Avenue, Miami, FL 33183, USA\",\"golden\":false,\"id\":\"752056580\",\"last_judgment_at\":\"2015-07-09T07:00:00Z\",\"lat\":\"25.71107741\",\"location\":\"-80.39184188 25.71107741\",\"long\":\"-80.39184188\",\"residential_yes\":\"not_avail\",\"residential_yes_confidence\":1,\"trusted_judgments\":1,\"unit_state\":\"finalized\",\"url\":\"http://maps.google.com/maps?cbll=25.711077,-80.391842\\u0026layer=c\"},{\"_root_\":\"752056581\",\"address\":\"5798 Southwest 123rd Avenue, Miami, FL 33183, USA\",\"golden\":false,\"id\":\"752056581\",\"last_judgment_at\":\"2015-07-09T07:01:00Z\",\"lat\":\"25.71304518\",\"location\":\"-80.39403149 25.71304518\",\"long\":\"-80.39403149\",\"residential_yes\":\"not_avail\",\"residential_yes_confidence\":1,\"trusted_judgments\":1,\"unit_state\":\"finalized\",\"url\":\"http://maps.google.com/maps?cbll=25.713045,-80.394031\\u0026layer=c\"},{\"_root_\":\"752056795\",\"address\":\"8865 Southwest 16th Street, Miami, FL 33165, USA\",\"golden\":false,\"id\":\"752056795\",\"last_judgment_at\":\"2015-07-09T07:06:00Z\",\"lat\":\"25.75562219\",\"location\":\"-80.34046094 25.75562219\",\"long\":\"-80.34046094\",\"residential_yes\":\"not_avail\",\"residential_yes_confidence\":1,\"trusted_judgments\":1,\"unit_state\":\"finalized\",\"url\":\"http://maps.google.com/maps?cbll=25.755622,-80.340461\\u0026layer=c\"},{\"_root_\":\"752056796\",\"address\":\"3199 Southwest 109th Court, Miami, FL 33165, USA\",\"golden\":false,\"house_types\":\"private_house\",\"house_types_confidence\":1,\"id\":\"752056796\",\"last_judgment_at\":\"2015-07-09T06:57:00Z\",\"lat\":\"25.73970622\",\"location\":\"-80.37254295 25.73970622\",\"long\":\"-80.37254295\",\"residential_yes\":\"yes\",\"residential_yes_confidence\":1,\"sidewalk_ok\":\"no\",\"sidewalk_ok_confidence\":1,\"trusted_judgments\":1,\"unit_state\":\"finalized\",\"url\":\"http://maps.google.com/maps?cbll=25.739706,-80.372543\\u0026layer=c\"},{\"_root_\":\"752056797\",\"address\":\"10210 Southwest 19th Street, Miami, FL 33165, USA\",\"golden\":false,\"house_types\":\"private_house\",\"house_types_confidence\":1,\"id\":\"752056797\",\"last_judgment_at\":\"2015-07-09T06:50:00Z\",\"lat\":\"25.75154644\",\"location\":\"-80.36041317 25.75154644\",\"long\":\"-80.36041317\",\"residential_yes\":\"yes\",\"residential_yes_confidence\":1,\"sidewalk_ok\":\"yes\",\"sidewalk_ok_confidence\":1,\"trusted_judgments\":1,\"unit_state\":\"finalized\",\"url\":\"http://maps.google.com/maps?cbll=25.751546,-80.360413\\u0026layer=c\"},{\"_root_\":\"752056798\",\"address\":\"3350 Southwest 129th Avenue, Miami, FL 33175, USA\",\"golden\":false,\"id\":\"752056798\",\"last_judgment_at\":\"2015-07-09T06:37:00Z\",\"lat\":\"25.73721927\",\"location\":\"-80.40445499 25.73721927\",\"long\":\"-80.40445499\",\"residential_yes\":\"not_avail\",\"residential_yes_confidence\":1,\"trusted_judgments\":1,\"unit_state\":\"finalized\",\"url\":\"http://maps.google.com/maps?cbll=25.737219,-80.404455\\u0026layer=c\"},{\"_root_\":\"752056799\",\"address\":\"3715 Southwest 121st Avenue, Miami, FL 33175, USA\",\"golden\":false,\"house_types\":\"private_house\",\"house_types_confidence\":1,\"id\":\"752056799\",\"last_judgment_at\":\"2015-07-09T06:59:00Z\",\"lat\":\"25.73423253\",\"location\":\"-80.39071936 25.73423253\",\"long\":\"-80.39071936\",\"residential_yes\":\"yes\",\"residential_yes_confidence\":1,\"sidewalk_ok\":\"yes\",\"sidewalk_ok_confidence\":1,\"trusted_judgments\":1,\"unit_state\":\"finalized\",\"url\":\"http://maps.google.com/maps?cbll=25.734233,-80.390719\\u0026layer=c\"},{\"_root_\":\"752055898\",\"address\":\"6181 Southwest 153rd Court Road, Miami, FL 33193, USA\",\"golden\":false,\"house_types\":\"private_house\",\"house_types_confidence\":1,\"id\":\"752055898\",\"last_judgment_at\":\"2015-07-09T06:32:00Z\",\"lat\":\"25.70988693\",\"location\":\"-80.44280531 25.70988693\",\"long\":\"-80.44280531\",\"residential_yes\":\"yes\",\"residential_yes_confidence\":1,\"sidewalk_ok\":\"yes\",\"sidewalk_ok_confidence\":1,\"trusted_judgments\":1,\"unit_state\":\"finalized\",\"url\":\"http://maps.google.com/maps?cbll=25.709887,-80.442805\\u0026layer=c\"},{\"_root_\":\"752055993\",\"address\":\"66-68 Southwest 47th Street, Miami, FL 33155, USA\",\"golden\":false,\"house_types\":\"private_house\",\"house_types_confidence\":1,\"id\":\"752055993\",\"last_judgment_at\":\"2015-07-09T07:17:00Z\",\"lat\":\"25.7726238\",\"location\":\"-80.27199793 25.7726238\",\"long\":\"-80.27199793\",\"residential_yes\":\"yes\",\"residential_yes_confidence\":1,\"sidewalk_ok\":\"yes\",\"sidewalk_ok_confidence\":1,\"trusted_judgments\":1,\"unit_state\":\"finalized\",\"url\":\"http://maps.google.com/maps?cbll=25.772624,-80.271998\\u0026layer=c\"},{\"_root_\":\"752056794\",\"address\":\"2685-2715 Southwest 109th Avenue, Miami, FL 33165, USA\",\"golden\":false,\"house_types\":\"private_house\",\"house_types_confidence\":1,\"id\":\"752056794\",\"last_judgment_at\":\"2015-07-09T07:00:00Z\",\"lat\":\"25.74418782\",\"location\":\"-80.37179383 25.74418782\",\"long\":\"-80.37179383\",\"residential_yes\":\"yes\",\"residential_yes_confidence\":1,\"sidewalk_ok\":\"Not sure, mixed\",\"sidewalk_ok_confidence\":1,\"trusted_judgments\":1,\"unit_state\":\"finalized\",\"url\":\"http://maps.google.com/maps?cbll=25.744188,-80.371794\\u0026layer=c\"},{\"_root_\":\"752056995\",\"address\":\"7350 Southwest 34th Street Road, Miami, FL 33155, USA\",\"golden\":false,\"house_types\":\"private_house\",\"house_types_confidence\":1,\"id\":\"752056995\",\"last_judgment_at\":\"2015-07-09T07:02:00Z\",\"lat\":\"25.7415286\",\"location\":\"-80.31475828 25.7415286\",\"long\":\"-80.31475828\",\"residential_yes\":\"yes\",\"residential_yes_confidence\":1,\"sidewalk_ok\":\"yes\",\"sidewalk_ok_confidence\":1,\"trusted_judgments\":1,\"unit_state\":\"finalized\",\"url\":\"http://maps.google.com/maps?cbll=25.741529,-80.314758\\u0026layer=c\"},{\"_root_\":\"752056996\",\"address\":\"7580-7598 Southwest 28th Street Road, Miami, FL 33155, USA\",\"golden\":false,\"house_types\":\"private_house\",\"house_types_confidence\":1,\"id\":\"752056996\",\"last_judgment_at\":\"2015-07-09T06:42:00Z\",\"lat\":\"25.74575446\",\"location\":\"-80.31899785 25.74575446\",\"long\":\"-80.31899785\",\"residential_yes\":\"yes\",\"residential_yes_confidence\":1,\"sidewalk_ok\":\"yes\",\"sidewalk_ok_confidence\":1,\"trusted_judgments\":1,\"unit_state\":\"finalized\",\"url\":\"http://maps.google.com/maps?cbll=25.745754,-80.318998\\u0026layer=c\"}],\"numFound\":38,\"numFoundExact\":true,\"start\":0},\"responseHeader\":{\"status\":0}}"

		So(string(updatedResBody), ShouldResemble, expectedResponse)
	})

	Convey("Solr: query with response matching", t, func() {
		inputMap := map[string]interface{}{
			"host":       "us-east-8-11.solrcluster.com",
			"collection": "appbase_demo",
			"headers": map[string]interface{}{
				"Authorization": "Basic b3BlbnNvbHI6MjdhZmMyNmJhNDdjOTE5YjYyYWQ5OTVmMTUzMmY1NTc=",
			},
			"query": "q=address:southwest",
		}
		inputInBytes, _ := json.Marshal(inputMap)
		inputAsString := string(inputInBytes)

		solrQueryStage := SolrQuery
		False := false

		stages := []ESPipelineStage{
			{
				Use:             &solrQueryStage,
				Inputs:          &inputAsString,
				ContinueOnError: &False,
			},
		}
		pipeline := ESPipelineDoc{
			Stages: &stages,
		}

		pipelineExecutionContext := PipelineExecutionContext{
			envs: make(map[string]interface{}),
			request: PipelineExecutionRequest{
				Body:    []byte(""),
				Headers: make(map[string]string),
			},
		}
		res, _ := pipeline.executePipeline(pipelineExecutionContext, nil, false, nil, false, false, false, nil)
		resInBytes, _ := json.Marshal(res)

		resMap := make(map[string]interface{})
		json.Unmarshal(resInBytes, &resMap)

		resBody := resMap["response"].(map[string]interface{})["body"].(string)

		updatedResBody := jsonparser.Delete([]byte(resBody), "responseHeader", "QTime")

		expectedResponse := "{\"response\":{\"docs\":[{\"_root_\":\"752055129\",\"address\":\"4761 Southwest Martha Street, Portland, OR 97221, USA \",\"golden\":true,\"house_types\":\"private_house\",\"house_types_confidence\":1,\"house_types_gold\":\"private_house\",\"house_types_gold_reason\":\"There seems to be single entry or door per family or household (individual house, private house, townhouse etc)\",\"id\":\"752055129\",\"lat\":\"45.4852149\",\"location\":\"-122.726314 45.4852149\",\"long\":\"-122.726314\",\"residential_yes\":\"yes\",\"residential_yes_confidence\":1,\"residential_yes_gold\":\"yes\",\"residential_yes_gold_reason\":\"You can mostly see houses where people live\",\"sidewalk_ok\":\"no\",\"sidewalk_ok_confidence\":0.961,\"sidewalk_ok_gold\":\"no\",\"sidewalk_ok_gold_reason\":\"The sidewalk/pedestrian path is not safe for wheelchairs ��� it is not continuous or not wide enough or there seems to be other issues with the sidewalk\",\"trusted_judgments\":26,\"unit_state\":\"golden\",\"url\":\"http://maps.google.com/maps?cbll=45.4852149,-122.726314\\u0026layer=c\"},{\"_root_\":\"752055130\",\"address\":\"1545 Southwest Nancy Drive, Gresham, OR 97080, USA \",\"golden\":true,\"house_types\":\"private_house\",\"house_types_confidence\":0.9642,\"house_types_gold\":\"private_house\",\"house_types_gold_reason\":\"There seems to be single entry or door per family or household (individual house, private house, townhouse etc)\",\"id\":\"752055130\",\"lat\":\"45.484122\",\"location\":\"-122.472306 45.484122\",\"long\":\"-122.472306\",\"residential_yes\":\"yes\",\"residential_yes_confidence\":0.9642,\"residential_yes_gold\":\"yes\",\"residential_yes_gold_reason\":\"You can mostly see houses where people live\",\"sidewalk_ok\":\"yes\",\"sidewalk_ok_confidence\":0.9642,\"sidewalk_ok_gold\":\"yes\",\"sidewalk_ok_gold_reason\":\"There is a sidewalk available, it does look safe and wide enough\",\"trusted_judgments\":25,\"unit_state\":\"golden\",\"url\":\"http://maps.google.com/maps?cbll=45.484122,-122.472306\\u0026layer=c\"},{\"_root_\":\"752055132\",\"address\":\"2089 Southwest Nancy Drive, Gresham, OR 97080, USA \",\"golden\":true,\"house_types\":\"private_house\",\"house_types_confidence\":0.9174,\"house_types_gold\":\"private_house\",\"house_types_gold_reason\":\"There seems to be single entry or door per family or household (individual house, private house, townhouse etc)\",\"id\":\"752055132\",\"lat\":\"45.4822119\",\"location\":\"-122.476723 45.4822119\",\"long\":\"-122.476723\",\"residential_yes\":\"yes\",\"residential_yes_confidence\":0.9174,\"residential_yes_gold\":\"yes\",\"residential_yes_gold_reason\":\"You can mostly see houses where people live\",\"sidewalk_ok\":\"yes\",\"sidewalk_ok_confidence\":0.8304,\"trusted_judgments\":22,\"unit_state\":\"golden\",\"url\":\"http://maps.google.com/maps?cbll=45.4822119,-122.476723\\u0026layer=c\"},{\"_root_\":\"752055140\",\"address\":\"3255 Southwest Willamette Avenue, Corvallis, OR 97333, USA \",\"golden\":true,\"house_types\":\"private_house\",\"house_types_confidence\":1,\"house_types_gold\":\"private_house\",\"house_types_gold_reason\":\"There seems to be single entry or door per family or household (individual house, private house, townhouse etc)\",\"id\":\"752055140\",\"lat\":\"44.5468192\",\"location\":\"-123.2855851 44.5468192\",\"long\":\"-123.2855851\",\"residential_yes\":\"yes\",\"residential_yes_confidence\":1,\"residential_yes_gold\":\"yes\",\"residential_yes_gold_reason\":\"You can mostly see houses where people live\",\"sidewalk_ok\":\"yes\",\"sidewalk_ok_confidence\":0.9581,\"sidewalk_ok_gold_reason\":\"There is a sidewalk available, it does look safe and wide enough\",\"trusted_judgments\":26,\"unit_state\":\"golden\",\"url\":\"http://maps.google.com/maps?cbll=44.5468192,-123.2855851\\u0026layer=c\"},{\"_root_\":\"752055162\",\"address\":\"2345 Southwest Roxbury Avenue, Portland, OR 97225, USA \",\"golden\":true,\"house_types\":\"private_house\",\"house_types_confidence\":1,\"house_types_gold\":\"private_house\",\"house_types_gold_reason\":\"There seems to be single entry or door per family or household (individual house, private house, townhouse etc)\",\"id\":\"752055162\",\"lat\":\"45.503084\",\"location\":\"-122.788185 45.503084\",\"long\":\"-122.788185\",\"residential_yes\":\"yes\",\"residential_yes_confidence\":1,\"residential_yes_gold\":\"yes\",\"residential_yes_gold_reason\":\"You can mostly see houses where people live\",\"sidewalk_ok\":\"yes\",\"sidewalk_ok_confidence\":1,\"sidewalk_ok_gold\":\"yes\",\"sidewalk_ok_gold_reason\":\"There is a sidewalk available, it does look safe and wide enough\",\"trusted_judgments\":24,\"unit_state\":\"golden\",\"url\":\"http://maps.google.com/maps?cbll=45.503084,-122.788185\\u0026layer=c\"},{\"_root_\":\"752055163\",\"address\":\"11650 Southwest Riverwood Road, Portland, OR 97219, USA \",\"golden\":true,\"id\":\"752055163\",\"lat\":\"45.440947\",\"location\":\"-122.648567 45.440947\",\"long\":\"-122.648567\",\"residential_yes\":\"not_avail\",\"residential_yes_confidence\":1,\"residential_yes_gold\":\"not_avail\",\"residential_yes_gold_reason\":\"No street view\",\"trusted_judgments\":38,\"unit_state\":\"golden\",\"url\":\"http://maps.google.com/maps?cbll=45.440947,-122.648567\\u0026layer=c\"},{\"_root_\":\"752055164\",\"address\":\"10505 Southwest Clydesdale Place, Tigard, OR 97223, USA \",\"golden\":true,\"house_types\":\"private_house\",\"house_types_confidence\":1,\"house_types_gold\":\"private_house\",\"house_types_gold_reason\":\"There seems to be single entry or door per family or household (individual house, private house, townhouse etc)\",\"id\":\"752055164\",\"lat\":\"45.432026\",\"location\":\"-122.784792 45.432026\",\"long\":\"-122.784792\",\"residential_yes\":\"yes\",\"residential_yes_confidence\":1,\"residential_yes_gold\":\"yes\",\"residential_yes_gold_reason\":\"You can mostly see houses where people live\",\"sidewalk_ok\":\"yes\",\"sidewalk_ok_confidence\":0.9224,\"sidewalk_ok_gold\":\"yes\",\"sidewalk_ok_gold_reason\":\"There is a sidewalk available, it does look safe and wide enough\",\"trusted_judgments\":31,\"unit_state\":\"golden\",\"url\":\"http://maps.google.com/maps?cbll=45.432026,-122.784792\\u0026layer=c\"},{\"_root_\":\"752055167\",\"address\":\"7715 Southwest Nyberg Street, Tualatin, OR 97062, USA \",\"golden\":true,\"id\":\"752055167\",\"lat\":\"45.3830787\",\"location\":\"-122.7568875 45.3830787\",\"long\":\"-122.7568875\",\"residential_yes\":\"no\",\"residential_yes_confidence\":0.9629,\"residential_yes_gold\":\"no\\r\\nnot_avail\",\"trusted_judgments\":31,\"unit_state\":\"golden\",\"url\":\"http://maps.google.com/maps?cbll=45.3830787,-122.7568875\\u0026layer=c\"},{\"_root_\":\"752055171\",\"address\":\"1620 Southwest Walters Drive, Gresham, OR 97080, USA \",\"golden\":true,\"id\":\"752055171\",\"lat\":\"45.484963\",\"location\":\"-122.440431 45.484963\",\"long\":\"-122.440431\",\"residential_yes\":\"not_avail\",\"residential_yes_confidence\":0.9622,\"residential_yes_gold\":\"not_avail\",\"residential_yes_gold_reason\":\"No street view\",\"trusted_judgments\":24,\"unit_state\":\"golden\",\"url\":\"http://maps.google.com/maps?cbll=45.484963,-122.440431\\u0026layer=c\"},{\"_root_\":\"752055173\",\"address\":\"10735 Southwest Wakefield Street, Portland, OR 97225, USA \",\"golden\":true,\"house_types\":\"private_house\",\"house_types_confidence\":1,\"house_types_gold\":\"private_house\",\"house_types_gold_reason\":\"There seems to be single entry or door per family or household (individual house, private house, townhouse etc)\",\"id\":\"752055173\",\"lat\":\"45.505646\",\"location\":\"-122.787249 45.505646\",\"long\":\"-122.787249\",\"residential_yes\":\"yes\",\"residential_yes_confidence\":1,\"residential_yes_gold\":\"yes\",\"residential_yes_gold_reason\":\"You can mostly see houses where people live\",\"sidewalk_ok\":\"yes\",\"sidewalk_ok_confidence\":0.927,\"sidewalk_ok_gold\":\"yes\",\"sidewalk_ok_gold_reason\":\"There is a sidewalk available, it does look safe and wide enough\",\"trusted_judgments\":34,\"unit_state\":\"golden\",\"url\":\"http://maps.google.com/maps?cbll=45.505646,-122.787249\\u0026layer=c\"},{\"_root_\":\"752055192\",\"address\":\"590 Southwest Brookwood Avenue, Hillsboro, OR 97123, USA\",\"golden\":true,\"id\":\"752055192\",\"lat\":\"45.515796\",\"location\":\"-122.934329 45.515796\",\"long\":\"-122.934329\",\"residential_yes\":\"not_avail\",\"residential_yes_confidence\":1,\"residential_yes_gold\":\"not_avail\",\"trusted_judgments\":30,\"unit_state\":\"golden\",\"url\":\"http://maps.google.com/maps?cbll=45.515796,-122.934329\\u0026layer=c\"},{\"_root_\":\"752055196\",\"address\":\"8790 Southwest Reiling Street, Tigard, OR 97224, USA\",\"golden\":true,\"house_types\":\"private_house\",\"house_types_confidence\":1,\"house_types_gold\":\"private_house\",\"house_types_gold_reason\":\"There seems to be single entry or door per family or household (individual house, private house, townhouse etc)\",\"id\":\"752055196\",\"lat\":\"45.411288\",\"location\":\"-122.76592 45.411288\",\"long\":\"-122.76592\",\"residential_yes\":\"yes\",\"residential_yes_confidence\":1,\"residential_yes_gold\":\"yes\",\"residential_yes_gold_reason\":\"No street view\",\"sidewalk_ok\":\"yes\",\"sidewalk_ok_confidence\":0.9637,\"sidewalk_ok_gold\":\"yes\",\"sidewalk_ok_gold_reason\":\"There is a sidewalk available, it does look safe and wide enough\",\"trusted_judgments\":32,\"unit_state\":\"golden\",\"url\":\"http://maps.google.com/maps?cbll=45.411288,-122.765920\\u0026layer=c\"},{\"_root_\":\"752055559\",\"address\":\"11001 Hackamore Avenue Southwest, Albuquerque, NM 87121, USA\",\"golden\":false,\"house_types\":\"private_house\",\"house_types_confidence\":1,\"id\":\"752055559\",\"last_judgment_at\":\"2015-07-09T06:41:00Z\",\"lat\":\"35.06045951\",\"location\":\"-106.7538155 35.06045951\",\"long\":\"-106.7538155\",\"residential_yes\":\"yes\",\"residential_yes_confidence\":1,\"sidewalk_ok\":\"yes\",\"sidewalk_ok_confidence\":1,\"trusted_judgments\":1,\"unit_state\":\"finalized\",\"url\":\"http://maps.google.com/maps?cbll=35.060460,-106.753816\\u0026layer=c\"},{\"_root_\":\"752056470\",\"address\":\"5680 Southwest Glenbrook Road, Beaverton, OR 97007, USA\",\"golden\":false,\"house_types\":\"private_house\",\"house_types_confidence\":1,\"id\":\"752056470\",\"last_judgment_at\":\"2015-07-09T06:39:00Z\",\"lat\":\"45.47865193\",\"location\":\"-122.8340754 45.47865193\",\"long\":\"-122.8340754\",\"residential_yes\":\"yes\",\"residential_yes_confidence\":1,\"sidewalk_ok\":\"yes\",\"sidewalk_ok_confidence\":1,\"trusted_judgments\":1,\"unit_state\":\"finalized\",\"url\":\"http://maps.google.com/maps?cbll=45.478652,-122.834075\\u0026layer=c\"},{\"_root_\":\"752056578\",\"address\":\"Southwest 65th Terrace, Miami, FL 33183, USA\",\"golden\":false,\"id\":\"752056578\",\"last_judgment_at\":\"2015-07-09T06:42:00Z\",\"lat\":\"25.70679975\",\"location\":\"-80.41635363 25.70679975\",\"long\":\"-80.41635363\",\"residential_yes\":\"not_avail\",\"residential_yes_confidence\":1,\"trusted_judgments\":1,\"unit_state\":\"finalized\",\"url\":\"http://maps.google.com/maps?cbll=25.706800,-80.416354\\u0026layer=c\"},{\"_root_\":\"752055128\",\"address\":\"4210 Southwest 167th Avenue, Beaverton, OR 97007, USA \",\"golden\":true,\"house_types\":\"private_house\",\"house_types_confidence\":1,\"house_types_gold\":\"private_house\",\"house_types_gold_reason\":\"There seems to be single entry or door per family or household (individual house, private house, townhouse etc)\",\"id\":\"752055128\",\"lat\":\"45.489486\",\"location\":\"-122.848955 45.489486\",\"long\":\"-122.848955\",\"residential_yes\":\"yes\",\"residential_yes_confidence\":1,\"residential_yes_gold\":\"yes\",\"residential_yes_gold_reason\":\"You can mostly see houses where people live\",\"sidewalk_ok\":\"yes\",\"sidewalk_ok_confidence\":0.9225,\"sidewalk_ok_gold\":\"yes\",\"sidewalk_ok_gold_reason\":\"There is a sidewalk available, it does look safe and wide enough\",\"trusted_judgments\":25,\"unit_state\":\"golden\",\"url\":\"http://maps.google.com/maps?cbll=45.489486,-122.848955\\u0026layer=c\"},{\"_root_\":\"752055131\",\"address\":\"4990 Southwest 188th Place, Aloha, OR 97007, USA \",\"golden\":true,\"house_types\":\"private_house\",\"house_types_confidence\":1,\"house_types_gold\":\"private_house\",\"house_types_gold_reason\":\"There seems to be single entry or door per family or household (individual house, private house, townhouse etc)\",\"id\":\"752055131\",\"lat\":\"45.483409\",\"location\":\"-122.870494 45.483409\",\"long\":\"-122.870494\",\"residential_yes\":\"yes\",\"residential_yes_confidence\":1,\"residential_yes_gold\":\"yes\",\"residential_yes_gold_reason\":\"You can mostly see houses where people live\",\"sidewalk_ok\":\"yes\",\"sidewalk_ok_confidence\":0.9611,\"sidewalk_ok_gold_reason\":\"There is a sidewalk available, it does look safe and wide enough\",\"trusted_judgments\":23,\"unit_state\":\"golden\",\"url\":\"http://maps.google.com/maps?cbll=45.483409,-122.870494\\u0026layer=c\"},{\"_root_\":\"752055183\",\"address\":\"5900 Southwest Prosperity Park Road, Tualatin, OR 97062, USA \",\"golden\":true,\"id\":\"752055183\",\"lat\":\"45.367782\",\"location\":\"-122.736988 45.367782\",\"long\":\"-122.736988\",\"residential_yes\":\"not_avail\",\"residential_yes_confidence\":1,\"residential_yes_gold\":\"not_avail\",\"trusted_judgments\":23,\"unit_state\":\"golden\",\"url\":\"http://maps.google.com/maps?cbll=45.367782,-122.736988\\u0026layer=c\"},{\"_root_\":\"752055188\",\"address\":\"13201 Southwest 17th Court, Miramar, FL 33027, USA\",\"golden\":true,\"house_types\":\"private_house\",\"house_types_confidence\":1,\"house_types_gold\":\"private_house\",\"house_types_gold_reason\":\"There seems to be single entry or door per family or household (individual house, private house, townhouse etc)\",\"id\":\"752055188\",\"lat\":\"25.992766\",\"location\":\"-80.322621 25.992766\",\"long\":\"-80.322621\",\"residential_yes\":\"yes\",\"residential_yes_confidence\":1,\"residential_yes_gold\":\"yes\",\"residential_yes_gold_reason\":\"You can mostly see houses where people live\",\"sidewalk_ok\":\"yes\",\"sidewalk_ok_confidence\":1,\"sidewalk_ok_gold\":\"yes\",\"sidewalk_ok_gold_reason\":\"There is a sidewalk available, it does look safe and wide enough\",\"trusted_judgments\":33,\"unit_state\":\"golden\",\"url\":\"http://maps.google.com/maps?cbll=25.992766,-80.322621\\u0026layer=c\"},{\"_root_\":\"752055304\",\"address\":\"10441 Southwest 46th Street, Miami, FL 33165, USA\",\"golden\":false,\"house_types\":\"private_house\",\"house_types_confidence\":1,\"id\":\"752055304\",\"last_judgment_at\":\"2015-07-09T06:45:00Z\",\"lat\":\"25.7251367\",\"location\":\"-80.36462556 25.7251367\",\"long\":\"-80.36462556\",\"residential_yes\":\"yes\",\"residential_yes_confidence\":1,\"sidewalk_ok\":\"yes\",\"sidewalk_ok_confidence\":1,\"trusted_judgments\":1,\"unit_state\":\"finalized\",\"url\":\"http://maps.google.com/maps?cbll=25.725137,-80.364626\\u0026layer=c\"},{\"_root_\":\"752055305\",\"address\":\"4301 Southwest 107th Avenue, Miami, FL 33165, USA\",\"golden\":false,\"house_types\":\"private_house\",\"house_types_confidence\":1,\"id\":\"752055305\",\"last_judgment_at\":\"2015-07-09T06:39:00Z\",\"lat\":\"25.72730827\",\"location\":\"-80.36669022 25.72730827\",\"long\":\"-80.36669022\",\"residential_yes\":\"yes\",\"residential_yes_confidence\":1,\"sidewalk_ok\":\"yes\",\"sidewalk_ok_confidence\":1,\"trusted_judgments\":1,\"unit_state\":\"finalized\",\"url\":\"http://maps.google.com/maps?cbll=25.727308,-80.366690\\u0026layer=c\"},{\"_root_\":\"752055558\",\"address\":\"1612 Silver Sky Drive Southwest, Albuquerque, NM 87121, USA\",\"golden\":false,\"house_types\":\"private_house\",\"house_types_confidence\":1,\"id\":\"752055558\",\"last_judgment_at\":\"2015-07-09T06:50:00Z\",\"lat\":\"35.0484229\",\"location\":\"-106.7364489 35.0484229\",\"long\":\"-106.7364489\",\"residential_yes\":\"yes\",\"residential_yes_confidence\":1,\"sidewalk_ok\":\"yes\",\"sidewalk_ok_confidence\":1,\"trusted_judgments\":1,\"unit_state\":\"finalized\",\"url\":\"http://maps.google.com/maps?cbll=35.048423,-106.736449\\u0026layer=c\"},{\"_root_\":\"752056471\",\"address\":\"6360 Southwest 154th Place, Beaverton, OR 97007, USA\",\"golden\":false,\"house_types\":\"private_house\",\"house_types_confidence\":1,\"id\":\"752056471\",\"last_judgment_at\":\"2015-07-09T06:30:00Z\",\"lat\":\"45.47374371\",\"location\":\"-122.8361185 45.47374371\",\"long\":\"-122.8361185\",\"residential_yes\":\"yes\",\"residential_yes_confidence\":1,\"sidewalk_ok\":\"yes\",\"sidewalk_ok_confidence\":1,\"trusted_judgments\":1,\"unit_state\":\"finalized\",\"url\":\"http://maps.google.com/maps?cbll=45.473744,-122.836118\\u0026layer=c\"},{\"_root_\":\"752056576\",\"address\":\"5015 Southwest 114th Avenue, Miami, FL 33165, USA\",\"golden\":false,\"house_types\":\"private_house\",\"house_types_confidence\":1,\"id\":\"752056576\",\"last_judgment_at\":\"2015-07-09T06:58:00Z\",\"lat\":\"25.72032098\",\"location\":\"-80.37921526 25.72032098\",\"long\":\"-80.37921526\",\"residential_yes\":\"yes\",\"residential_yes_confidence\":1,\"sidewalk_ok\":\"yes\",\"sidewalk_ok_confidence\":1,\"trusted_judgments\":1,\"unit_state\":\"finalized\",\"url\":\"http://maps.google.com/maps?cbll=25.720321,-80.379215\\u0026layer=c\"},{\"_root_\":\"752056577\",\"address\":\"11171 Southwest 57th Terrace, Miami, FL 33173, USA\",\"golden\":false,\"house_types\":\"private_house\",\"house_types_confidence\":1,\"id\":\"752056577\",\"last_judgment_at\":\"2015-07-09T07:01:00Z\",\"lat\":\"25.71392911\",\"location\":\"-80.37413524 25.71392911\",\"long\":\"-80.37413524\",\"residential_yes\":\"yes\",\"residential_yes_confidence\":1,\"sidewalk_ok\":\"yes\",\"sidewalk_ok_confidence\":1,\"trusted_judgments\":1,\"unit_state\":\"finalized\",\"url\":\"http://maps.google.com/maps?cbll=25.713929,-80.374135\\u0026layer=c\"},{\"_root_\":\"752056579\",\"address\":\"11893 Southwest 56th Street, Miami, FL 33175, USA\",\"golden\":false,\"id\":\"752056579\",\"last_judgment_at\":\"2015-07-09T06:32:00Z\",\"lat\":\"25.71584582\",\"location\":\"-80.38476238 25.71584582\",\"long\":\"-80.38476238\",\"residential_yes\":\"no\",\"residential_yes_confidence\":1,\"trusted_judgments\":1,\"unit_state\":\"finalized\",\"url\":\"http://maps.google.com/maps?cbll=25.715846,-80.384762\\u0026layer=c\"},{\"_root_\":\"752056580\",\"address\":\"6025 Southwest 123rd Avenue, Miami, FL 33183, USA\",\"golden\":false,\"id\":\"752056580\",\"last_judgment_at\":\"2015-07-09T07:00:00Z\",\"lat\":\"25.71107741\",\"location\":\"-80.39184188 25.71107741\",\"long\":\"-80.39184188\",\"residential_yes\":\"not_avail\",\"residential_yes_confidence\":1,\"trusted_judgments\":1,\"unit_state\":\"finalized\",\"url\":\"http://maps.google.com/maps?cbll=25.711077,-80.391842\\u0026layer=c\"},{\"_root_\":\"752056581\",\"address\":\"5798 Southwest 123rd Avenue, Miami, FL 33183, USA\",\"golden\":false,\"id\":\"752056581\",\"last_judgment_at\":\"2015-07-09T07:01:00Z\",\"lat\":\"25.71304518\",\"location\":\"-80.39403149 25.71304518\",\"long\":\"-80.39403149\",\"residential_yes\":\"not_avail\",\"residential_yes_confidence\":1,\"trusted_judgments\":1,\"unit_state\":\"finalized\",\"url\":\"http://maps.google.com/maps?cbll=25.713045,-80.394031\\u0026layer=c\"},{\"_root_\":\"752056795\",\"address\":\"8865 Southwest 16th Street, Miami, FL 33165, USA\",\"golden\":false,\"id\":\"752056795\",\"last_judgment_at\":\"2015-07-09T07:06:00Z\",\"lat\":\"25.75562219\",\"location\":\"-80.34046094 25.75562219\",\"long\":\"-80.34046094\",\"residential_yes\":\"not_avail\",\"residential_yes_confidence\":1,\"trusted_judgments\":1,\"unit_state\":\"finalized\",\"url\":\"http://maps.google.com/maps?cbll=25.755622,-80.340461\\u0026layer=c\"},{\"_root_\":\"752056796\",\"address\":\"3199 Southwest 109th Court, Miami, FL 33165, USA\",\"golden\":false,\"house_types\":\"private_house\",\"house_types_confidence\":1,\"id\":\"752056796\",\"last_judgment_at\":\"2015-07-09T06:57:00Z\",\"lat\":\"25.73970622\",\"location\":\"-80.37254295 25.73970622\",\"long\":\"-80.37254295\",\"residential_yes\":\"yes\",\"residential_yes_confidence\":1,\"sidewalk_ok\":\"no\",\"sidewalk_ok_confidence\":1,\"trusted_judgments\":1,\"unit_state\":\"finalized\",\"url\":\"http://maps.google.com/maps?cbll=25.739706,-80.372543\\u0026layer=c\"},{\"_root_\":\"752056797\",\"address\":\"10210 Southwest 19th Street, Miami, FL 33165, USA\",\"golden\":false,\"house_types\":\"private_house\",\"house_types_confidence\":1,\"id\":\"752056797\",\"last_judgment_at\":\"2015-07-09T06:50:00Z\",\"lat\":\"25.75154644\",\"location\":\"-80.36041317 25.75154644\",\"long\":\"-80.36041317\",\"residential_yes\":\"yes\",\"residential_yes_confidence\":1,\"sidewalk_ok\":\"yes\",\"sidewalk_ok_confidence\":1,\"trusted_judgments\":1,\"unit_state\":\"finalized\",\"url\":\"http://maps.google.com/maps?cbll=25.751546,-80.360413\\u0026layer=c\"},{\"_root_\":\"752056798\",\"address\":\"3350 Southwest 129th Avenue, Miami, FL 33175, USA\",\"golden\":false,\"id\":\"752056798\",\"last_judgment_at\":\"2015-07-09T06:37:00Z\",\"lat\":\"25.73721927\",\"location\":\"-80.40445499 25.73721927\",\"long\":\"-80.40445499\",\"residential_yes\":\"not_avail\",\"residential_yes_confidence\":1,\"trusted_judgments\":1,\"unit_state\":\"finalized\",\"url\":\"http://maps.google.com/maps?cbll=25.737219,-80.404455\\u0026layer=c\"},{\"_root_\":\"752056799\",\"address\":\"3715 Southwest 121st Avenue, Miami, FL 33175, USA\",\"golden\":false,\"house_types\":\"private_house\",\"house_types_confidence\":1,\"id\":\"752056799\",\"last_judgment_at\":\"2015-07-09T06:59:00Z\",\"lat\":\"25.73423253\",\"location\":\"-80.39071936 25.73423253\",\"long\":\"-80.39071936\",\"residential_yes\":\"yes\",\"residential_yes_confidence\":1,\"sidewalk_ok\":\"yes\",\"sidewalk_ok_confidence\":1,\"trusted_judgments\":1,\"unit_state\":\"finalized\",\"url\":\"http://maps.google.com/maps?cbll=25.734233,-80.390719\\u0026layer=c\"},{\"_root_\":\"752055898\",\"address\":\"6181 Southwest 153rd Court Road, Miami, FL 33193, USA\",\"golden\":false,\"house_types\":\"private_house\",\"house_types_confidence\":1,\"id\":\"752055898\",\"last_judgment_at\":\"2015-07-09T06:32:00Z\",\"lat\":\"25.70988693\",\"location\":\"-80.44280531 25.70988693\",\"long\":\"-80.44280531\",\"residential_yes\":\"yes\",\"residential_yes_confidence\":1,\"sidewalk_ok\":\"yes\",\"sidewalk_ok_confidence\":1,\"trusted_judgments\":1,\"unit_state\":\"finalized\",\"url\":\"http://maps.google.com/maps?cbll=25.709887,-80.442805\\u0026layer=c\"},{\"_root_\":\"752055993\",\"address\":\"66-68 Southwest 47th Street, Miami, FL 33155, USA\",\"golden\":false,\"house_types\":\"private_house\",\"house_types_confidence\":1,\"id\":\"752055993\",\"last_judgment_at\":\"2015-07-09T07:17:00Z\",\"lat\":\"25.7726238\",\"location\":\"-80.27199793 25.7726238\",\"long\":\"-80.27199793\",\"residential_yes\":\"yes\",\"residential_yes_confidence\":1,\"sidewalk_ok\":\"yes\",\"sidewalk_ok_confidence\":1,\"trusted_judgments\":1,\"unit_state\":\"finalized\",\"url\":\"http://maps.google.com/maps?cbll=25.772624,-80.271998\\u0026layer=c\"},{\"_root_\":\"752056794\",\"address\":\"2685-2715 Southwest 109th Avenue, Miami, FL 33165, USA\",\"golden\":false,\"house_types\":\"private_house\",\"house_types_confidence\":1,\"id\":\"752056794\",\"last_judgment_at\":\"2015-07-09T07:00:00Z\",\"lat\":\"25.74418782\",\"location\":\"-80.37179383 25.74418782\",\"long\":\"-80.37179383\",\"residential_yes\":\"yes\",\"residential_yes_confidence\":1,\"sidewalk_ok\":\"Not sure, mixed\",\"sidewalk_ok_confidence\":1,\"trusted_judgments\":1,\"unit_state\":\"finalized\",\"url\":\"http://maps.google.com/maps?cbll=25.744188,-80.371794\\u0026layer=c\"},{\"_root_\":\"752056995\",\"address\":\"7350 Southwest 34th Street Road, Miami, FL 33155, USA\",\"golden\":false,\"house_types\":\"private_house\",\"house_types_confidence\":1,\"id\":\"752056995\",\"last_judgment_at\":\"2015-07-09T07:02:00Z\",\"lat\":\"25.7415286\",\"location\":\"-80.31475828 25.7415286\",\"long\":\"-80.31475828\",\"residential_yes\":\"yes\",\"residential_yes_confidence\":1,\"sidewalk_ok\":\"yes\",\"sidewalk_ok_confidence\":1,\"trusted_judgments\":1,\"unit_state\":\"finalized\",\"url\":\"http://maps.google.com/maps?cbll=25.741529,-80.314758\\u0026layer=c\"},{\"_root_\":\"752056996\",\"address\":\"7580-7598 Southwest 28th Street Road, Miami, FL 33155, USA\",\"golden\":false,\"house_types\":\"private_house\",\"house_types_confidence\":1,\"id\":\"752056996\",\"last_judgment_at\":\"2015-07-09T06:42:00Z\",\"lat\":\"25.74575446\",\"location\":\"-80.31899785 25.74575446\",\"long\":\"-80.31899785\",\"residential_yes\":\"yes\",\"residential_yes_confidence\":1,\"sidewalk_ok\":\"yes\",\"sidewalk_ok_confidence\":1,\"trusted_judgments\":1,\"unit_state\":\"finalized\",\"url\":\"http://maps.google.com/maps?cbll=25.745754,-80.318998\\u0026layer=c\"}],\"numFound\":38,\"numFoundExact\":true,\"start\":0},\"responseHeader\":{\"status\":0}}"

		So(string(updatedResBody), ShouldResemble, expectedResponse)
	})*/

	Convey("Solr: RS to Solr conversion", t, func() {
		False := false
		convertScript := "function handleRequest() { const queries = JSON.parse(context.request.body); var generatedURIs = {}; for (var key of Object.keys(queries)) { const queryEach = queries[key]; const generatedEach = {'original': JSON.parse(queryEach['_original']) }; delete queryEach['_original']; generatedURIs[key] = generatedEach; generatedEach['built'] = '?' + Object.keys(queryEach).reduce( function (a, k) { a.push(k + '=' + encodeURIComponent(queryEach[k])); return a }, []).join('&') } return { response: { body: JSON.stringify(generatedURIs), code: 200 } } }"
		script := "function handleRequest() { return { request: { body: JSON.stringify({'query': [{'id': 'test-before', 'value': 'Vegas', 'dataField': 'location_t', 'execute': false}, {'id': 'test-after', 'value': 'Las Vegas', 'dataField': 'location_t', 'execute': false}, { 'id': 'test', 'value': 'Las Vegas Nevada', 'queryFormat': 'AND', 'dataField': [{'field': 'summary_t', 'weight': 3}, {'field': 'location_t', 'weight': 2}], 'size': 12, 'from': 24, 'includeFields': ['summary_t', 'location_t'], 'sortBy': 'asc', 'execute': true, 'type': 'search', 'highlight': true, 'highlightConfig': {'fields': {'summary_t': {}}}, 'react': {'or': ['test-before', 'test-after']} }]}) } } }"
		convertId := "convert_validate"
		mockRequestId := "mock_request_body"

		stages := []ESPipelineStage{
			{
				ID:     &mockRequestId,
				Script: &script,
			},
			{
				Use:             &rsStage,
				Inputs:          &rsInputsAsString,
				ContinueOnError: &False,
			},
			{
				ID:              &convertId,
				Script:          &convertScript,
				ContinueOnError: &False,
			},
		}
		pipeline := ESPipelineDoc{
			Stages: &stages,
		}

		pipelineExecutionContext := PipelineExecutionContext{
			envs: make(map[string]interface{}),
			request: PipelineExecutionRequest{
				Body:    []byte(""),
				Headers: make(map[string]string),
			},
		}
		res, _ := pipeline.executePipeline(pipelineExecutionContext, nil, false, nil, false, false, false, nil)
		resInBytes, _ := json.Marshal(res)

		resMap := make(map[string]interface{})
		json.Unmarshal(resInBytes, &resMap)

		resBody := resMap["response"].(map[string]interface{})["body"].(string)

		expectedResponse := "{\"test\":{\"original\":{\"id\":\"test\",\"type\":\"search\",\"react\":{\"or\":[\"test-before\",\"test-after\"]},\"queryFormat\":\"AND\",\"dataField\":[{\"field\":\"summary_t\",\"weight\":3},{\"field\":\"location_t\",\"weight\":2}],\"from\":24,\"size\":12,\"sortBy\":\"asc\",\"value\":\"Las Vegas Nevada\",\"includeFields\":[\"summary_t\",\"location_t\"],\"highlight\":true,\"highlightConfig\":{\"fields\":{\"summary_t\":{}}},\"execute\":true},\"built\":\"?=&_index=&defType=edismax&fl=summary_t%2Clocation_t%2Cscore%2Cid&fq=(((location_t%3A%22Vegas*%22))%20OR%20((location_t%3A%22Las%20Vegas*%22)))&hl=true&hl.fl=summary_t&q=Las%20AND%20Vegas%20AND%20Nevada*&qf=summary_tsummary_t%5E3.000000%20location_tlocation_t%5E2.000000&rows=12&sort=summary_t%20asc%2C%20id%20asc&start=24\"}}"

		So(string(resBody), ShouldResemble, expectedResponse)
	})
}
