search

package
v0.0.0-...-e9d0818 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 20, 2014 License: Apache-2.0 Imports: 8 Imported by: 0

README


To run tests on this, you must first have run/imported data inside of *core*

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BoolClause

type BoolClause string

A bool (and/or) clause

type FacetDsl

type FacetDsl struct {
	Terms map[string]*Term `json:"terms,omitempty"`
	// contains filtered or unexported fields
}

func Facet

func Facet() *FacetDsl
"facets": {
    "terms": {
		"terms": {
			"field": [
			  "@fields.category"
			],
			"size": 25
		}
    }
}
"facets": {
  "actors": { "terms": {"field": ["actor"],"size": "10" }}
  , "langauge": { "terms": {"field": ["repository.language"],"size": "10" }}
}

func (*FacetDsl) Fields

func (m *FacetDsl) Fields(fields ...string) *FacetDsl

func (*FacetDsl) MarshalJSON

func (m *FacetDsl) MarshalJSON() ([]byte, error)

func (*FacetDsl) Regex

func (m *FacetDsl) Regex(field, match string) *FacetDsl

func (*FacetDsl) Size

func (m *FacetDsl) Size(size string) *FacetDsl

type FilterClause

type FilterClause interface {
	String() string
}

Filter clause is either a boolClause or FilterOp

type FilterOp

type FilterOp struct {
	TermsMap    map[string][]interface{}     `json:"terms,omitempty"`
	Range       map[string]map[string]string `json:"range,omitempty"`
	Exist       map[string]string            `json:"exists,omitempty"`
	MisssingVal map[string]string            `json:"missing,omitempty"`
	// contains filtered or unexported fields
}

func Filter

func Filter() *FilterOp

Filter Operation

Filter().Term("user","kimchy")

// we use variadics to allow n arguments, first is the "field" rest are values
Filter().Terms("user", "kimchy", "elasticsearch")

Filter().Exists("repository.name")

func Range

func Range() *FilterOp

A range is a special type of Filter operation

Range().Exists("repository.name")

func (*FilterOp) Add

func (f *FilterOp) Add(fop *FilterOp) *FilterOp

Add another Filterop, "combines" two filter ops into one

func (*FilterOp) Exists

func (f *FilterOp) Exists(name string) *FilterOp

func (*FilterOp) Field

func (f *FilterOp) Field(fld string) *FilterOp

func (*FilterOp) From

func (f *FilterOp) From(from string) *FilterOp

func (*FilterOp) Missing

func (f *FilterOp) Missing(name string) *FilterOp

func (*FilterOp) Terms

func (f *FilterOp) Terms(field string, values ...interface{}) *FilterOp

Filter Terms

Filter().Terms("user","kimchy")

// we use variadics to allow n arguments, first is the "field" rest are values
Filter().Terms("user", "kimchy", "elasticsearch")

func (*FilterOp) To

func (f *FilterOp) To(to string) *FilterOp

type FilterWrap

type FilterWrap struct {
	// contains filtered or unexported fields
}

A wrapper to allow for custom serialization

func NewFilterWrap

func NewFilterWrap() *FilterWrap

func (*FilterWrap) MarshalJSON

func (f *FilterWrap) MarshalJSON() ([]byte, error)

Custom marshalling to support the query dsl

func (*FilterWrap) String

func (f *FilterWrap) String() string

type MatchAll

type MatchAll struct {
	All string `json:"-"`
}

type QueryDsl

type QueryDsl struct {
	QueryEmbed
	FilterVal *FilterOp `json:"filter,omitempty"`
}

some ways to serialize

"query": {
	"filtered": {
	  "query": {
	    "query_string": {
	      "default_operator": "OR",
	      "default_field": "_all",
	      "query": " actor:\"bob\"  AND type:\"EventType\""
	    }
	  },
	  "filter": {
	    "range": {
	      "@timestamp": {
	        "from": "2012-12-29T16:52:48+00:00",
	        "to": "2012-12-29T17:52:48+00:00"
	      }
	    }
	  }
	}
},
"query" : {
    "term" : { "user" : "kimchy" }
}
"query" : {
    "match_all" : {}
},

func Query

func Query() *QueryDsl

QueryDsl creates a new Query Dsl

func (*QueryDsl) All

func (q *QueryDsl) All() *QueryDsl

get all

func (*QueryDsl) Fields

func (q *QueryDsl) Fields(fields, search, exists, missing string) *QueryDsl

Fields in query_string search

Fields("fieldname","search_for","","")

Fields("fieldname,field2,field3","search_for","","")

Fields("fieldname,field2,field3","search_for","field_exists","")

func (*QueryDsl) Filter

func (q *QueryDsl) Filter(f *FilterOp) *QueryDsl

Filter this query

func (*QueryDsl) MarshalJSON

func (qd *QueryDsl) MarshalJSON() ([]byte, error)

MarshalJSON provides custom marshalling to support the query dsl which is a conditional json format, not always the same parent/children

func (*QueryDsl) Qs

func (q *QueryDsl) Qs(qs *QueryString) *QueryDsl

Querystring operations

func (*QueryDsl) Range

func (q *QueryDsl) Range(fop *FilterOp) *QueryDsl

Limit the query to this range

func (*QueryDsl) Search

func (q *QueryDsl) Search(searchFor string) *QueryDsl

The raw search strings (lucene valid)

func (*QueryDsl) Term

func (q *QueryDsl) Term(name, value string) *QueryDsl

Add a term search for a specific field

Term("user","kimchy")

type QueryEmbed

type QueryEmbed struct {
	MatchAll *MatchAll         `json:"match_all,omitempty"`
	Terms    map[string]string `json:"term,omitempty"`
	Qs       *QueryString      `json:"query_string,omitempty"`
}

The core Query Syntax can be embedded as a child of a variety of different parents

type QueryString

type QueryString struct {
	DefaultOperator string   `json:"default_operator,omitempty"`
	DefaultField    string   `json:"default_field,omitempty"`
	Query           string   `json:"query,omitempty"`
	Exists          string   `json:"_exists_,omitempty"`
	Missing         string   `json:"_missing_,omitempty"`
	Fields          []string `json:"fields,omitempty"`
}

func NewQueryString

func NewQueryString(field, query string) QueryString

QueryString based search

type QueryWrap

type QueryWrap struct {
	Qs QueryString `json:"query_string,omitempty"`
}

should we reuse QueryDsl here?

type SearchDsl

type SearchDsl struct {
	FromVal   int         `json:"from,omitempty"`
	SizeVal   int         `json:"size,omitempty"`
	Index     string      `json:"-"`
	FacetVal  *FacetDsl   `json:"facets,omitempty"`
	QueryVal  *QueryDsl   `json:"query,omitempty"`
	SortBody  []*SortDsl  `json:"sort,omitempty"`
	FilterVal *FilterWrap `json:"filter,omitempty"`
	// contains filtered or unexported fields
}
func Search(index string) *SearchDsl

Search is the entry point to the SearchDsl, it is a chainable set of utilities to create searches.

params

@index = elasticsearch index to search

out, err := Search("github").Type("Issues").Pretty().Query(
Query().Range(
     Range().Field("created_at").From("2012-12-10T15:00:00-08:00").To("2012-12-10T15:10:00-08:00"),
   ).Search("add"),
 ).Result()

func (*SearchDsl) Bytes

func (s *SearchDsl) Bytes() ([]byte, error)

func (*SearchDsl) Facet

func (s *SearchDsl) Facet(f *FacetDsl) *SearchDsl

Facet passes a Query expression to this search

qry := Search("github").Size("0").Facet(
			Facet().Regex("repository.name", "no.*").Size("8"),
		)

qry := Search("github").Pretty().Facet(
			Facet().Fields("type").Size("25"),
		)

func (*SearchDsl) Filter

func (s *SearchDsl) Filter(fl ...interface{}) *SearchDsl

Filter adds a Filter Clause with optional Boolean Clause. This accepts n number of filter clauses. If more than one, and missing Boolean Clause it assumes "and"

qry := Search("github").Filter(
    Filter().Exists("repository.name"),
)

qry := Search("github").Filter(
    "or",
    Filter().Exists("repository.name"),
    Filter().Terms("actor_attributes.location", "portland"),
)

qry := Search("github").Filter(
    Filter().Exists("repository.name"),
    Filter().Terms("repository.has_wiki", true)
)

func (*SearchDsl) From

func (s *SearchDsl) From(from string) *SearchDsl

func (*SearchDsl) Pretty

func (s *SearchDsl) Pretty() *SearchDsl

func (*SearchDsl) Query

func (s *SearchDsl) Query(q *QueryDsl) *SearchDsl

func (*SearchDsl) Result

func (s *SearchDsl) Result() (*core.SearchResult, error)

func (*SearchDsl) Search

func (s *SearchDsl) Search(srch string) *SearchDsl

Search is a simple interface to search, doesn't have the power of query but uses a simple query_string search

func (*SearchDsl) Size

func (s *SearchDsl) Size(size string) *SearchDsl

func (*SearchDsl) Sort

func (s *SearchDsl) Sort(sort ...*SortDsl) *SearchDsl

func (*SearchDsl) Type

func (s *SearchDsl) Type(indexType string) *SearchDsl

Type is the elasticsearch *Type* within a specific index

type SortBody

type SortBody []interface{}

type SortDsl

type SortDsl struct {
	Name   string
	IsDesc bool
}

func Sort

func Sort(field string) *SortDsl

SortDsl accepts any number of Sort commands

Query().Sort(
    Sort("last_name").Desc(),
    Sort("age"),
)

func (*SortDsl) Asc

func (s *SortDsl) Asc() *SortDsl

func (*SortDsl) Desc

func (s *SortDsl) Desc() *SortDsl

func (*SortDsl) MarshalJSON

func (s *SortDsl) MarshalJSON() ([]byte, error)

type Term

type Term struct {
	Terms Terms `json:"terms,omitempty"`
}

Generic Term based (used in query, facet, filter)

type Terms

type Terms struct {
	Fields []string `json:"field,omitempty"`
	Size   string   `json:"size,omitempty"`
	Regex  string   `json:"regex,omitempty"`
}

func (*Terms) MarshalJSON

func (t *Terms) MarshalJSON() ([]byte, error)

Custom marshalling

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL