mirror of
https://github.com/wgh136/nysoure.git
synced 2025-09-27 04:17:23 +00:00
Improve search
This commit is contained in:
@@ -291,6 +291,19 @@ func SearchResource(query string, page int) ([]model.ResourceView, int, error) {
|
||||
// split query to search
|
||||
keywords := splitQuery(query)
|
||||
var temp []uint
|
||||
haveTag := false
|
||||
for _, keyword := range keywords {
|
||||
if len([]rune(keyword)) <= maxTagLength {
|
||||
exists, err := dao.ExistsTag(keyword)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
if exists {
|
||||
haveTag = true
|
||||
}
|
||||
}
|
||||
}
|
||||
if haveTag {
|
||||
first := true
|
||||
for _, keyword := range keywords {
|
||||
if keyword == "" {
|
||||
@@ -320,6 +333,13 @@ func SearchResource(query string, page int) ([]model.ResourceView, int, error) {
|
||||
temp = temp1
|
||||
}
|
||||
}
|
||||
} else {
|
||||
res, err := searchWithKeyword(query)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
temp = res
|
||||
}
|
||||
resources = append(resources, temp...)
|
||||
resources = utils.RemoveDuplicate(resources)
|
||||
|
||||
|
Reference in New Issue
Block a user