Skip to content
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
48 changes: 48 additions & 0 deletions solr/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,3 +269,51 @@ func (parser *MoreLikeThisParser) Parse(resp_ *[]byte) (*SolrMltResult, error) {
}
return sr, nil
}

type AnyResultParser interface {
Parse(*[]byte) (*SolrAnyResult, error)
}

type AnyParser struct {
}

func (parser *AnyParser) Parse(resp_ *[]byte) (*SolrAnyResult, error) {
jsonbuf, err := bytes2json(resp_)
sr := &SolrAnyResult{}
if err != nil {
return sr, nil
}
var resp = new(SolrResponse)
resp.Response = jsonbuf
resp.Status = int(jsonbuf["responseHeader"].(map[string]interface{})["status"].(float64))

sr.Results = new(Collection)
sr.Status = resp.Status
sr.Payload = make(map[string]interface{})

if responseHeader, ok := resp.Response["responseHeader"].(map[string]interface{}); ok {
sr.ResponseHeader = responseHeader
}

if resp.Status != 0 {
if err, ok := resp.Response["error"].(map[string]interface{}); ok {
sr.Error = err
}
return sr, err
}

for k, r := range resp.Response {
switch k {
case "response":
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we think that we still have some kind of response that is corresponding to collection. My thought is that we should skip this and put everything i Payload. We do very generic stuff here and let application go for specific parsing

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look like suggester didn't have response?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we think that we still have some kind of response that is corresponding to collection. My thought is that we should skip this and put everything i Payload. We do very generic stuff here and let application go for specific parsing

Since it is still part of Solr responds then it be parsed using the same methods in the library. Only if it is new response then it is left up to the developer to parse it.

Look like suggester didn't have response?

No the suggest response would look something like this:

{
   "responseHeader":{
      "status":0,
      "QTime":2
   },
   "suggest":{
      "suggester":{
         "keyword":{
            "numFound":0,
            "suggestions":[

            ]
         }
      }
   }
}

Copy link
Copy Markdown
Owner

@vanng822 vanng822 Feb 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And you're sure that response always contains documents response, ie

"response":{"numFound":1,"start":0,"maxScore":2.3025851,"docs":[ {...}]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly yes unless Solr change their response scheme

if resp, ok := r.(map[string]interface{}); ok {
ParseDocResponse(resp, sr.Results)
}
case "responseHeader":
continue
default:
sr.Payload[k] = r
}
}

return sr, nil
}
12 changes: 12 additions & 0 deletions solr/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,15 @@ func (s *Search) SpellCheck(parser ResultParser) (*SolrResult, error) {
}
return parser.Parse(resp)
}

// This method is for making query to user-specific or any request handler endpoint
func (s *Search) Any(endpoint string, parser AnyResultParser) (*SolrAnyResult, error) {
resp, err := s.Resource(endpoint, s.QueryParams())
if err != nil {
return nil, err
}
if parser == nil {
parser = new(AnyParser)
}
return parser.Parse(resp)
}
13 changes: 11 additions & 2 deletions solr/solr.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type FireworkCollection struct {

// Parsed result for SearchHandler response, ie /select
type FireworkSolrResult struct {
Status int // status quick access to status
Status int // status quick access to status
Results FireworkCollection `json:"response"` // results parsed documents, basically response object
QTime int
Params map[string]string `json:"params"`
Expand All @@ -62,7 +62,7 @@ type FireworkSolrResult struct {
Grouped map[string]interface{} // grouped for grouping result if grouping Results will be empty
Stats map[string]interface{}
MoreLikeThis map[string]interface{} // MoreLikeThis using Search (select) Component
NextCursorMark string `json:"nextCursorMark"`
NextCursorMark string `json:"nextCursorMark"`
}

// Holding the search result
Expand Down Expand Up @@ -99,6 +99,15 @@ type SolrMltResult struct {
Error map[string]interface{}
}

// Parsed result for any response that is not already handled
type SolrAnyResult struct {
Status int // status quick access to status
Results *Collection // results parsed documents, basically response object
ResponseHeader map[string]interface{}
Error map[string]interface{}
Payload map[string]interface{}
}

type SolrInterface struct {
conn *Connection
}
Expand Down