0
0

Merge branch 'test' of https://github.com/nimishzynga/bleve into nimishzynga-test

This commit is contained in:
Marty Schoch 2015-07-13 15:23:51 -04:00
commit e8e1556996
3 changed files with 42 additions and 27 deletions

View File

@ -16,7 +16,7 @@ const (
ErrorIndexMetaMissing ErrorIndexMetaMissing
ErrorIndexMetaCorrupt ErrorIndexMetaCorrupt
ErrorDisjunctionFewerThanMinClauses ErrorDisjunctionFewerThanMinClauses
ErrorBooleanQueryNeedsMustOrShould ErrorBooleanQueryNeedsMustOrShouldOrNotMust
ErrorNumericQueryNoBounds ErrorNumericQueryNoBounds
ErrorPhraseQueryNoTerms ErrorPhraseQueryNoTerms
ErrorUnknownQueryType ErrorUnknownQueryType
@ -35,17 +35,17 @@ func (e Error) Error() string {
} }
var errorMessages = map[int]string{ var errorMessages = map[int]string{
int(ErrorIndexPathExists): "cannot create new index, path already exists", int(ErrorIndexPathExists): "cannot create new index, path already exists",
int(ErrorIndexPathDoesNotExist): "cannot open index, path does not exist", int(ErrorIndexPathDoesNotExist): "cannot open index, path does not exist",
int(ErrorIndexMetaMissing): "cannot open index, metadata missing", int(ErrorIndexMetaMissing): "cannot open index, metadata missing",
int(ErrorIndexMetaCorrupt): "cannot open index, metadata corrupt", int(ErrorIndexMetaCorrupt): "cannot open index, metadata corrupt",
int(ErrorDisjunctionFewerThanMinClauses): "disjunction query has fewer than the minimum number of clauses to satisfy", 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(ErrorNumericQueryNoBounds): "numeric range query must specify min or max",
int(ErrorPhraseQueryNoTerms): "phrase query must contain at least one term", int(ErrorPhraseQueryNoTerms): "phrase query must contain at least one term",
int(ErrorUnknownQueryType): "unknown query type", int(ErrorUnknownQueryType): "unknown query type",
int(ErrorUnknownStorageType): "unknown storage type", int(ErrorUnknownStorageType): "unknown storage type",
int(ErrorIndexClosed): "index is closed", int(ErrorIndexClosed): "index is closed",
int(ErrorAliasMulti): "cannot perform single index operation on multiple index alias", int(ErrorAliasMulti): "cannot perform single index operation on multiple index alias",
int(ErrorAliasEmpty): "cannot perform operation on empty alias", int(ErrorAliasEmpty): "cannot perform operation on empty alias",
} }

View File

@ -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) { func (q *booleanQuery) Searcher(i index.IndexReader, m *IndexMapping, explain bool) (search.Searcher, error) {
var err 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 var mustSearcher search.Searcher
if q.Must != nil { if q.Must != nil {
@ -112,15 +122,6 @@ func (q *booleanQuery) Searcher(i index.IndexReader, m *IndexMapping, explain bo
return nil, err 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) return searchers.NewBooleanSearcher(i, mustSearcher, shouldSearcher, mustNotSearcher, explain)
} }
@ -143,8 +144,8 @@ func (q *booleanQuery) Validate() error {
return err return err
} }
} }
if q.Must == nil && q.Should == nil { if q.Must == nil && q.Should == nil && q.MustNot == nil {
return ErrorBooleanQueryNeedsMustOrShould return ErrorBooleanQueryNeedsMustOrShouldOrNotMust
} }
return nil return nil
} }

View File

@ -192,14 +192,28 @@ func TestQueryValidate(t *testing.T) {
nil, nil,
nil, nil,
[]Query{NewMatchQuery("devon").SetField("desc")}), []Query{NewMatchQuery("devon").SetField("desc")}),
err: ErrorBooleanQueryNeedsMustOrShould, err: nil,
}, },
{ {
query: NewBooleanQuery( query: NewBooleanQuery(
[]Query{}, []Query{},
[]Query{}, []Query{},
[]Query{NewMatchQuery("devon").SetField("desc")}), []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( query: NewBooleanQueryMinShould(