mirror of
https://github.com/wgh136/nysoure.git
synced 2025-09-27 04:17:23 +00:00
Compare commits
2 Commits
abbd7ed006
...
ed5843cd54
Author | SHA1 | Date | |
---|---|---|---|
ed5843cd54 | |||
c0d904e035 |
@@ -430,24 +430,32 @@ func GetResourcesIdWithTag(tagID uint) ([]uint, error) {
|
||||
}
|
||||
|
||||
func BatchGetResources(ids []uint) ([]model.Resource, error) {
|
||||
idMap := make(map[uint]struct{})
|
||||
uniqueIds := make([]uint, 0, len(ids))
|
||||
for _, id := range ids {
|
||||
if _, exists := idMap[id]; !exists {
|
||||
idMap[id] = struct{}{}
|
||||
uniqueIds = append(uniqueIds, id)
|
||||
}
|
||||
}
|
||||
|
||||
var resources []model.Resource
|
||||
|
||||
for _, id := range ids {
|
||||
var r model.Resource
|
||||
if err := db.
|
||||
Where("id IN ?", uniqueIds).
|
||||
Preload("User").
|
||||
Preload("Images").
|
||||
Preload("Tags").
|
||||
Find(&resources).
|
||||
Error; err != nil {
|
||||
First(&r, id).Error; err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
continue
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
for i, tag := range r.Tags {
|
||||
if tag.AliasOf != nil {
|
||||
t, err := GetTagByID(*tag.AliasOf)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
r.Tags[i].Type = t.Type
|
||||
}
|
||||
}
|
||||
}
|
||||
resources = append(resources, r)
|
||||
}
|
||||
|
||||
return resources, nil
|
||||
}
|
||||
|
@@ -82,7 +82,6 @@ func init() {
|
||||
func SearchResource(keyword string) ([]uint, error) {
|
||||
query := bleve.NewMatchQuery(keyword)
|
||||
searchRequest := bleve.NewSearchRequest(query)
|
||||
searchRequest.Size = 1000
|
||||
searchResults, err := index.Search(searchRequest)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -90,8 +89,8 @@ func SearchResource(keyword string) ([]uint, error) {
|
||||
|
||||
results := make([]uint, 0)
|
||||
for _, hit := range searchResults.Hits {
|
||||
if hit.Score < 0.6 {
|
||||
continue
|
||||
if hit.Score < 0.2 {
|
||||
break
|
||||
}
|
||||
id, err := strconv.ParseUint(hit.ID, 10, 32)
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user