in search-algolia/algolia.go [77:130]
func (s *SearchAlgolia) SearchContents(ctx context.Context, cond *plugin.SearchBasicCond) (res []plugin.SearchResult, total int64, err error) {
var (
filters = "status<10"
tagFilters []string
userIDFilter string
votesFilter string
)
if len(cond.TagIDs) > 0 {
for _, tagGroup := range cond.TagIDs {
var tagsIn []string
if len(tagGroup) > 0 {
for _, tagID := range tagGroup {
tagsIn = append(tagsIn, "tags:"+tagID)
}
}
tagFilters = append(tagFilters, "("+strings.Join(tagsIn, " OR ")+")")
}
if len(tagFilters) > 0 {
filters += " AND " + strings.Join(tagFilters, " AND ")
}
}
if len(cond.UserID) > 0 {
userIDFilter = "userID:" + cond.UserID
filters += " AND " + userIDFilter
}
if cond.VoteAmount == 0 {
votesFilter = "votes=" + strconv.Itoa(cond.VoteAmount)
filters += " AND " + votesFilter
} else if cond.VoteAmount > 0 {
votesFilter = "votes>=" + strconv.Itoa(cond.VoteAmount)
filters += " AND " + votesFilter
}
var (
query = strings.TrimSpace(strings.Join(cond.Words, " "))
opts = []interface{}{
opt.AttributesToRetrieve("objectID", "type"),
opt.Filters(filters),
opt.Page(cond.Page - 1),
opt.HitsPerPage(cond.PageSize),
}
qres search.QueryRes
)
qres, err = s.getIndex(string(cond.Order)).Search(query, opts...)
for _, hit := range qres.Hits {
res = append(res, plugin.SearchResult{
ID: hit["objectID"].(string),
Type: hit["type"].(string),
})
}
total = int64(qres.NbHits)
return res, total, err
}