Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding JSON Facet support #60

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

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