parent
7be7ecdf8e
commit
77779b70f4
28
error.go
28
error.go
|
@ -16,7 +16,7 @@ const (
|
|||
ErrorIndexMetaMissing
|
||||
ErrorIndexMetaCorrupt
|
||||
ErrorDisjunctionFewerThanMinClauses
|
||||
ErrorBooleanQueryNeedsMustOrShould
|
||||
ErrorBooleanQueryNeedsMustOrShouldOrNotMust
|
||||
ErrorNumericQueryNoBounds
|
||||
ErrorPhraseQueryNoTerms
|
||||
ErrorUnknownQueryType
|
||||
|
@ -35,17 +35,17 @@ func (e Error) Error() string {
|
|||
}
|
||||
|
||||
var errorMessages = map[int]string{
|
||||
int(ErrorIndexPathExists): "cannot create new index, path already exists",
|
||||
int(ErrorIndexPathDoesNotExist): "cannot open index, path does not exist",
|
||||
int(ErrorIndexMetaMissing): "cannot open index, metadata missing",
|
||||
int(ErrorIndexMetaCorrupt): "cannot open index, metadata corrupt",
|
||||
int(ErrorDisjunctionFewerThanMinClauses): "disjunction query has fewer than the minimum number of clauses to satisfy",
|
||||
int(ErrorBooleanQueryNeedsMustOrShould): "boolean query must contain at least one must or should clause",
|
||||
int(ErrorNumericQueryNoBounds): "numeric range query must specify min or max",
|
||||
int(ErrorPhraseQueryNoTerms): "phrase query must contain at least one term",
|
||||
int(ErrorUnknownQueryType): "unknown query type",
|
||||
int(ErrorUnknownStorageType): "unknown storage type",
|
||||
int(ErrorIndexClosed): "index is closed",
|
||||
int(ErrorAliasMulti): "cannot perform single index operation on multiple index alias",
|
||||
int(ErrorAliasEmpty): "cannot perform operation on empty alias",
|
||||
int(ErrorIndexPathExists): "cannot create new index, path already exists",
|
||||
int(ErrorIndexPathDoesNotExist): "cannot open index, path does not exist",
|
||||
int(ErrorIndexMetaMissing): "cannot open index, metadata missing",
|
||||
int(ErrorIndexMetaCorrupt): "cannot open index, metadata corrupt",
|
||||
int(ErrorDisjunctionFewerThanMinClauses): "disjunction query has fewer than the minimum number of clauses to satisfy",
|
||||
int(ErrorBooleanQueryNeedsMustOrShouldOrNotMust): "boolean query must contain at least one must or should or not must clause",
|
||||
int(ErrorNumericQueryNoBounds): "numeric range query must specify min or max",
|
||||
int(ErrorPhraseQueryNoTerms): "phrase query must contain at least one term",
|
||||
int(ErrorUnknownQueryType): "unknown query type",
|
||||
int(ErrorUnknownStorageType): "unknown storage type",
|
||||
int(ErrorIndexClosed): "index is closed",
|
||||
int(ErrorAliasMulti): "cannot perform single index operation on multiple index alias",
|
||||
int(ErrorAliasEmpty): "cannot perform operation on empty alias",
|
||||
}
|
||||
|
|
|
@ -96,6 +96,16 @@ func (q *booleanQuery) SetBoost(b float64) Query {
|
|||
|
||||
func (q *booleanQuery) Searcher(i index.IndexReader, m *IndexMapping, explain bool) (search.Searcher, error) {
|
||||
var err error
|
||||
var mustNotSearcher search.Searcher
|
||||
if q.MustNot != nil {
|
||||
mustNotSearcher, err = q.MustNot.Searcher(i, m, explain)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if q.Must == nil && q.Should == nil {
|
||||
q.Must = NewMatchAllQuery()
|
||||
}
|
||||
}
|
||||
|
||||
var mustSearcher search.Searcher
|
||||
if q.Must != nil {
|
||||
|
@ -112,15 +122,6 @@ func (q *booleanQuery) Searcher(i index.IndexReader, m *IndexMapping, explain bo
|
|||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
var mustNotSearcher search.Searcher
|
||||
if q.MustNot != nil {
|
||||
mustNotSearcher, err = q.MustNot.Searcher(i, m, explain)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return searchers.NewBooleanSearcher(i, mustSearcher, shouldSearcher, mustNotSearcher, explain)
|
||||
}
|
||||
|
||||
|
@ -143,8 +144,8 @@ func (q *booleanQuery) Validate() error {
|
|||
return err
|
||||
}
|
||||
}
|
||||
if q.Must == nil && q.Should == nil {
|
||||
return ErrorBooleanQueryNeedsMustOrShould
|
||||
if q.Must == nil && q.Should == nil && q.MustNot == nil {
|
||||
return ErrorBooleanQueryNeedsMustOrShouldOrNotMust
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -192,14 +192,28 @@ func TestQueryValidate(t *testing.T) {
|
|||
nil,
|
||||
nil,
|
||||
[]Query{NewMatchQuery("devon").SetField("desc")}),
|
||||
err: ErrorBooleanQueryNeedsMustOrShould,
|
||||
err: nil,
|
||||
},
|
||||
{
|
||||
query: NewBooleanQuery(
|
||||
[]Query{},
|
||||
[]Query{},
|
||||
[]Query{NewMatchQuery("devon").SetField("desc")}),
|
||||
err: ErrorBooleanQueryNeedsMustOrShould,
|
||||
err: nil,
|
||||
},
|
||||
{
|
||||
query: NewBooleanQuery(
|
||||
nil,
|
||||
nil,
|
||||
nil),
|
||||
err: ErrorBooleanQueryNeedsMustOrShouldOrNotMust,
|
||||
},
|
||||
{
|
||||
query: NewBooleanQuery(
|
||||
[]Query{},
|
||||
[]Query{},
|
||||
[]Query{}),
|
||||
err: ErrorBooleanQueryNeedsMustOrShouldOrNotMust,
|
||||
},
|
||||
{
|
||||
query: NewBooleanQueryMinShould(
|
||||
|
|
Loading…
Reference in New Issue