mirror of
https://github.com/wgh136/nysoure.git
synced 2025-09-27 20:27: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
|
// split query to search
|
||||||
keywords := splitQuery(query)
|
keywords := splitQuery(query)
|
||||||
var temp []uint
|
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
|
first := true
|
||||||
for _, keyword := range keywords {
|
for _, keyword := range keywords {
|
||||||
if keyword == "" {
|
if keyword == "" {
|
||||||
@@ -320,6 +333,13 @@ func SearchResource(query string, page int) ([]model.ResourceView, int, error) {
|
|||||||
temp = temp1
|
temp = temp1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
res, err := searchWithKeyword(query)
|
||||||
|
if err != nil {
|
||||||
|
return nil, 0, err
|
||||||
|
}
|
||||||
|
temp = res
|
||||||
|
}
|
||||||
resources = append(resources, temp...)
|
resources = append(resources, temp...)
|
||||||
resources = utils.RemoveDuplicate(resources)
|
resources = utils.RemoveDuplicate(resources)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user