mirror of
https://github.com/kevin-DL/m3o-go.git
synced 2026-01-23 23:21:27 +00:00
Commit from m3o/m3o action
This commit is contained in:
103
search/search.go
103
search/search.go
@@ -5,7 +5,10 @@ import (
|
||||
)
|
||||
|
||||
type Search interface {
|
||||
Vote(*VoteRequest) (*VoteResponse, error)
|
||||
DeleteIndex(*DeleteIndexRequest) (*DeleteIndexResponse, error)
|
||||
Delete(*DeleteRequest) (*DeleteResponse, error)
|
||||
Index(*IndexRequest) (*IndexResponse, error)
|
||||
Search(*SearchRequest) (*SearchResponse, error)
|
||||
}
|
||||
|
||||
func NewSearchService(token string) *SearchService {
|
||||
@@ -20,20 +23,98 @@ type SearchService struct {
|
||||
client *client.Client
|
||||
}
|
||||
|
||||
// Vote to have the Search api launched faster!
|
||||
func (t *SearchService) Vote(request *VoteRequest) (*VoteResponse, error) {
|
||||
// Delete an index.
|
||||
func (t *SearchService) DeleteIndex(request *DeleteIndexRequest) (*DeleteIndexResponse, error) {
|
||||
|
||||
rsp := &VoteResponse{}
|
||||
return rsp, t.client.Call("search", "Vote", request, rsp)
|
||||
rsp := &DeleteIndexResponse{}
|
||||
return rsp, t.client.Call("search", "DeleteIndex", request, rsp)
|
||||
|
||||
}
|
||||
|
||||
type VoteRequest struct {
|
||||
// optional message
|
||||
Message string `json:"message"`
|
||||
// Delete a document given its ID
|
||||
func (t *SearchService) Delete(request *DeleteRequest) (*DeleteResponse, error) {
|
||||
|
||||
rsp := &DeleteResponse{}
|
||||
return rsp, t.client.Call("search", "Delete", request, rsp)
|
||||
|
||||
}
|
||||
|
||||
type VoteResponse struct {
|
||||
// response message
|
||||
Message string `json:"message"`
|
||||
// Index a document i.e. insert a document to search for.
|
||||
func (t *SearchService) Index(request *IndexRequest) (*IndexResponse, error) {
|
||||
|
||||
rsp := &IndexResponse{}
|
||||
return rsp, t.client.Call("search", "Index", request, rsp)
|
||||
|
||||
}
|
||||
|
||||
// Search for documents in a given in index
|
||||
func (t *SearchService) Search(request *SearchRequest) (*SearchResponse, error) {
|
||||
|
||||
rsp := &SearchResponse{}
|
||||
return rsp, t.client.Call("search", "Search", request, rsp)
|
||||
|
||||
}
|
||||
|
||||
type CreateIndexRequest struct {
|
||||
Fields []Field `json:"fields"`
|
||||
// the name of the index
|
||||
Index string `json:"index"`
|
||||
}
|
||||
|
||||
type CreateIndexResponse struct {
|
||||
}
|
||||
|
||||
type DeleteIndexRequest struct {
|
||||
// The name of the index to delete
|
||||
Index string `json:"index"`
|
||||
}
|
||||
|
||||
type DeleteIndexResponse struct {
|
||||
}
|
||||
|
||||
type DeleteRequest struct {
|
||||
// The ID of the document to delete
|
||||
Id string `json:"id"`
|
||||
// The index the document belongs to
|
||||
Index string `json:"index"`
|
||||
}
|
||||
|
||||
type DeleteResponse struct {
|
||||
}
|
||||
|
||||
type Document struct {
|
||||
// The JSON contents of the document
|
||||
Contents map[string]interface{} `json:"contents"`
|
||||
// The ID for this document. If blank, one will be generated
|
||||
Id string `json:"id"`
|
||||
}
|
||||
|
||||
type Field struct {
|
||||
// The name of the field. Use a `.` separator to define nested fields e.g. foo.bar
|
||||
Name string `json:"name"`
|
||||
// The type of the field - string, number
|
||||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
type IndexRequest struct {
|
||||
// The document to index
|
||||
Document *Document `json:"document"`
|
||||
// The index this document belongs to
|
||||
Index string `json:"index"`
|
||||
}
|
||||
|
||||
type IndexResponse struct {
|
||||
Id string `json:"id"`
|
||||
}
|
||||
|
||||
type SearchRequest struct {
|
||||
// The index the document belongs to
|
||||
Index string `json:"index"`
|
||||
// The query. See docs for query language examples
|
||||
Query string `json:"query"`
|
||||
}
|
||||
|
||||
type SearchResponse struct {
|
||||
// The matching documents
|
||||
Documents []Document `json:"documents"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user