Skip to content

Commit

Permalink
fix: Add missing types for facetFilters
Browse files Browse the repository at this point in the history
Thanks to one customer report, we discovered that the documentation was
wrong regarding the way to set the `facetFilters` parameter. This commit
adds the support for other types (namely `[][]string` and
`[]interface{}`), so that all the following calls are now legit in Go:

```
// category:Book
"facetFilters": "category:Book"

// category:Book AND author:J.K. Rowling
"facetFilters": []string{
	"category:Book",
	"author:J.K. Rowling",
}

// (category:Book OR category:Movie) AND (author:J.K. Rowling OR author:Stephen King)
"facetFilters": [][]string{
	[]string{"category:Book", "category:Movie"},
	[]string{"author:J.K. Rowling", "author:Stephen King"},
}

// (category:Book OR category:Movie) AND author:J.K. Rowling
"facetFilters": []interface{}{
	[]string{"category:Book", "category:Movie"},
	"author:J.K. Rowling",
}
```

Related to https://github.com/algolia/doc/pull/1760.
  • Loading branch information
aseure committed Sep 28, 2018
1 parent b76d198 commit f71d328
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
9 changes: 8 additions & 1 deletion algoliasearch/check_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,17 @@ Outer:
return invalidType(k, "string or []interface{}")
}

case "facetFilters":
switch v.(type) {
case string, []string, [][]string, []interface{}:
//OK
default:
return invalidType(k, "string, []string, [][]string or []interface{}")
}

case "analyticsTags",
"restrictSearchableAttributes",
"facets",
"facetFilters",
"optionalWords":
switch v.(type) {
case string, []string:
Expand Down
18 changes: 18 additions & 0 deletions algoliasearch/check_query_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package algoliasearch

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestCheckQuery(t *testing.T) {
for _, m := range []Map{
Map{"facetFilters": "filter"},
Map{"facetFilters": []string{"f1", "f2"}},
Map{"facetFilters": [][]string{[]string{"f1", "f2"}, []string{"f3"}}},
Map{"facetFilters": []interface{}{[]string{"f1", "f2"}, "f3"}},
} {
require.NoError(t, checkQuery(m), "should accept the following query parameter: %#v", m)
}
}

0 comments on commit f71d328

Please sign in to comment.