0
0
Fork 0

fix issues identified by go lint

This commit is contained in:
Marty Schoch 2014-09-02 17:40:46 -04:00
parent d75d836c09
commit 28980c4da1
10 changed files with 46 additions and 32 deletions

View File

@ -9,6 +9,7 @@
package bleve package bleve
// Constant Error values which can be compared to determine the type of error
const ( const (
ErrorIndexPathExists Error = iota ErrorIndexPathExists Error = iota
ErrorIndexPathDoesNotExist ErrorIndexPathDoesNotExist
@ -23,6 +24,8 @@ const (
ErrorIndexClosed ErrorIndexClosed
) )
// Error represents a more strongly typed bleve error for detecting
// and handling specific types of errors.
type Error int type Error int
func (e Error) Error() string { func (e Error) Error() string {

View File

@ -387,7 +387,7 @@ func (i *indexImpl) Search(req *SearchRequest) (*SearchResult, error) {
if highlightFields == nil { if highlightFields == nil {
// add all fields with matches // add all fields with matches
highlightFields = make([]string, 0, len(hit.Locations)) highlightFields = make([]string, 0, len(hit.Locations))
for k, _ := range hit.Locations { for k := range hit.Locations {
highlightFields = append(highlightFields, k) highlightFields = append(highlightFields, k)
} }
} }

View File

@ -57,9 +57,8 @@ func (i *indexMeta) Save(path string) error {
if err != nil { if err != nil {
if os.IsExist(err) { if os.IsExist(err) {
return ErrorIndexPathExists return ErrorIndexPathExists
} else {
return err
} }
return err
} }
defer indexMetaFile.Close() defer indexMetaFile.Close()
_, err = indexMetaFile.Write(metaBytes) _, err = indexMetaFile.Write(metaBytes)

View File

@ -112,7 +112,7 @@ func NewDocumentDisabledMapping() *DocumentMapping {
return &DocumentMapping{} return &DocumentMapping{}
} }
// Adds the provided DocumentMapping as a sub-mapping // AddSubDocumentMapping adds the provided DocumentMapping as a sub-mapping
// for the specified named subsection. // for the specified named subsection.
func (dm *DocumentMapping) AddSubDocumentMapping(property string, sdm *DocumentMapping) *DocumentMapping { func (dm *DocumentMapping) AddSubDocumentMapping(property string, sdm *DocumentMapping) *DocumentMapping {
if dm.Properties == nil { if dm.Properties == nil {
@ -122,7 +122,7 @@ func (dm *DocumentMapping) AddSubDocumentMapping(property string, sdm *DocumentM
return dm return dm
} }
// Adds the provided FieldMapping for this section // AddFieldMapping adds the provided FieldMapping for this section
// of the document. // of the document.
func (dm *DocumentMapping) AddFieldMapping(fm *FieldMapping) *DocumentMapping { func (dm *DocumentMapping) AddFieldMapping(fm *FieldMapping) *DocumentMapping {
if dm.Fields == nil { if dm.Fields == nil {

View File

@ -108,60 +108,67 @@ type IndexMapping struct {
cache *registry.Cache `json:"_"` cache *registry.Cache `json:"_"`
} }
func (i *IndexMapping) AddCustomCharFilter(name string, config map[string]interface{}) error { // AddCustomCharFilter defines a custom char fitler for use in this mapping
_, err := i.cache.DefineCharFilter(name, config) func (im *IndexMapping) AddCustomCharFilter(name string, config map[string]interface{}) error {
_, err := im.cache.DefineCharFilter(name, config)
if err != nil { if err != nil {
return err return err
} }
i.CustomAnalysis.CharFilters[name] = config im.CustomAnalysis.CharFilters[name] = config
return nil return nil
} }
func (i *IndexMapping) AddCustomTokenizer(name string, config map[string]interface{}) error { // AddCustomTokenizer defines a custom tokenizer for use in this mapping
_, err := i.cache.DefineTokenizer(name, config) func (im *IndexMapping) AddCustomTokenizer(name string, config map[string]interface{}) error {
_, err := im.cache.DefineTokenizer(name, config)
if err != nil { if err != nil {
return err return err
} }
i.CustomAnalysis.Tokenizers[name] = config im.CustomAnalysis.Tokenizers[name] = config
return nil return nil
} }
func (i *IndexMapping) AddCustomTokenMap(name string, config map[string]interface{}) error { // AddCustomTokenMap defines a custom token map for use in this mapping
_, err := i.cache.DefineTokenMap(name, config) func (im *IndexMapping) AddCustomTokenMap(name string, config map[string]interface{}) error {
_, err := im.cache.DefineTokenMap(name, config)
if err != nil { if err != nil {
return err return err
} }
i.CustomAnalysis.TokenMaps[name] = config im.CustomAnalysis.TokenMaps[name] = config
return nil return nil
} }
func (i *IndexMapping) AddCustomTokenFilter(name string, config map[string]interface{}) error { // AddCustomTokenFilter defines a custom token filter for use in this mapping
_, err := i.cache.DefineTokenFilter(name, config) func (im *IndexMapping) AddCustomTokenFilter(name string, config map[string]interface{}) error {
_, err := im.cache.DefineTokenFilter(name, config)
if err != nil { if err != nil {
return err return err
} }
i.CustomAnalysis.TokenFilters[name] = config im.CustomAnalysis.TokenFilters[name] = config
return nil return nil
} }
func (i *IndexMapping) AddCustomAnalyzer(name string, config map[string]interface{}) error { // AddCustomAnalyzer defines a custom analyzer for use in this mapping
_, err := i.cache.DefineAnalyzer(name, config) func (im *IndexMapping) AddCustomAnalyzer(name string, config map[string]interface{}) error {
_, err := im.cache.DefineAnalyzer(name, config)
if err != nil { if err != nil {
return err return err
} }
i.CustomAnalysis.Analyzers[name] = config im.CustomAnalysis.Analyzers[name] = config
return nil return nil
} }
func (i *IndexMapping) AddCustomDateTimeParser(name string, config map[string]interface{}) error { // AddCustomDateTimeParser defines a custom date time parser for use in this mapping
_, err := i.cache.DefineDateTimeParser(name, config) func (im *IndexMapping) AddCustomDateTimeParser(name string, config map[string]interface{}) error {
_, err := im.cache.DefineDateTimeParser(name, config)
if err != nil { if err != nil {
return err return err
} }
i.CustomAnalysis.DateTimeParsers[name] = config im.CustomAnalysis.DateTimeParsers[name] = config
return nil return nil
} }
// NewIndexMapping creates a new IndexMapping that will use all the default indexing rules
func NewIndexMapping() *IndexMapping { func NewIndexMapping() *IndexMapping {
return &IndexMapping{ return &IndexMapping{
TypeMapping: make(map[string]*DocumentMapping), TypeMapping: make(map[string]*DocumentMapping),
@ -203,6 +210,7 @@ func (im *IndexMapping) validate() error {
return nil return nil
} }
// AddDocumentMapping sets a custom document mapping for the specified type
func (im *IndexMapping) AddDocumentMapping(doctype string, dm *DocumentMapping) *IndexMapping { func (im *IndexMapping) AddDocumentMapping(doctype string, dm *DocumentMapping) *IndexMapping {
im.TypeMapping[doctype] = dm im.TypeMapping[doctype] = dm
return im return im
@ -216,6 +224,7 @@ func (im *IndexMapping) mappingForType(docType string) *DocumentMapping {
return docMapping return docMapping
} }
// UnmarshalJSON deserializes a JSON representation of the IndexMapping
func (im *IndexMapping) UnmarshalJSON(data []byte) error { func (im *IndexMapping) UnmarshalJSON(data []byte) error {
var tmp struct { var tmp struct {
TypeMapping map[string]*DocumentMapping `json:"types"` TypeMapping map[string]*DocumentMapping `json:"types"`

View File

@ -36,6 +36,11 @@ func NewDateRangeQuery(start, end *string) *dateRangeQuery {
return NewDateRangeInclusiveQuery(start, end, nil, nil) return NewDateRangeInclusiveQuery(start, end, nil, nil)
} }
// NewDateRangeInclusiveQuery creates a new Query for ranges
// of date values.
// A DateTimeParser is chosed based on the field.
// Either, but not both endpoints can be nil.
// startInclusive and endInclusive control inclusion of the endpoints.
func NewDateRangeInclusiveQuery(start, end *string, startInclusive, endInclusive *bool) *dateRangeQuery { func NewDateRangeInclusiveQuery(start, end *string, startInclusive, endInclusive *bool) *dateRangeQuery {
return &dateRangeQuery{ return &dateRangeQuery{
Start: start, Start: start,

View File

@ -86,10 +86,9 @@ func (q *matchQuery) Searcher(i *indexImpl, explain bool) (search.Searcher, erro
SetBoost(q.BoostVal) SetBoost(q.BoostVal)
return shouldQuery.Searcher(i, explain) return shouldQuery.Searcher(i, explain)
} else {
noneQuery := NewMatchNoneQuery()
return noneQuery.Searcher(i, explain)
} }
noneQuery := NewMatchNoneQuery()
return noneQuery.Searcher(i, explain)
} }
func (q *matchQuery) Validate() error { func (q *matchQuery) Validate() error {

View File

@ -82,10 +82,9 @@ func (q *matchPhraseQuery) Searcher(i *indexImpl, explain bool) (search.Searcher
phraseQuery := NewPhraseQuery(ts, field).SetBoost(q.BoostVal) phraseQuery := NewPhraseQuery(ts, field).SetBoost(q.BoostVal)
return phraseQuery.Searcher(i, explain) return phraseQuery.Searcher(i, explain)
} else {
noneQuery := NewMatchNoneQuery()
return noneQuery.Searcher(i, explain)
} }
noneQuery := NewMatchNoneQuery()
return noneQuery.Searcher(i, explain)
} }
func (q *matchPhraseQuery) Validate() error { func (q *matchPhraseQuery) Validate() error {

View File

@ -32,7 +32,7 @@ func NewNumericRangeQuery(min, max *float64) *numericRangeQuery {
return NewNumericRangeInclusiveQuery(min, max, nil, nil) return NewNumericRangeInclusiveQuery(min, max, nil, nil)
} }
// NewNumericRangeQuery creates a new Query for ranges // NewNumericRangeInclusiveQuery creates a new Query for ranges
// of date values. // of date values.
// Either, but not both endpoints can be nil. // Either, but not both endpoints can be nil.
// Control endpoint inclusion with inclusiveMin, inclusiveMax. // Control endpoint inclusion with inclusiveMin, inclusiveMax.

View File

@ -112,11 +112,11 @@ func (fr *FacetRequest) AddNumericRange(name string, min, max *float64) {
fr.NumericRanges = append(fr.NumericRanges, &numericRange{Name: name, Min: min, Max: max}) fr.NumericRanges = append(fr.NumericRanges, &numericRange{Name: name, Min: min, Max: max})
} }
// FacetsRequests groups together all the // FacetsRequest groups together all the
// FacetRequest objects for a single query. // FacetRequest objects for a single query.
type FacetsRequest map[string]*FacetRequest type FacetsRequest map[string]*FacetRequest
// HighlighRequest describes how field matches // HighlightRequest describes how field matches
// should be highlighted. // should be highlighted.
type HighlightRequest struct { type HighlightRequest struct {
Style *string `json:"style"` Style *string `json:"style"`