forked from couchbase/gocb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GOCBC-184: Implemented new FTS Geo & TermRange queries and sorting.
Change-Id: I6ee13a1ee6cbd2450a32868d0d0c89507ee83731 Reviewed-on: http://review.couchbase.org/78072 Reviewed-by: Mike Goldsmith <goldsmith.mike@gmail.com> Tested-by: Brett Lawson <brett19@gmail.com>
- Loading branch information
Showing
3 changed files
with
211 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
package cbft | ||
|
||
import ( | ||
"encoding/json" | ||
) | ||
|
||
// *VOLATILE* | ||
// FtsQuery represents an FTS query for a search query. | ||
type FtsSort interface { | ||
} | ||
|
||
type ftsSortBase struct { | ||
options map[string]interface{} | ||
} | ||
|
||
func newFtsSortBase() ftsSortBase { | ||
return ftsSortBase{ | ||
options: make(map[string]interface{}), | ||
} | ||
} | ||
|
||
// MarshalJSON marshal's this query to JSON for the FTS REST API. | ||
func (q ftsSortBase) MarshalJSON() ([]byte, error) { | ||
return json.Marshal(q.options) | ||
} | ||
|
||
// SearchSortScore represents a FTS score sort. | ||
type SearchSortScore struct { | ||
ftsSortBase | ||
} | ||
|
||
// NewSearchSortScore creates a new SearchSortScore. | ||
func NewSearchSortScore() *SearchSortScore { | ||
q := &SearchSortScore{newFtsSortBase()} | ||
q.options["by"] = "score" | ||
return q | ||
} | ||
|
||
// Descending specifies the ordering of the results. | ||
func (q *SearchSortScore) Descending(descending bool) *SearchSortScore { | ||
q.options["descending"] = descending | ||
return q | ||
} | ||
|
||
// SearchSortScore represents a FTS Document ID sort. | ||
type SearchSortId struct { | ||
ftsSortBase | ||
} | ||
|
||
// NewSearchSortScore creates a new SearchSortScore. | ||
func NewSearchSortId() *SearchSortId { | ||
q := &SearchSortId{newFtsSortBase()} | ||
q.options["by"] = "id" | ||
return q | ||
} | ||
|
||
// Descending specifies the ordering of the results. | ||
func (q *SearchSortId) Descending(descending bool) *SearchSortId { | ||
q.options["descending"] = descending | ||
return q | ||
} | ||
|
||
// SearchSortField represents a FTS field sort. | ||
type SearchSortField struct { | ||
ftsSortBase | ||
} | ||
|
||
// NewSearchSortField creates a new SearchSortField. | ||
func NewSearchSortField(field string) *SearchSortField { | ||
q := &SearchSortField{newFtsSortBase()} | ||
q.options["by"] = "field" | ||
q.options["field"] = field | ||
return q | ||
} | ||
|
||
func (q *SearchSortField) Type(value string) *SearchSortField { | ||
q.options["type"] = value | ||
return q | ||
} | ||
|
||
func (q *SearchSortField) Mode(mode string) *SearchSortField { | ||
q.options["mode"] = mode | ||
return q | ||
} | ||
|
||
func (q *SearchSortField) Missing(missing string) *SearchSortField { | ||
q.options["missing"] = missing | ||
return q | ||
} | ||
|
||
// Descending specifies the ordering of the results. | ||
func (q *SearchSortField) Descending(descending bool) *SearchSortField { | ||
q.options["descending"] = descending | ||
return q | ||
} | ||
|
||
// SearchSortGeoDistance represents a FTS geo sort. | ||
type SearchSortGeoDistance struct { | ||
ftsSortBase | ||
} | ||
|
||
// NewSearchSortGeoDistance creates a new SearchSortGeoDistance. | ||
func NewSearchSortGeoDistance(field string, lat, lon float64) *SearchSortGeoDistance { | ||
q := &SearchSortGeoDistance{newFtsSortBase()} | ||
q.options["by"] = "geo_distance" | ||
q.options["field"] = field | ||
q.options["location"] = []float64{lon, lat} | ||
return q | ||
} | ||
|
||
// Unit specifies the unit used for sorting | ||
func (q *SearchSortGeoDistance) Unit(unit string) *SearchSortGeoDistance { | ||
q.options["unit"] = unit | ||
return q | ||
} | ||
|
||
// Descending specifies the ordering of the results. | ||
func (q *SearchSortGeoDistance) Descending(descending bool) *SearchSortGeoDistance { | ||
q.options["descending"] = descending | ||
return q | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters