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


Golang search.Open函数代码示例

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


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

示例1: SearchUsers

func SearchUsers(c appengine.Context, query string) ([]StoredUserMeta, error) {
	db := DB{c}
	index, err := search.Open("users")
	if err != nil {
		return nil, err
	}

	var users []StoredUserMeta

	opts := &search.SearchOptions{
		Limit:   100,
		IDsOnly: true,
	}

	for t := index.Search(c, query, opts); ; {
		key, err := t.Next(nil)
		if err == search.Done {
			break
		} else if err != nil {
			return nil, err
		}
		id, _ := strconv.ParseInt(key, 10, 64)
		userMeta, err := db.GetUserMeta(id)

		users = append(users, userMeta.(StoredUserMeta))
	}

	return users, nil
}
开发者ID:vishnuvr,项目名称:davine,代码行数:29,代码来源:user.go

示例2: searchHandler

func searchHandler(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	index, err := search.Open("Package")
	if err != nil {
		log.Print(err)
	}
	c := appengine.NewContext(r)
	packages := []*SearchResult{}
	for t := index.Search(c, vars["query"], nil); ; {
		var doc Package
		id, err2 := t.Next(&doc)
		if err2 == search.Done {
			break
		}
		if err2 != nil {
			log.Print(w, "Search error: %v\n", err2)
			break
		}
		log.Print(id)
		packages = append(packages, &SearchResult{
			Id:  id,
			Url: doc.Url,
		})
	}

	jsonPackages, err3 := json.Marshal(packages)
	if err3 != nil {
		http.Error(w, err3.Error(), http.StatusInternalServerError)
		return
	}
	w.Header().Set("Content-Type", "application/json")
	w.Write(jsonPackages)
}
开发者ID:hatched,项目名称:gopkg-api,代码行数:33,代码来源:server.go

示例3: debugIndex

func debugIndex(w http.ResponseWriter, r *http.Request) {
	context := appengine.NewContext(r)

	// Fetch document index.
	index, _ := search.Open(ImageIndex)
	num := 0
	for t := index.List(context, nil); ; {
		doc := &ImageDoc{}
		_, err := t.Next(doc)
		if err == search.Done {
			break
		}
		if err != nil {
			fmt.Fprintf(w, err.Error())
			break
		}
		fmt.Fprintf(w, doc.String())
		num++
	}

	fmt.Fprintf(w, "%d documents in index", num)

	updated := getLastUpdated(context)
	fmt.Fprintf(w, "%d last updated", updated)
}
开发者ID:jborak,项目名称:charityspotter,代码行数:25,代码来源:main.go

示例4: importHistory

func importHistory(c appengine.Context, commands []History) {

	log.Printf("Started delayed task")

	index, err := search.Open(HISTORY_INDEX)
	if err != nil {
		log.Printf("Could not connect to search service. %s", err.Error())
		return
	}
	ctr := 0
	for _, h := range commands {

		data := []byte(h.Command)
		docId := fmt.Sprintf("%x", md5.Sum(data))

		_, err = index.Put(c, docId, &h)
		if err != nil {
			return
		}

		ctr += 1

	}
	log.Printf("Finished delayed task. Imported %d", ctr)
}
开发者ID:rem7,项目名称:gae_history,代码行数:25,代码来源:hello.go

示例5: index

func index(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
	c := appengine.NewContext(r)

	index, err := search.Open(xkcdIndex)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	var x *Comic
	comicNum := r.FormValue("id")
	if comicNum != "" {
		iComicNum, _ := strconv.Atoi(comicNum)
		x, _ = Get(c, iComicNum)
	} else {
		x, _ = GetCurrent(c)
	}
	xSearch := &ComicSearch{
		strconv.Itoa(x.Num),
		x.Title,
		x.Img,
		x.Alt,
		x.Transcript,
	}

	id := strconv.Itoa(x.Num)
	_, err = index.Put(c, id, xSearch)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	w.WriteHeader(http.StatusNoContent)
}
开发者ID:chrishoffman,项目名称:xkcd-slack,代码行数:33,代码来源:index.go

示例6: backfill

func backfill(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
	c := appengine.NewContext(r)

	index, err := search.Open(xkcdIndex)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	current, _ := GetCurrent(c)
	for i := 1; i <= current.Num; i++ {
		// xcdc returns 404 with issue 404
		if i == 404 {
			continue
		}

		comicNum := strconv.Itoa(i)

		force := r.FormValue("force")
		if force != "yes" {
			var s ComicSearch
			err := index.Get(c, comicNum, &s)
			if err == nil {
				continue
			}
		}

		t := taskqueue.NewPOSTTask("/index", map[string][]string{"id": {comicNum}})
		if _, err := taskqueue.Add(c, t, ""); err != nil {
			http.Error(w, err.Error(), http.StatusInternalServerError)
			return
		}
	}
}
开发者ID:chrishoffman,项目名称:xkcd-slack,代码行数:34,代码来源:index.go

示例7: searchPut

func searchPut(w http.ResponseWriter, r *http.Request) {

	lg, b := loghttp.BuffLoggerUniversal(w, r)
	_ = b

	id := "PA6-5001"
	user := &User{
		Customer:  "Carl Corral",
		Comment:   "I am <em>riled up</em> text",
		Visits:    1,
		LastVisit: time.Now(),
		Birthday:  time.Date(1968, time.May, 19, 0, 0, 0, 0, time.UTC),
	}

	c := appengine.NewContext(r)

	index, err := search.Open("users")
	lg(err)

	ret_id, err := index.Put(c, id, user)
	lg(err)

	fmt.Fprint(w, "OK, saved "+ret_id+"\n\n")

	var u2 User
	err = index.Get(c, ret_id, &u2)
	lg(err)
	fmt.Fprint(w, "Retrieved document: ", u2)

}
开发者ID:aarzilli,项目名称:tools,代码行数:30,代码来源:fulltext_search.go

示例8: searchBooks

func searchBooks(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)

	// start search OMIT
	index, err := search.Open("Book") // HL
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	books := make([]*Book, 0, 10)
	t := index.Search(c, "Gopher Price >= 3000", nil) // HL
	for {
		var book Book
		_, err := t.Next(&book)
		if err == search.Done {
			break
		} else if err != nil {
			http.Error(w, err.Error(), http.StatusInternalServerError)
			return
		}
		books = append(books, &book)
	}
	// end search OMIT

	je := json.NewEncoder(w)
	if err := je.Encode(books); err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
}
开发者ID:knightso,项目名称:goslides,代码行数:31,代码来源:search.go

示例9: searchSlashCommandHandler

func searchSlashCommandHandler(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
	c := appengine.NewContext(r)

	text := r.FormValue("text")
	if text == "" {
		http.Error(w, "Missing required fields", http.StatusBadRequest)
		return
	}

	index, err := search.Open(xkcdIndex)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	var comicList []*ComicSearch
	for t := index.Search(c, text, nil); ; {
		var xkcd ComicSearch
		_, err := t.Next(&xkcd)
		if err == search.Done {
			break
		}
		if err != nil {
			http.Error(w, err.Error(), http.StatusInternalServerError)
			break
		}

		comicList = append(comicList, &xkcd)
	}

	sr := new(searchSlashCommandResponse)
	if len(comicList) == 0 {
		sr.Text = "EPOCH FAIL!"
	} else {
		n := rand.Intn(len(comicList))
		comic := comicList[n]

		attachment := &searchSlashCommandAttachment{
			Text:      comic.Alt,
			TitleLink: fmt.Sprintf("https://xkcd.com/%s/", comic.Num),
			Title:     fmt.Sprintf("%s (#%s)", comic.Title, comic.Num),
			ImageUrl:  comic.Img,
		}
		sr.Attachments = []*searchSlashCommandAttachment{attachment}
		sr.ResponseType = "in_channel"
	}
	rsp, _ := json.Marshal(sr)

	w.Header().Set("Content-Type", "application/json; charset=utf-8")
	fmt.Fprintf(w, string(rsp))

	logSearch(c, r.FormValue("user_name"), r.FormValue("channel_name"), r.FormValue("team_domain"), text)
}
开发者ID:chrishoffman,项目名称:xkcd-slack,代码行数:53,代码来源:search.go

示例10: getHistory

func getHistory(res http.ResponseWriter, req *http.Request) {

	password := req.URL.Query().Get("password")

	if password != os.Getenv("SERVER_PASSWORD") {
		http.Error(res, "uh oh", http.StatusForbidden)
		return
	}

	c := appengine.NewContext(req)

	index, err := search.Open(HISTORY_INDEX)
	if err != nil {
		http.Error(res, err.Error(), http.StatusInternalServerError)
		return
	}

	// options := search.SearchOptions{
	// 	Sort: &search.SortOptions{
	// 		Expressions: []search.SortExpression{
	// 			search.SortExpression{
	// 				Expr:    "",
	// 				Reverse: true,
	// 			},
	// 		},
	// 	},
	// }

	history := HistorySlice{}
	for t := index.List(c, nil); ; {

		var h History
		_, err := t.Next(&h)
		if err == search.Done {
			break
		}

		if err != nil {
			fmt.Fprintf(res, "Search error: %v\n", err)
			break
		}

		history = append(history, h)
	}

	sort.Sort(history)

	for _, h := range history {
		fmt.Fprintf(res, "%v\n", h.Command)
	}

}
开发者ID:rem7,项目名称:gae_history,代码行数:52,代码来源:hello.go

示例11: GetIndex

func (r *WifiSpotRepository) GetIndex() *search.Index {
	// if r.Index == nil {
	index, err := search.Open("wifi_spots")
	if err != nil {
		panic(err.Error())
	}
	// r.Index = index
	return index
	/**
	} else {
		return r.Index
	}
	**/
}
开发者ID:sousk,项目名称:sandbox-gcp-go,代码行数:14,代码来源:app.go

示例12: addToIndex

func addToIndex(p *Package, w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)

	index, err1 := search.Open("Package")
	if err1 != nil {
		http.Error(w, err1.Error(), http.StatusInternalServerError)
		return
	}
	id, err2 := index.Put(c, "", p)
	if err2 != nil {
		http.Error(w, err2.Error(), http.StatusInternalServerError)
		return
	}
	log.Print("index id " + id)
}
开发者ID:hatched,项目名称:gopkg-api,代码行数:15,代码来源:server.go

示例13: IndexPortal

func IndexPortal(c appengine.Context, portal Portal) error {
	index, err := search.Open("portals")
	if err != nil {
		return err
	}
	var sp SearchPortal
	sp.ToIndex(portal)
	_, err = index.Put(c, portal.Id, &sp)
	if err != nil {
		c.Infof("Error al indexar portal %s, id: %s", portal.Title, portal.Id)
		//http.Error(w, err.Error(), http.StatusInternalServerError)
		return err
	}
	return nil
}
开发者ID:jquinter,项目名称:gogress,代码行数:15,代码来源:search.go

示例14: DeleteHandler

func DeleteHandler(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)
	index, _ := search.Open("portals")

	for t := index.List(c, nil); ; {
		var portal Portal
		id, err := t.Next(&portal)
		if err == search.Done {
			break
		}
		if err != nil {
			return
		}
		index.Delete(c, id)
		c.Infof("deleting index %s", id)
	}
}
开发者ID:jquinter,项目名称:gogress,代码行数:17,代码来源:search.go

示例15: handleSearchDelete

func handleSearchDelete(rw http.ResponseWriter, req *http.Request) {
	c := appengine.NewContext(req)
	getQuery := req.URL.Query()
	indexName := getQuery.Get("index")
	id := getQuery.Get("id")
	index, err := search.Open(indexName)
	if err != nil {
		jsonReplyMap(rw, http.StatusInternalServerError, "error", err.Error())
		return
	}
	err = index.Delete(c, id)
	if err != nil {
		jsonReplyMap(rw, http.StatusInternalServerError, "error", err.Error())
		return
	}
	jsonReplyMap(rw, http.StatusOK, "index", indexName, "id", id)
}
开发者ID:miolini,项目名称:slackhistorybot,代码行数:17,代码来源:search_delete.go


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