Skip to content

Commit

Permalink
Merge pull request #46 from mathewvp/master
Browse files Browse the repository at this point in the history
Add facet query option
  • Loading branch information
vanng822 authored Aug 1, 2018
2 parents a032067 + 6b8f222 commit 537618f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
7 changes: 7 additions & 0 deletions solr/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ func (q *Query) AddFacet(f string) {
q.params.Add("facet.field", f)
}

// fq (FacetQuery) https://wiki.apache.org/solr/SimpleFacetParameters#facet.query_:_Arbitrary_Query_Faceting
// Example: price:[* TO 500]
func (q *Query) AddFacetQuery(fq string) {
q.params.Set("facet", "true")
q.params.Add("facet.query", fq)
}

// mc (Facet min count) https://cwiki.apache.org/confluence/display/solr/Faceting#Faceting-Thefacet.mincountParameter
// Example: 5
func (q *Query) SetFacetMinCount(mc int) {
Expand Down
11 changes: 11 additions & 0 deletions solr/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,17 @@ func TestSolrQueryAddFacet(t *testing.T) {
}
}

func TestSolrQueryAddFacetQuery(t *testing.T) {
q := NewQuery()
q.AddFacetQuery("price:[* TO 500]")
q.AddFacetQuery("price:[501 TO *]")
expected := "facet=true&facet.query=price%3A%5B%2A+TO+500%5D&facet.query=price%3A%5B501+TO+%2A%5D"
result := q.String()
if result != expected {
t.Errorf("expected '%s' but got '%s'", expected, result)
}
}

func TestSolrQuerySetFacetMinCount(t *testing.T) {
q := NewQuery()
q.SetFacetMinCount(10)
Expand Down

5 comments on commit 537618f

@mathewvp
Copy link

Choose a reason for hiding this comment

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

Hi,
This commit is not in the latest release? When doing a dep init, it pulls version 0.5.0 which does not have this code

@vanng822
Copy link
Owner Author

@vanng822 vanng822 commented on 537618f Sep 17, 2018

Choose a reason for hiding this comment

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

Hi @mathewvp I haven't created release branch for a while. I was thinking it is no longer needed. Not sure how dep works. Does it select a release branch by default? I create a new one and see if it works better

@mathewvp
Copy link

Choose a reason for hiding this comment

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

dep pulls the latest release unless you specify the release version which is 0.5.0 which does not have the above code.

@vanng822
Copy link
Owner Author

Choose a reason for hiding this comment

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

I created a new branch from master now. Try it out and notify me, thanks

@mathewvp
Copy link

Choose a reason for hiding this comment

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

dep is completely broken for me, may be I am doing something wrong. For the time being, I am using

revision = "537618faa3444670161401adf81eff7e0d44dafa" to pull the commit.

Please sign in to comment.