Skip to content

Conversation

M-Anwar
Copy link

@M-Anwar M-Anwar commented Apr 26, 2019

This PR adds barebones support for Solr's JSON faceting API. This should help address the issue raised in #55.

The main addition in this PR is including a Facets map[string]interface{} `json:"facets"` to the SolrResponse structure. Along with a few helper methods/types in solrHTTP.go

Example usage is documented in the added unit tests, but also documented below for clarity:

query := []func(url.Values){
    solr.Query("*:*"),
    solr.JSONFacet(
	solr.M{
	    "max_salary": "max(salary)",
	    "salary": solr.M{
		"type":  "terms",
		"field": "salary",
	    },
        },
    ),
}

r, err := solrHttp.Select(replicas, query...)

r.Facets will have the following response structure:

Facets: 
map[
    salary:map[
        buckets:[
            map[val:40000 count:20] 
            map[val:60000 count:20] 
            map[val:80000 count:20] 
            map[val:100000 count:20] 
            map[count:20 val:120000]]] 
    count:100 
    max_salary:120000
]

Because this PR adds barebones support for faceting, additional manipulation of the Solr Facet response is left to the user (i.e conversion to a struct using https://github.com/mitchellh/mapstructure etc).

All features of the Solr JSON Faceting API are supported in this PR (Terms, Query, Range, Heatmap, Metric/Aggregations, Nested, Sorting, Domain (filter, block-join, traversal) )

@M-Anwar M-Anwar mentioned this pull request Apr 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant