当前位置: 首页>>代码示例>>Golang>>正文


Golang model.ParseSearchParams函数代码示例

本文整理汇总了Golang中github.com/mattermost/platform/model.ParseSearchParams函数的典型用法代码示例。如果您正苦于以下问题:Golang ParseSearchParams函数的具体用法?Golang ParseSearchParams怎么用?Golang ParseSearchParams使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了ParseSearchParams函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: searchPosts

func searchPosts(c *Context, w http.ResponseWriter, r *http.Request) {
	terms := r.FormValue("terms")

	if len(terms) == 0 {
		c.SetInvalidParam("search", "terms")
		return
	}

	paramsList := model.ParseSearchParams(terms)
	channels := []store.StoreChannel{}

	for _, params := range paramsList {
		channels = append(channels, Srv.Store.Post().Search(c.Session.TeamId, c.Session.UserId, params))
	}

	posts := &model.PostList{}
	for _, channel := range channels {
		if result := <-channel; result.Err != nil {
			c.Err = result.Err
			return
		} else {
			data := result.Data.(*model.PostList)
			posts.Extend(data)
		}
	}

	w.Write([]byte(posts.ToJson()))
}
开发者ID:noahd1,项目名称:platform,代码行数:28,代码来源:post.go

示例2: searchPosts

func searchPosts(c *Context, w http.ResponseWriter, r *http.Request) {
	terms := r.FormValue("terms")

	if len(terms) == 0 {
		c.SetInvalidParam("search", "terms")
		return
	}

	paramsList := model.ParseSearchParams(terms)
	channels := []store.StoreChannel{}

	for _, params := range paramsList {
		// don't allow users to search for everything
		if params.Terms != "*" {
			channels = append(channels, Srv.Store.Post().Search(c.Session.TeamId, c.Session.UserId, params))
		}
	}

	posts := &model.PostList{}
	for _, channel := range channels {
		if result := <-channel; result.Err != nil {
			c.Err = result.Err
			return
		} else {
			data := result.Data.(*model.PostList)
			posts.Extend(data)
		}
	}

	w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
	w.Header().Set("Expires", "0")
	w.Write([]byte(posts.ToJson()))
}
开发者ID:r0b0ticus,项目名称:platform,代码行数:33,代码来源:post.go

示例3: searchPosts

func searchPosts(c *Context, w http.ResponseWriter, r *http.Request) {
	terms := r.FormValue("terms")

	if len(terms) == 0 {
		c.SetInvalidParam("search", "terms")
		return
	}

	plainSearchParams, hashtagSearchParams := model.ParseSearchParams(terms)

	var hchan store.StoreChannel
	if hashtagSearchParams != nil {
		hchan = Srv.Store.Post().Search(c.Session.TeamId, c.Session.UserId, hashtagSearchParams)
	}

	var pchan store.StoreChannel
	if plainSearchParams != nil {
		pchan = Srv.Store.Post().Search(c.Session.TeamId, c.Session.UserId, plainSearchParams)
	}

	mainList := &model.PostList{}
	if hchan != nil {
		if result := <-hchan; result.Err != nil {
			c.Err = result.Err
			return
		} else {
			mainList = result.Data.(*model.PostList)
		}
	}

	plainList := &model.PostList{}
	if pchan != nil {
		if result := <-pchan; result.Err != nil {
			c.Err = result.Err
			return
		} else {
			plainList = result.Data.(*model.PostList)
		}
	}

	for _, postId := range plainList.Order {
		if _, ok := mainList.Posts[postId]; !ok {
			mainList.AddPost(plainList.Posts[postId])
			mainList.AddOrder(postId)
		}

	}

	w.Write([]byte(mainList.ToJson()))
}
开发者ID:nikwins,项目名称:platform,代码行数:50,代码来源:post.go

示例4: searchPosts

func searchPosts(c *Context, w http.ResponseWriter, r *http.Request) {
	props := model.StringInterfaceFromJson(r.Body)

	terms := props["terms"].(string)
	if len(terms) == 0 {
		c.SetInvalidParam("search", "terms")
		return
	}

	isOrSearch := false
	if val, ok := props["is_or_search"]; ok && val != nil {
		isOrSearch = val.(bool)
	}

	paramsList := model.ParseSearchParams(terms)
	channels := []store.StoreChannel{}

	for _, params := range paramsList {
		params.OrTerms = isOrSearch
		// don't allow users to search for everything
		if params.Terms != "*" {
			channels = append(channels, Srv.Store.Post().Search(c.TeamId, c.Session.UserId, params))
		}
	}

	posts := &model.PostList{}
	for _, channel := range channels {
		if result := <-channel; result.Err != nil {
			c.Err = result.Err
			return
		} else {
			data := result.Data.(*model.PostList)
			posts.Extend(data)
		}
	}

	w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
	w.Write([]byte(posts.ToJson()))
}
开发者ID:carriercomm,项目名称:platform,代码行数:39,代码来源:post.go


注:本文中的github.com/mattermost/platform/model.ParseSearchParams函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。