Skip to content
This repository was archived by the owner on Feb 20, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 48 additions & 1 deletion solr.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,28 @@ type Query struct {
OmitHeader bool
}

/*
* Response Health Check Solr
*/
type ResponseHealth struct {
ResponseHeader struct {
QTime int
Params struct {
Df string
Distrib string
EchoParams string
Facet_method string
Facet_mincount string
Q string
Rows string
Version string
Wt string
}
Status int
}
Status string
}

/*
* Query.String() returns the Query in solr query string format
*/
Expand Down Expand Up @@ -280,7 +302,10 @@ func EncodeURLParamMap(m *URLParamMap) string {
* Generates a Solr query string from a connection, query string and handler name
*/
func SolrSelectString(c *Connection, q string, handlerName string) string {
return fmt.Sprintf("%s/%s?wt=json&%s", c.URL, handlerName, q)
if q != "" {
return fmt.Sprintf("%s/%s?wt=json&%s", c.URL, handlerName, q)
}
return fmt.Sprintf("%s/%s?wt=json", c.URL, handlerName)
}

/*
Expand Down Expand Up @@ -507,6 +532,28 @@ func (c *Connection) SelectRaw(q string) (*SelectResponse, error) {
return resp, err
}

/*
* Performs health check
*/
func (c *Connection) HealthCheck() (bool, error) {
body, err := HTTPGet(SolrSelectString(c, "", "admin/ping"))
if err != nil {
return false, err
}

resp := ResponseHealth{}

err = json.Unmarshal(body, &resp)
if err != nil {
return false, err
}

if resp.Status == "OK" {
return true, nil
}
return false, nil
}

/*
* Performs a raw Select query given a raw query string and handlerName
*/
Expand Down
4 changes: 4 additions & 0 deletions solr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ func TestSolrSelectString(t *testing.T) {
t.Fail()
}

s2 := SolrSelectString(c, "", "admin/ping")
if s2 != "http://localhost:8696/solr/core0/admin/ping?wt=json" {
t.Fail()
}
}

func TestSolrUpdateString(t *testing.T) {
Expand Down