mirror of
https://github.com/wgh136/nysoure.git
synced 2025-09-27 04:17:23 +00:00
Improve search
This commit is contained in:
@@ -32,16 +32,10 @@ func createIndex() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, r := range res {
|
for _, r := range res {
|
||||||
title := r.Title
|
|
||||||
title = utils.RemoveSpaces(title)
|
|
||||||
altTitles := make([]string, len(r.AlternativeTitles))
|
|
||||||
for i, t := range r.AlternativeTitles {
|
|
||||||
altTitles[i] = utils.RemoveSpaces(t)
|
|
||||||
}
|
|
||||||
err := index.Index(fmt.Sprintf("%d", r.ID), ResourceParams{
|
err := index.Index(fmt.Sprintf("%d", r.ID), ResourceParams{
|
||||||
Id: r.ID,
|
Id: r.ID,
|
||||||
Title: title,
|
Title: r.Title,
|
||||||
Subtitles: altTitles,
|
Subtitles: r.AlternativeTitles,
|
||||||
Time: r.CreatedAt,
|
Time: r.CreatedAt,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -72,8 +66,6 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func SearchResource(keyword string) (map[uint]time.Time, error) {
|
func SearchResource(keyword string) (map[uint]time.Time, error) {
|
||||||
keyword = utils.RemoveSpaces(keyword)
|
|
||||||
|
|
||||||
query := bleve.NewMatchQuery(keyword)
|
query := bleve.NewMatchQuery(keyword)
|
||||||
searchRequest := bleve.NewSearchRequest(query)
|
searchRequest := bleve.NewSearchRequest(query)
|
||||||
searchRequest.Size = 10000
|
searchRequest.Size = 10000
|
||||||
@@ -85,6 +77,9 @@ func SearchResource(keyword string) (map[uint]time.Time, error) {
|
|||||||
|
|
||||||
results := make(map[uint]time.Time)
|
results := make(map[uint]time.Time)
|
||||||
for _, hit := range searchResults.Hits {
|
for _, hit := range searchResults.Hits {
|
||||||
|
if hit.Score < 0.5 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
id, err := strconv.ParseUint(hit.ID, 10, 32)
|
id, err := strconv.ParseUint(hit.ID, 10, 32)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
|
Reference in New Issue
Block a user