Skip to content

Commit

Permalink
GOCBC-661: Moved Search building helpers to a sub-package.
Browse files Browse the repository at this point in the history
Change-Id: I60c7c6d8344c191cf18b8ac62800fa3d76eff735
  • Loading branch information
brett19 committed Jan 17, 2020
1 parent 450e1d3 commit 082bdc6
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 22 deletions.
3 changes: 2 additions & 1 deletion cluster_searchquery.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"time"

cbsearch "github.com/couchbase/gocb/v2/search"
gocbcore "github.com/couchbase/gocbcore/v8"
)

Expand Down Expand Up @@ -253,7 +254,7 @@ func (r *SearchResult) Facets() (map[string]SearchFacetResult, error) {
}

// SearchQuery executes the analytics query statement on the server.
func (c *Cluster) SearchQuery(indexName string, query SearchQuery, opts *SearchOptions) (*SearchResult, error) {
func (c *Cluster) SearchQuery(indexName string, query cbsearch.Query, opts *SearchOptions) (*SearchResult, error) {
if opts == nil {
opts = &SearchOptions{}
}
Expand Down
6 changes: 3 additions & 3 deletions searchquery_facet.go → search/facets.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package gocb
package search

import (
"encoding/json"
)

// SearchFacet represents a facet for a search query.
type SearchFacet interface {
// Facet represents a facet for a search query.
type Facet interface {
}

type termFacetData struct {
Expand Down
28 changes: 14 additions & 14 deletions searchquery.go → search/queries.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package gocb
package search

import "encoding/json"

// SearchQuery represents a search query.
type SearchQuery interface {
// Query represents a search query.
type Query interface {
}

type searchQueryBase struct {
Expand Down Expand Up @@ -221,15 +221,15 @@ type ConjunctionQuery struct {
}

// NewConjunctionQuery creates a new ConjunctionQuery.
func NewConjunctionQuery(queries ...SearchQuery) *ConjunctionQuery {
func NewConjunctionQuery(queries ...Query) *ConjunctionQuery {
q := &ConjunctionQuery{newSearchQueryBase()}
q.options["conjuncts"] = []SearchQuery{}
q.options["conjuncts"] = []Query{}
return q.And(queries...)
}

// And adds new predicate queries to this conjunction query.
func (q *ConjunctionQuery) And(queries ...SearchQuery) *ConjunctionQuery {
q.options["conjuncts"] = append(q.options["conjuncts"].([]SearchQuery), queries...)
func (q *ConjunctionQuery) And(queries ...Query) *ConjunctionQuery {
q.options["conjuncts"] = append(q.options["conjuncts"].([]Query), queries...)
return q
}

Expand All @@ -245,15 +245,15 @@ type DisjunctionQuery struct {
}

// NewDisjunctionQuery creates a new DisjunctionQuery.
func NewDisjunctionQuery(queries ...SearchQuery) *DisjunctionQuery {
func NewDisjunctionQuery(queries ...Query) *DisjunctionQuery {
q := &DisjunctionQuery{newSearchQueryBase()}
q.options["disjuncts"] = []SearchQuery{}
q.options["disjuncts"] = []Query{}
return q.Or(queries...)
}

// Or adds new predicate queries to this disjunction query.
func (q *DisjunctionQuery) Or(queries ...SearchQuery) *DisjunctionQuery {
q.options["disjuncts"] = append(q.options["disjuncts"].([]SearchQuery), queries...)
func (q *DisjunctionQuery) Or(queries ...Query) *DisjunctionQuery {
q.options["disjuncts"] = append(q.options["disjuncts"].([]Query), queries...)
return q
}

Expand Down Expand Up @@ -283,7 +283,7 @@ func NewBooleanQuery() *BooleanQuery {
}

// Must specifies a query which must match.
func (q *BooleanQuery) Must(query SearchQuery) *BooleanQuery {
func (q *BooleanQuery) Must(query Query) *BooleanQuery {
switch val := query.(type) {
case ConjunctionQuery:
q.data.Must = &val
Expand All @@ -296,7 +296,7 @@ func (q *BooleanQuery) Must(query SearchQuery) *BooleanQuery {
}

// Should specifies a query which should match.
func (q *BooleanQuery) Should(query SearchQuery) *BooleanQuery {
func (q *BooleanQuery) Should(query Query) *BooleanQuery {
switch val := query.(type) {
case DisjunctionQuery:
q.data.Should = &val
Expand All @@ -309,7 +309,7 @@ func (q *BooleanQuery) Should(query SearchQuery) *BooleanQuery {
}

// MustNot specifies a query which must not match.
func (q *BooleanQuery) MustNot(query SearchQuery) *BooleanQuery {
func (q *BooleanQuery) MustNot(query Query) *BooleanQuery {
switch val := query.(type) {
case DisjunctionQuery:
q.data.MustNot = &val
Expand Down
4 changes: 2 additions & 2 deletions searchquery_sorting.go → search/sorting.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package gocb
package search

import (
"encoding/json"
)

// SearchSort represents an search sorting for a search query.
type SearchSort interface {
type Sort interface {
}

type searchSortBase struct {
Expand Down
6 changes: 4 additions & 2 deletions searchquery_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package gocb

import (
"time"

cbsearch "github.com/couchbase/gocb/v2/search"
)

// SearchHighlightStyle indicates the type of highlighting to use for a search query.
Expand Down Expand Up @@ -42,8 +44,8 @@ type SearchOptions struct {
Explain bool
Highlight *SearchHighlightOptions
Fields []string
Sort []interface{}
Facets map[string]interface{}
Sort []cbsearch.Sort
Facets map[string]cbsearch.Facet
ConsistentWith *MutationState
Raw map[string]interface{}

Expand Down

0 comments on commit 082bdc6

Please sign in to comment.