// Converts the ElasticSearch raw JSON response into a SearchResult slice,
// ready for use in the HTML Template Engine.
Converts the ElasticSearch raw JSON response into a SearchResult slice,
ready for use in the HTML Template Engine.
// Converts the ElasticSearch raw JSON response into a SearchResult slice // ready for use in the HTML Template Engine .
func parseQueryResponse(res *esapi.Response) ([]SearchResult, error) {
	var r map[string]interface{}
	if err := json.NewDecoder(res.Body).Decode(&r); err != nil {
		return nil, fmt.Errorf("Error parsing the response body: %s", err)
	}
	var results []SearchResult
	for _, hit := range r["hits"].(map[string]interface{})["hits"].([]interface{}) {
		fName := hit.(map[string]interface{})["_source"].(map[string]interface{})["name"].(string)
		var fTags []string
		for _, val := range hit.(map[string]interface{})["_source"].(map[string]interface{})["tags"].([]interface{}) {
			fTags = append(fTags, val.(string))
		}
		fScore := hit.(map[string]interface{})["_score"].(float64)
		results = append(results, SearchResult{
			FileName: fName,
			FileTags: fTags,
			Score: fScore,
		})
	}
	return results, nil
}
func parseQueryResponse ( res * esapi . Response ) ( [ ] SearchResult , error ) { var r map [ string ] interface { } if err := json . NewDecoder ( res . Body ) . Decode ( & r ) ; err != nil { return nil , fmt . Errorf ( " " , err ) } var results [ ] SearchResult for _ , hit := range r [ " " ] . ( map [ string ] interface { } ) [ " " ] . ( [ ] interface { } ) { fName := hit . ( map [ string ] interface { } ) [ " " ] . ( map [ string ] interface { } ) [ " " ] . ( string ) var fTags [ ] string for _ , val := range hit . ( map [ string ] interface { } ) [ " " ] . ( map [ string ] interface { } ) [ " " ] . ( [ ] interface { } ) { fTags = append ( fTags , val . ( string ) ) } fScore := hit . ( map [ string ] interface { } ) [ " " ] . ( float64 ) results = append ( results , SearchResult { FileName : fName , FileTags : fTags , Score : fScore , } ) } return results , nil }
Converts the ElasticSearch raw JSON response into a SearchResult slice,
ready for use in the HTML Template Engine.
Converts the ElasticSearch raw JSON response into a SearchResult slice ready for use in the HTML Template Engine .
// Save the name and tags for each hit.