本文整理匯總了Golang中github.com/urandom/readeef/content.User.ArticlesById方法的典型用法代碼示例。如果您正苦於以下問題:Golang User.ArticlesById方法的具體用法?Golang User.ArticlesById怎麽用?Golang User.ArticlesById使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/urandom/readeef/content.User
的用法示例。
在下文中一共展示了User.ArticlesById方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: query
func query(term, highlight string, index bleve.Index, u content.User, feedIds []data.FeedId, paging ...int) (ua []content.UserArticle, err error) {
var query bleve.Query
query = bleve.NewQueryStringQuery(term)
if len(feedIds) > 0 {
queries := make([]bleve.Query, len(feedIds))
conjunct := make([]bleve.Query, 2)
for i, id := range feedIds {
q := bleve.NewTermQuery(strconv.FormatInt(int64(id), 10))
q.SetField("FeedId")
queries[i] = q
}
disjunct := bleve.NewDisjunctionQuery(queries)
conjunct[0] = query
conjunct[1] = disjunct
query = bleve.NewConjunctionQuery(conjunct)
}
searchRequest := bleve.NewSearchRequest(query)
if highlight != "" {
searchRequest.Highlight = bleve.NewHighlightWithStyle(highlight)
}
limit, offset := pagingLimit(paging)
searchRequest.Size = limit
searchRequest.From = offset
searchResult, err := index.Search(searchRequest)
if err != nil {
return
}
if len(searchResult.Hits) == 0 {
return
}
articleIds := []data.ArticleId{}
hitMap := map[data.ArticleId]*search.DocumentMatch{}
for _, hit := range searchResult.Hits {
if articleId, err := strconv.ParseInt(hit.ID, 10, 64); err == nil {
id := data.ArticleId(articleId)
articleIds = append(articleIds, id)
hitMap[id] = hit
}
}
ua = u.ArticlesById(articleIds)
if u.HasErr() {
return ua, u.Err()
}
for i := range ua {
data := ua[i].Data()
hit := hitMap[data.Id]
if len(hit.Fragments) > 0 {
data.Hit.Fragments = hit.Fragments
ua[i].Data(data)
}
}
return
}
示例2: Handler
//.........這裏部分代碼省略.........
case "all_articles":
case "adaptive":
case "unread":
o.UnreadOnly = true
case "marked":
o.FavoriteOnly = true
default:
skip = true
}
if !skip {
articles = articleRepo.Articles(o)
}
}
}
if len(articles) > 0 {
firstId = articles[0].Data().Id
}
headlines := ttRssHeadlinesFromArticles(articles, feedTitle, req.ShowContent, req.ShowExcerpt)
if req.IncludeHeader {
header := ttRssHeadlinesHeader{Id: req.FeedId, FirstId: firstId, IsCat: req.IsCat}
hContent := ttRssHeadlinesHeaderContent{}
hContent = append(hContent, header)
hContent = append(hContent, headlines)
con = hContent
} else {
con = headlines
}
case "updateArticle":
articles := user.ArticlesById(req.ArticleIds, data.ArticleQueryOptions{SkipSessionProcessors: true})
updateCount := int64(0)
switch req.Field {
case 0, 2:
for _, a := range articles {
d := a.Data()
updated := false
switch req.Field {
case 0:
switch req.Mode {
case 0:
if d.Favorite {
updated = true
d.Favorite = false
}
case 1:
if !d.Favorite {
updated = true
d.Favorite = true
}
case 2:
updated = true
d.Favorite = !d.Favorite
}
if updated {
a.Favorite(d.Favorite)
}
case 2:
switch req.Mode {
case 0:
if !d.Read {
示例3: Search
func (e Elastic) Search(
term string, u content.User, feedIds []data.FeedId, limit, offset int,
) (ua []content.UserArticle, err error) {
search := e.client.Search().Index(elasticIndexName)
var query elastic.Query
if t, err := url.QueryUnescape(term); err == nil {
term = t
}
query = elastic.NewCommonTermsQuery("_all", term)
if len(feedIds) > 0 {
idFilter := elastic.NewBoolQuery()
for _, id := range feedIds {
idFilter = idFilter.Should(elastic.NewTermQuery("feed_id", int64(id)))
}
query = elastic.NewBoolQuery().Must(query).Filter(idFilter)
}
search.Query(query)
search.Highlight(elastic.NewHighlight().PreTags("<mark>").PostTags("</mark>").Field("title").Field("description"))
search.From(offset).Size(limit)
switch e.Field() {
case data.SortByDate:
search.Sort("date", e.Order() == data.AscendingOrder)
case data.SortById, data.DefaultSort:
search.Sort("article_id", e.Order() == data.AscendingOrder)
}
var res *elastic.SearchResult
res, err = search.Do()
if err != nil {
return
}
if res.TotalHits() == 0 {
return
}
articleIds := []data.ArticleId{}
highlightMap := map[data.ArticleId]elastic.SearchHitHighlight{}
if res.Hits != nil && res.Hits.Hits != nil {
for _, hit := range res.Hits.Hits {
a := indexArticle{}
if err := json.Unmarshal(*hit.Source, &a); err == nil {
if id, err := strconv.ParseInt(a.ArticleId, 10, 64); err == nil {
articleId := data.ArticleId(id)
articleIds = append(articleIds, articleId)
highlightMap[articleId] = hit.Highlight
}
}
}
}
ua = u.ArticlesById(articleIds)
if u.HasErr() {
return ua, u.Err()
}
for i := range ua {
data := ua[i].Data()
if highlight, ok := highlightMap[data.Id]; ok {
data.Hit.Fragments = map[string][]string{}
if len(highlight["title"]) > 0 {
data.Hit.Fragments["Title"] = highlight["title"]
}
if len(highlight["description"]) > 0 {
data.Hit.Fragments["Description"] = highlight["description"]
}
ua[i].Data(data)
}
}
return
}
示例4: Handler
//.........這裏部分代碼省略.........
if count > 0 {
if val, ok := r.Form["since_id"]; ok {
since, err = strconv.ParseInt(val[0], 10, 64)
if err != nil {
err = nil
since = 0
}
}
if val, ok := r.Form["max_id"]; ok {
max, err = strconv.ParseInt(val[0], 10, 64)
if err != nil {
err = nil
since = 0
}
}
var articles []content.UserArticle
// Fever clients do their own paging
o := data.ArticleQueryOptions{Limit: 50, Offset: 0, SkipSessionProcessors: true}
if withIds, ok := r.Form["with_ids"]; ok {
stringIds := strings.Split(withIds[0], ",")
ids := make([]data.ArticleId, 0, len(stringIds))
for _, stringId := range stringIds {
stringId = strings.TrimSpace(stringId)
if id, err := strconv.ParseInt(stringId, 10, 64); err == nil {
ids = append(ids, data.ArticleId(id))
}
}
articles, err = user.ArticlesById(ids, data.ArticleQueryOptions{SkipSessionProcessors: true}), user.Err()
} else if max > 0 {
user.Order(data.DescendingOrder)
o.BeforeId = data.ArticleId(max)
articles, err = user.Articles(o), user.Err()
} else {
user.Order(data.AscendingOrder)
o.AfterId = data.ArticleId(since)
articles, err = user.Articles(o), user.Err()
}
if err != nil {
break
}
for i := range articles {
in := articles[i].Data()
item := feverItem{
Id: in.Id, FeedId: in.FeedId, Title: in.Title, Html: in.Description,
Url: in.Link, CreatedOnTime: in.Date.Unix(),
}
if in.Read {
item.IsRead = 1
}
if in.Favorite {
item.IsSaved = 1
}
items = append(items, item)
}
}
resp["total_items"] = count
resp["items"] = items