Merge branch 'nimishzynga-test'
This commit is contained in:
commit
548b17310b
4
error.go
4
error.go
|
@ -16,7 +16,7 @@ const (
|
|||
ErrorIndexMetaMissing
|
||||
ErrorIndexMetaCorrupt
|
||||
ErrorDisjunctionFewerThanMinClauses
|
||||
ErrorBooleanQueryNeedsMustOrShould
|
||||
ErrorBooleanQueryNeedsMustOrShouldOrNotMust
|
||||
ErrorNumericQueryNoBounds
|
||||
ErrorPhraseQueryNoTerms
|
||||
ErrorUnknownQueryType
|
||||
|
@ -40,7 +40,7 @@ var errorMessages = map[int]string{
|
|||
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(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",
|
||||
|
|
|
@ -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
Block a user