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,34 +291,54 @@ 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
|
||||||
first := true
|
haveTag := false
|
||||||
for _, keyword := range keywords {
|
for _, keyword := range keywords {
|
||||||
if keyword == "" {
|
if len([]rune(keyword)) <= maxTagLength {
|
||||||
continue
|
exists, err := dao.ExistsTag(keyword)
|
||||||
}
|
if err != nil {
|
||||||
if utils.OnlyPunctuation(keyword) {
|
return nil, 0, err
|
||||||
continue
|
}
|
||||||
|
if exists {
|
||||||
|
haveTag = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if haveTag {
|
||||||
|
first := true
|
||||||
|
for _, keyword := range keywords {
|
||||||
|
if keyword == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if utils.OnlyPunctuation(keyword) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
res, err := searchWithKeyword(keyword)
|
res, err := searchWithKeyword(keyword)
|
||||||
|
if err != nil {
|
||||||
|
return nil, 0, err
|
||||||
|
}
|
||||||
|
if first {
|
||||||
|
temp = utils.RemoveDuplicate(res)
|
||||||
|
first = false
|
||||||
|
} else {
|
||||||
|
temp1 := make([]uint, 0)
|
||||||
|
for _, id := range temp {
|
||||||
|
for _, id2 := range res {
|
||||||
|
if id == id2 {
|
||||||
|
temp1 = append(temp1, id)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
temp = temp1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
res, err := searchWithKeyword(query)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, 0, err
|
return nil, 0, err
|
||||||
}
|
}
|
||||||
if first {
|
temp = res
|
||||||
temp = utils.RemoveDuplicate(res)
|
|
||||||
first = false
|
|
||||||
} else {
|
|
||||||
temp1 := make([]uint, 0)
|
|
||||||
for _, id := range temp {
|
|
||||||
for _, id2 := range res {
|
|
||||||
if id == id2 {
|
|
||||||
temp1 = append(temp1, id)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
temp = temp1
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
resources = append(resources, temp...)
|
resources = append(resources, temp...)
|
||||||
resources = utils.RemoveDuplicate(resources)
|
resources = utils.RemoveDuplicate(resources)
|
||||||
|
Reference in New Issue
Block a user