func SelectResponseFromHTTPResponse(b []byte) (*SelectResponse, error) {
	j, err := BytesToJSON(&b)
	if err != nil {
		return nil, err
	}
	resp, err := BuildResponse(j)
	if err != nil {
		return nil, err
	}
	return resp, nil
}
/*
Decodes a HTTP (Solr) response and returns a Response
package solr
import (
	"bytes"
	"encoding/json"
	"fmt"
	"io/ioutil"
	"net/http"
	"net/url"
	"strings"
)
type Connection struct {
	URL     string
	Version []int
}
type Document struct {
	Fields map[string]interface{}
}
type FacetCount struct {
	Value string
	Count int
}
var facet_chunk_size int = 2
type Facet struct {
	Name   string        
	Counts []FacetCount  
}
type DocumentCollection struct {
	Facets     []Facet
	Collection []Document
	NumFacets  int  
	NumFound   int
	Start      int
}
type SelectResponse struct {
	Results *DocumentCollection
	Status  int
	QTime   int
}
type ErrorResponse struct {
	Message string
	Status  int
}
type UpdateResponse struct {
	Success bool
}
type URLParamMap map[string][]string
type Query struct {
	Params     URLParamMap
	Rows       int
	Start      int
	Sort       string
	DefType    string
	Debug      bool
	OmitHeader bool
}
func (q *Query) String() string {
	s := []string{}
	if len(q.Params) > 0 {
		s = append(s, EncodeURLParamMap(&q.Params))
	}
	if q.Rows != 0 {
		s = append(s, fmt.Sprintf("rows=%d", q.Rows))
	}
	if q.Start != 0 {
		s = append(s, fmt.Sprintf("start=%d", q.Start))
	}
	if q.Sort != "" {
		s = append(s, fmt.Sprintf("sort=%s", q.Sort))
	}
	if q.DefType != "" {
		s = append(s, fmt.Sprintf("defType=%s", q.DefType))
	}
	if q.Debug {
		s = append(s, fmt.Sprintf("debugQuery=true"))
	}
	if q.OmitHeader {
		s = append(s, fmt.Sprintf("omitHeader=true"))
	}
	return strings.Join(s, "&")
}
func (d *DocumentCollection) Get(i int) *Document {
	return &d.Collection[i]
}
func (d *DocumentCollection) Len() int {
	return len(d.Collection)
}
func (document Document) Field(field string) interface{} {
	r, _ := document.Fields[field]
	return r
}
func (document Document) Doc() map[string]interface{} {
	return document.Fields
}
func (r SelectResponse) String() string {
	return fmt.Sprintf("SelectResponse: %d Results, Status: %d, QTime: %d", r.Results.Len(), r.Status, r.QTime)
}
func (r ErrorResponse) String() string {
	return fmt.Sprintf("Solr Error: [code: %d, msg: \"%s\"]", r.Status, r.Message)
}
func (r UpdateResponse) String() string {
	if r.Success {
		return fmt.Sprintf("UpdateResponse: OK")
	}
	return fmt.Sprintf("UpdateResponse: FAIL")
}
func HTTPGet(httpUrl string) ([]byte, error) {
	r, err := http.Get(httpUrl)
	if err != nil {
		return nil, err
	}
	defer r.Body.Close()
	if err != nil {
		return nil, err
	}
	body, err := ioutil.ReadAll(r.Body)
	if err != nil {
		return nil, err
	}
	return body, nil
}
func HTTPPost(url string, headers [][]string, payload *[]byte) ([]byte, error) {
	client := &http.Client{}
	req, err := http.NewRequest("POST", url, bytes.NewReader(*payload))
	if len(headers) > 0 {
		for i := range headers {
			req.Header.Add(headers[i][0], headers[i][1])
		}
	}
	resp, err := client.Do(req)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()
	if err != nil {
		return nil, err
	}
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return nil, err
	}
	return body, nil
}
func EncodeURLParamMap(m *URLParamMap) string {
	parameters := url.Values{}
	for k, v := range *m {
		l := len(v)
		for x := 0; x < l; x++ {
			parameters.Add(k, v[x])
		}
	}
	qEncoded := parameters.Encode()
	return string(qEncoded)
}
func SolrSelectString(c *Connection, q string, handlerName string) string {
	return fmt.Sprintf("%s/%s?wt=json&%s", c.URL, handlerName, q)
}
func SolrUpdateString(c *Connection, commit bool) string {
	s := fmt.Sprintf("%s/update", c.URL)
	if commit {
		return fmt.Sprintf("%s?commit=true", s)
	}
	return s
}
func BytesToJSON(b *[]byte) (*interface{}, error) {
	var container interface{}
	err := json.Unmarshal(*b, &container)
	if err != nil {
		return nil, err
	}
	return &container, nil
}
func JSONToBytes(m map[string]interface{}) (*[]byte, error) {
	b, err := json.Marshal(m)
	if err != nil {
		return nil, err
	}
	return &b, nil
}
func BuildResponse(j *interface{}) (*SelectResponse, error) {
	response_root := (*j).(map[string]interface{})
	response := response_root["response"]
	if response == nil {
		return nil, fmt.Errorf("Supplied interface appears invalid (missing response)")
	}
	r := SelectResponse{}
	r_header := (*j).(map[string]interface{})["responseHeader"].(map[string]interface{})
	if r_header != nil {
		r.Status = int(r_header["status"].(float64))
		r.QTime = int(r_header["QTime"].(float64))
	}
	docs := response.(map[string]interface{})["docs"].([]interface{})
	if docs != nil {
		num_found := int(response.(map[string]interface{})["numFound"].(float64))
		num_results := len(docs)
		coll := DocumentCollection{}
		coll.NumFound = num_found
		ds := []Document{}
		for i := 0; i < num_results; i++ {
			ds = append(ds, Document{docs[i].(map[string]interface{})})
		}
		coll.Collection = ds
		r.Results = &coll
	}
	facet_response, ok := response_root["facet_counts"].(interface{})
	if ok == true {
		facet_counts := facet_response.(map[string]interface{})
		if facet_counts != nil {
			facet_fields := facet_counts["facet_fields"].(map[string]interface{})
			facets := []Facet{}
			if facet_fields != nil {
				for k, v := range facet_fields {
					f := Facet{Name: k}
					chunked := chunk(v.([]interface{}), facet_chunk_size)
					lc := len(chunked)
					for i := 0; i < lc; i++ {
						f.Counts = append(f.Counts, FacetCount{
							Value: chunked[i][0].(string),
							Count: int(chunked[i][1].(float64)),
						})
					}
					facets = append(facets, f)
				}
			}
			r.Results.Facets = facets
			r.Results.NumFacets = len(facets)
		}
	}
	return &r, nil
}