optimize #129 make tweet search by tag more exact when use meilisearch

pull/133/head
alimy 2 years ago
parent 64ad2c7076
commit 6f73103300

@ -65,6 +65,15 @@ func newMeiliLogHook() *meiliLogHook {
Uid: hook.idxName, Uid: hook.idxName,
PrimaryKey: "id", PrimaryKey: "id",
}) })
rankingRules := []string{
"message",
"time:desc",
}
sortableAttributes := []string{
"time:desc",
}
index.UpdateRankingRules(&rankingRules)
index.UpdateSortableAttributes(&sortableAttributes)
} }
// 初始化addDocsCh // 初始化addDocsCh

@ -25,10 +25,12 @@ func newMeiliTweetSearchServant() *meiliTweetSearchServant {
}) })
searchableAttributes := []string{"content", "tags"} searchableAttributes := []string{"content", "tags"}
sortableAttributes := []string{"is_top", "latest_replied_on"} sortableAttributes := []string{"is_top", "latest_replied_on"}
filterableAttributes := []string{"tags"}
index := client.Index(s.Index) index := client.Index(s.Index)
index.UpdateSearchableAttributes(&searchableAttributes) index.UpdateSearchableAttributes(&searchableAttributes)
index.UpdateSortableAttributes(&sortableAttributes) index.UpdateSortableAttributes(&sortableAttributes)
index.UpdateFilterableAttributes(&filterableAttributes)
} }
return &meiliTweetSearchServant{ return &meiliTweetSearchServant{
@ -80,7 +82,6 @@ func (s *meiliTweetSearchServant) queryByContent(q *core.QueryReq, offset, limit
resp, err := s.index.Search(q.Query, &meilisearch.SearchRequest{ resp, err := s.index.Search(q.Query, &meilisearch.SearchRequest{
Offset: int64(offset), Offset: int64(offset),
Limit: int64(limit), Limit: int64(limit),
AttributesToRetrieve: []string{"*"},
Sort: []string{"is_top:desc", "latest_replied_on:desc"}, Sort: []string{"is_top:desc", "latest_replied_on:desc"},
}) })
if err != nil { if err != nil {
@ -93,7 +94,7 @@ func (s *meiliTweetSearchServant) queryByTag(q *core.QueryReq, offset, limit int
resp, err := s.index.Search("#"+q.Query, &meilisearch.SearchRequest{ resp, err := s.index.Search("#"+q.Query, &meilisearch.SearchRequest{
Offset: int64(offset), Offset: int64(offset),
Limit: int64(limit), Limit: int64(limit),
AttributesToRetrieve: []string{"*"}, Filter: []string{"tags." + q.Query + "=1"},
Sort: []string{"is_top:desc", "latest_replied_on:desc"}, Sort: []string{"is_top:desc", "latest_replied_on:desc"},
}) })
if err != nil { if err != nil {
@ -106,7 +107,6 @@ func (s *meiliTweetSearchServant) queryAny(offset, limit int) (*core.QueryResp,
resp, err := s.index.Search("", &meilisearch.SearchRequest{ resp, err := s.index.Search("", &meilisearch.SearchRequest{
Offset: int64(offset), Offset: int64(offset),
Limit: int64(limit), Limit: int64(limit),
Matches: true,
Sort: []string{"is_top:desc", "latest_replied_on:desc"}, Sort: []string{"is_top:desc", "latest_replied_on:desc"},
}) })
if err != nil { if err != nil {

Loading…
Cancel
Save