| 64 | } |
| 65 | |
| 66 | func (s *SearchAlgolia) SearchContents(ctx context.Context, cond *plugin.SearchBasicCond) (res []plugin.SearchResult, total int64, err error) { |
| 67 | var ( |
| 68 | filters = "status<10" |
| 69 | tagFilters []string |
| 70 | userIDFilter string |
| 71 | votesFilter string |
| 72 | ) |
| 73 | if len(cond.TagIDs) > 0 { |
| 74 | for _, tagID := range cond.TagIDs { |
| 75 | tagFilters = append(tagFilters, "tags:"+tagID) |
| 76 | } |
| 77 | if len(tagFilters) > 0 { |
| 78 | filters += " AND " + strings.Join(tagFilters, " AND ") |
| 79 | } |
| 80 | } |
| 81 | if len(cond.UserID) > 0 { |
| 82 | userIDFilter = "userID:" + cond.UserID |
| 83 | filters += " AND " + userIDFilter |
| 84 | } |
| 85 | if cond.VoteAmount == 0 { |
| 86 | votesFilter = "votes=" + strconv.Itoa(cond.VoteAmount) |
| 87 | filters += " AND " + votesFilter |
| 88 | } else if cond.VoteAmount > 0 { |
| 89 | votesFilter = "votes>=" + strconv.Itoa(cond.VoteAmount) |
| 90 | filters += " AND " + votesFilter |
| 91 | } |
| 92 | |
| 93 | var ( |
| 94 | query = strings.TrimSpace(strings.Join(cond.Words, " ")) |
| 95 | opts = []interface{}{ |
| 96 | opt.AttributesToRetrieve("objectID", "type"), |
| 97 | opt.Filters(filters), |
| 98 | opt.Page(cond.Page - 1), |
| 99 | opt.HitsPerPage(cond.PageSize), |
| 100 | } |
| 101 | qres search.QueryRes |
| 102 | ) |
| 103 | |
| 104 | qres, err = s.getIndex(string(cond.Order)).Search(query, opts...) |
| 105 | for _, hit := range qres.Hits { |
| 106 | res = append(res, plugin.SearchResult{ |
| 107 | ID: hit["objectID"].(string), |
| 108 | Type: hit["type"].(string), |
| 109 | }) |
| 110 | } |
| 111 | total = int64(qres.NbHits) |
| 112 | return res, total, err |
| 113 | } |
| 114 | |
| 115 | func (s *SearchAlgolia) SearchQuestions(ctx context.Context, cond *plugin.SearchBasicCond) (res []plugin.SearchResult, total int64, err error) { |
| 116 | var ( |