From 707fbd1821b2ebcc33d19ba37390cd8896608e76 Mon Sep 17 00:00:00 2001 From: Wessie Date: Sat, 21 Dec 2024 01:12:41 +0100 Subject: [PATCH] search/bleve: use a more generic interface for the typecheck We've been seeing non-ConjunctionQuery in Must so something is changing that. --- search/bleve/main.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/search/bleve/main.go b/search/bleve/main.go index 1d3163a..3ff8971 100644 --- a/search/bleve/main.go +++ b/search/bleve/main.go @@ -329,13 +329,18 @@ func NewQuery(ctx context.Context, s string) (query.Query, error) { return q, nil } - cq, ok := bq.Must.(*query.ConjunctionQuery) - if !ok { - zerolog.Ctx(ctx).Warn().Str("type", fmt.Sprintf("%T", q)).Msg("query was not a ConjuctionQuery") + switch qq := bq.Must.(type) { + case *query.ConjunctionQuery: + // move the should (OR) into the must (AND) query set + qq.AddQuery(dq.Disjuncts...) + case *query.BooleanQuery: + // move the should (OR) into the must (AND) query set + qq.AddMust(dq.Disjuncts...) + default: + zerolog.Ctx(ctx).Warn().Str("type", fmt.Sprintf("%T", q)).Msg("query is unknown type") return q, nil } - // move the disjuncts (OR) into the conjuncts (AND) query set - cq.AddQuery(dq.Disjuncts...) + // set the original should to nil bq.Should = nil