[MM-25538] Adds the termOperator and takes it into account for terms and hashtag queries (#14664)
Automatic Merge
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
8d4da8b968
Коммит
6643a7c610
@@ -43,6 +43,11 @@ func (b *BleveEngine) SearchPosts(channels *model.ChannelList, searchParams []*m
|
|||||||
filters = append(filters, typeQ)
|
filters = append(filters, typeQ)
|
||||||
|
|
||||||
for i, params := range searchParams {
|
for i, params := range searchParams {
|
||||||
|
var termOperator query.MatchQueryOperator = query.MatchQueryOperatorAnd
|
||||||
|
if searchParams[0].OrTerms {
|
||||||
|
termOperator = query.MatchQueryOperatorOr
|
||||||
|
}
|
||||||
|
|
||||||
// Date, channels and FromUsers filters come in all
|
// Date, channels and FromUsers filters come in all
|
||||||
// searchParams iteration, and as they are global to the
|
// searchParams iteration, and as they are global to the
|
||||||
// query, we only need to process them once
|
// query, we only need to process them once
|
||||||
@@ -141,29 +146,26 @@ func (b *BleveEngine) SearchPosts(channels *model.ChannelList, searchParams []*m
|
|||||||
if params.Terms != "" {
|
if params.Terms != "" {
|
||||||
hashtagQ := bleve.NewMatchQuery(params.Terms)
|
hashtagQ := bleve.NewMatchQuery(params.Terms)
|
||||||
hashtagQ.SetField("Hashtags")
|
hashtagQ.SetField("Hashtags")
|
||||||
|
hashtagQ.SetOperator(termOperator)
|
||||||
termQueries = append(termQueries, hashtagQ)
|
termQueries = append(termQueries, hashtagQ)
|
||||||
} else if params.ExcludedTerms != "" {
|
} else if params.ExcludedTerms != "" {
|
||||||
hashtagQ := bleve.NewMatchQuery(params.ExcludedTerms)
|
hashtagQ := bleve.NewMatchQuery(params.ExcludedTerms)
|
||||||
hashtagQ.SetField("Hashtags")
|
hashtagQ.SetField("Hashtags")
|
||||||
|
hashtagQ.SetOperator(termOperator)
|
||||||
notTermQueries = append(notTermQueries, hashtagQ)
|
notTermQueries = append(notTermQueries, hashtagQ)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if len(params.Terms) > 0 {
|
if len(params.Terms) > 0 {
|
||||||
query := bleve.NewBooleanQuery()
|
|
||||||
messageQ := bleve.NewMatchQuery(params.Terms)
|
messageQ := bleve.NewMatchQuery(params.Terms)
|
||||||
messageQ.SetField("Message")
|
messageQ.SetField("Message")
|
||||||
|
messageQ.SetOperator(termOperator)
|
||||||
if searchParams[0].OrTerms {
|
|
||||||
query.AddShould(messageQ)
|
|
||||||
} else {
|
|
||||||
query.AddMust(messageQ)
|
|
||||||
}
|
|
||||||
termQueries = append(termQueries, messageQ)
|
termQueries = append(termQueries, messageQ)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(params.ExcludedTerms) > 0 {
|
if len(params.ExcludedTerms) > 0 {
|
||||||
messageQ := bleve.NewMatchQuery(params.ExcludedTerms)
|
messageQ := bleve.NewMatchQuery(params.ExcludedTerms)
|
||||||
messageQ.SetField("Message")
|
messageQ.SetField("Message")
|
||||||
|
messageQ.SetOperator(termOperator)
|
||||||
notTermQueries = append(notTermQueries, messageQ)
|
notTermQueries = append(notTermQueries, messageQ)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user