• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang search.Open函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: indexIdiomFullText

func indexIdiomFullText(c context.Context, idiom *Idiom, idiomKey *datastore.Key) error {
	index, err := gaesearch.Open("idioms")
	if err != nil {
		return err
	}
	// By using directly the idiom Key as docID,
	// we can leverage faster ID-only search later.
	docID := strconv.Itoa(idiom.Id)
	w, wTitle, wLead := idiom.ExtractIndexableWords()
	doc := &searchableIdiomDoc{
		IdiomKeyString: gaesearch.Atom(idiomKey.Encode()),
		IdiomID:        gaesearch.Atom(strconv.Itoa(idiom.Id)),
		Bulk:           strings.Join(w, " "),
		Langs:          implementedLanguagesConcat(idiom),
		TitleWords:     strings.Join(wTitle, " "),
		LeadWords:      strings.Join(wLead, " "),
	}
	doc.TitleOrLeadWords = doc.TitleWords + " " + doc.LeadWords
	_, err = index.Put(c, docID, doc)
	if err != nil {
		return err
	}

	// Also index each impl individually,
	// so we know what to highlight.
	indexImpl, err := gaesearch.Open("impls")
	if err != nil {
		return err
	}
	for _, impl := range idiom.Implementations {
		implDocID := fmt.Sprintf("%d_%d", idiom.Id, impl.Id)
		w := impl.ExtractIndexableWords()
		implDoc := &searchableImplDoc{
			Lang:    impl.LanguageName,
			IdiomID: gaesearch.Atom(strconv.Itoa(idiom.Id)),
			Bulk:    strings.Join(w, " "),
		}
		// Weird that the search API doesn't have batch queries.
		// TODO: index each impl concurrently?
		// TODO: index only last edited impl?
		_, err = indexImpl.Put(c, implDocID, implDoc)
		if err != nil {
			return err
		}
	}

	return nil
}
开发者ID:Deleplace,项目名称:programming-idioms,代码行数:48,代码来源:dataAccessorGaeSearch.go


示例2: handleGet

func handleGet(ctx context.Context, res http.ResponseWriter, criteria string) error {
	index, err := search.Open("Movies")
	if err != nil {
		return err
	}
	var iterator *search.Iterator
	if criteria == "" {
		iterator = index.List(ctx, nil)
	} else {
		iterator = index.Search(ctx, criteria, nil)
	}
	// slice of movie instances
	var movies []Movie
	for {
		var movie Movie
		_, err := iterator.Next(&movie)
		if err == search.Done {
			break
		}
		if err != nil {
			return err
		}
		movies = append(movies, movie)
	}
	json.NewEncoder(res).Encode(movies)
}
开发者ID:kaveenherath,项目名称:SummerBootCamp,代码行数:26,代码来源:handlers.go


示例3: handleSearch

func handleSearch(res http.ResponseWriter, req *http.Request) {
	ctx := appengine.NewContext(req)
	query := req.FormValue("q")
	model := &searchModel{
		Query: query,
	}

	index, err := search.Open("movies")
	if err != nil {
		http.Error(res, err.Error(), 500)
		return
	}

	iterator := index.Search(ctx, query, nil)
	for {
		var movie Movie
		_, err := iterator.Next(&movie)
		if err == search.Done {
			break
		} else if err != nil {
			http.Error(res, err.Error(), 500)
			return
		}
		model.Movies = append(model.Movies, movie)
	}

	err = tpl.ExecuteTemplate(res, "search", model)
	if err != nil {
		http.Error(res, err.Error(), 500)
		return
	}
}
开发者ID:RaviTezu,项目名称:GolangTraining,代码行数:32,代码来源:search.go


示例4: cleanup

func cleanup(s *testerator.Setup) error {
	c := s.Context
	sniff, ok := c.Value(&ctxKey).(*searchSniffer)
	if !ok {
		return ErrSetupRequired
	}

	indexNames := make(map[string]bool, 0)
	for _, req := range sniff.searchIndexDocumentRequests {
		indexNames[*req.GetParams().GetIndexSpec().Name] = true
	}
	for indexName, _ := range indexNames {
		idx, err := search.Open(indexName)
		if err != nil {
			return err
		}
		iter := idx.List(c, &search.ListOptions{IDsOnly: true})
		for {
			docID, err := iter.Next(nil)
			if err == search.Done {
				break
			} else if err != nil {
				return err
			}
			err = idx.Delete(c, docID)
			if err != nil {
				return err
			}
		}
	}

	sniff.searchIndexDocumentRequests = nil

	return nil
}
开发者ID:favclip,项目名称:testerator,代码行数:35,代码来源:search.go


示例5: indexIdiomCheatsheets

func indexIdiomCheatsheets(c context.Context, idiom *Idiom) error {
	index, err := gaesearch.Open("cheatsheets")
	if err != nil {
		return err
	}
	// Index each impl individually.
	for _, impl := range idiom.Implementations {
		docID := fmt.Sprintf("%d_%d", idiom.Id, impl.Id)
		doc := &cheatSheetLineDoc{
			Lang:                 gaesearch.Atom(impl.LanguageName),
			IdiomID:              gaesearch.Atom(strconv.Itoa(idiom.Id)),
			IdiomTitle:           gaesearch.Atom(idiom.Title),
			IdiomLeadParagraph:   gaesearch.Atom(idiom.LeadParagraph),
			ImplID:               gaesearch.Atom(strconv.Itoa(impl.Id)),
			ImplImportsBlock:     gaesearch.Atom(impl.ImportsBlock),
			ImplCodeBlock:        gaesearch.Atom(impl.CodeBlock),
			ImplCodeBlockComment: gaesearch.Atom(impl.AuthorComment),
		}
		// Weird that the search API doesn't have batch queries.
		// TODO: index each impl concurrently?
		_, err = index.Put(c, docID, doc)
		if err != nil {
			return err
		}
	}

	return nil
}
开发者ID:Deleplace,项目名称:programming-idioms,代码行数:28,代码来源:dataAccessorGaeSearch.go


示例6: unindexAll

func (a *GaeDatastoreAccessor) unindexAll(c context.Context) error {
	log.Infof(c, "Unindexing everything (from the text search indexes)")

	// Must remove 1 by 1 (Index has no batch methods)
	for _, indexName := range []string{
		"idioms",
		"impls",
		"cheatsheets",
	} {
		log.Infof(c, "Unindexing items of [%v]", indexName)
		index, err := gaesearch.Open(indexName)
		if err != nil {
			return err
		}
		it := index.List(c, &gaesearch.ListOptions{IDsOnly: true})
		for {
			docID, err := it.Next(nil)
			if err == gaesearch.Done {
				break
			}
			if err != nil {
				log.Errorf(c, "Error getting next indexed object to unindex: %v", err)
				return err
			}
			err = index.Delete(c, docID)
			if err != nil {
				return err
			}
		}
	}

	return nil
}
开发者ID:Deleplace,项目名称:programming-idioms,代码行数:33,代码来源:dataAccessorGaeSearch.go


示例7: handleNewMovie

func handleNewMovie(res http.ResponseWriter, req *http.Request) {
	ctx := appengine.NewContext(req)
	model := &newMovieModel{}

	if req.Method == "POST" {
		title := req.FormValue("title")
		summary := req.FormValue("summary")

		index, err := search.Open("movies")
		if err != nil {
			http.Error(res, err.Error(), 500)
			return
		}

		movie := &Movie{
			Title:   title,
			Summary: summary,
		}

		id, err := index.Put(ctx, "", movie)
		if err != nil {
			http.Error(res, err.Error(), 500)
			return
		}
		model.CreatedID = id
	}

	err := tpl.ExecuteTemplate(res, "new-movie", model)
	if err != nil {
		http.Error(res, err.Error(), 500)
		return
	}
}
开发者ID:RaviTezu,项目名称:GolangTraining,代码行数:33,代码来源:newmovie.go


示例8: getCheatSheet

func (a *GaeDatastoreAccessor) getCheatSheet(c context.Context, lang string, limit int) ([]cheatSheetLineDoc, error) {
	index, err := gaesearch.Open("cheatsheets")
	if err != nil {
		return nil, err
	}
	if limit == 0 {
		// Limit is not optional. 0 means zero result.
		return nil, nil
	}
	cheatLines := make([]cheatSheetLineDoc, 0, 200)
	query := "Lang:" + lang
	it := index.Search(c, query, &gaesearch.SearchOptions{
		Limit: limit,
	})
	for {
		var cheatLine cheatSheetLineDoc
		_, err := it.Next(&cheatLine)
		if err == gaesearch.Done {
			break
		}
		if err != nil {
			return nil, err
		}
		cheatLines = append(cheatLines, cheatLine)
	}
	// Sort by IdiomID asc, ImplID asc
	sort.Sort(cheatSheetLineDocs(cheatLines))
	return cheatLines, err
}
开发者ID:Deleplace,项目名称:programming-idioms,代码行数:29,代码来源:dataAccessorGaeSearch.go


示例9: PutDocument

func (b *InventorySearchBuilder) PutDocument(c context.Context, src *InventorySearch) (string, error) {
	index, err := search.Open(b.IndexName())
	if err != nil {
		return "", err
	}

	docID := ""
	if v, ok := interface{}(src).(smgutils.DocIDer); ok { // TODO can I shorten this cond expression?
		docID, err = v.DocID(c)
		if err != nil {
			return "", err
		}
		src.ID = docID
	}

	log.Debugf(c, "id: %#v, payload: %#v", docID, src)

	docID, err = index.Put(c, docID, src)
	if err != nil {
		return "", err
	}

	src.ID = docID

	return docID, nil
}
开发者ID:favclip,项目名称:smg,代码行数:26,代码来源:usecase_test.go


示例10: deleteIndex

func deleteIndex(c context.Context, id string) error {
	idx, err := search.Open("packages")
	if err != nil {
		return err
	}
	return idx.Delete(c, id)
}
开发者ID:golang,项目名称:gddo,代码行数:7,代码来源:indexae.go


示例11: handleSearch

func handleSearch(res http.ResponseWriter, req *http.Request) {
	ctx := appengine.NewContext(req)
	index, err := search.Open("movies")
	if err != nil {
		http.Error(res, err.Error(), 500)
		return
	}
	var movies []Movie
	q := ""
	switch req.FormValue("mode") {
	case "title":
		q = "Title = " + req.FormValue("q")
	case "description":
		q = "Description = " + req.FormValue("q")
	case "username":
		q = "Username = " + req.FormValue("q")
	}
	iterator := index.Search(ctx, q, nil)
	for {
		var movie Movie
		_, err := iterator.Next(&movie)
		if err == search.Done {
			break
		} else if err != nil {
			http.Error(res, err.Error(), 500)
			return
		}
		movies = append(movies, movie)
	}
	renderTemplate(res, req, "layout", PageModel{
		SearchResults: movies,
	})
}
开发者ID:robertsturner52,项目名称:search,代码行数:33,代码来源:search.go


示例12: indexCommentForSearch

// Indexes the comment with the specified key for search
func indexCommentForSearch(ctx context.Context, itemID TodoID) *MaybeError {
	index, err := search.Open("tada")
	var result = new(MaybeError)
	if err != nil {
		*result = E(err.Error())
	} else {
		item := readTodoItem(ctx, itemID)
		v := reflect.ValueOf(item)
		switch (*item).(type) {
		case E:
			result = item
		case TodoItem:
			log(fmt.Sprintf("Putting: %s of kind %s and %s", *item, v.Kind(), v.Elem().Kind()))
			titem := (*item).(TodoItem)
			_, err2 := index.Put(ctx, "", &titem)
			if err2 != nil {
				*result = E(err2.Error())
			} else {
				*result = Ok{}
			}
		case TodoID, Matches:
			*result = E("weird response from readTodoItem in indexCommentForSearch")
		}
	}
	return result
}
开发者ID:catamorphism,项目名称:tada,代码行数:27,代码来源:tada.go


示例13: searchImplIDs

func (a *GaeDatastoreAccessor) searchImplIDs(c context.Context, words, langs []string) (map[string]bool, error) {
	index, err := gaesearch.Open("impls")
	if err != nil {
		return nil, err
	}
	hits := map[string]bool{}
	query := "Bulk:(~" + strings.Join(words, " AND ~") + ")"
	if len(langs) > 0 {
		query += " AND Lang:(" + strings.Join(langs, " OR ") + ")"
	}
	// Beware of INVALID_REQUEST: The limit 1000000 must be between 1 and 1000
	limit := 1000
	// This is an *IDsOnly* search, where docID == idiomID_implID
	it := index.Search(c, query, &gaesearch.SearchOptions{
		Limit:   limit,
		IDsOnly: true,
	})
	for {
		docID, err := it.Next(nil)
		if err == gaesearch.Done {
			break
		}
		if err != nil {
			return nil, err
		}
		implIDStr := strings.Split(docID, "_")[1]
		hits[implIDStr] = true
	}
	return hits, nil
}
开发者ID:Deleplace,项目名称:programming-idioms,代码行数:30,代码来源:dataAccessorGaeSearch.go


示例14: executeIdiomKeyTextSearchQuery

func executeIdiomKeyTextSearchQuery(c context.Context, query string, limit int) (keystrings []string, err error) {
	// log.Infof(c, query)
	index, err := gaesearch.Open("idioms")
	if err != nil {
		return nil, err
	}
	if limit == 0 {
		// Limit is not optional. 0 means zero result.
		return nil, nil
	}
	idiomKeyStrings := make([]string, 0, limit)
	// This is an *IDsOnly* search, where docID == Idiom.Id
	it := index.Search(c, query, &gaesearch.SearchOptions{
		Limit:   limit,
		IDsOnly: true,
	})
	for {
		docID, err := it.Next(nil)
		if err == gaesearch.Done {
			break
		}
		if err != nil {
			return nil, err
		}
		idiomID, err := strconv.Atoi(docID)
		if err != nil {
			return nil, err
		}
		idiomKeyString := newIdiomKey(c, idiomID).Encode()
		idiomKeyStrings = append(idiomKeyStrings, idiomKeyString)
	}
	//log.Debugf(c, "Query [%v] yields %d results.", query, len(idiomKeyStrings))
	return idiomKeyStrings, nil
}
开发者ID:Deleplace,项目名称:programming-idioms,代码行数:34,代码来源:dataAccessorGaeSearch.go


示例15: DeleteByDocID

// DeleteByDocID from Index.
func (b *SampleSearchBuilder) DeleteByDocID(c context.Context, docID string) error {
	index, err := search.Open(b.IndexName())
	if err != nil {
		return err
	}

	return index.Delete(c, docID)
}
开发者ID:favclip,项目名称:smg,代码行数:9,代码来源:model_search.go


示例16: addToIndex

func addToIndex(ctx context.Context, mov *movie) error {
	idx, err := search.Open("movies")
	if err != nil {
		return err
	}

	_, err = idx.Put(ctx, "", mov)
	return err
}
开发者ID:CodingDance,项目名称:GolangTraining,代码行数:9,代码来源:search.go


示例17: unindex

func (a *GaeDatastoreAccessor) unindex(c context.Context, idiomID int) error {
	log.Infof(c, "Unindexing idiom %d", idiomID)

	docID := strconv.Itoa(idiomID)
	index, err := gaesearch.Open("idioms")
	if err != nil {
		return err
	}
	return index.Delete(c, docID)
}
开发者ID:Deleplace,项目名称:programming-idioms,代码行数:10,代码来源:dataAccessorGaeSearch.go


示例18: handleNewMovie

func handleNewMovie(res http.ResponseWriter, req *http.Request) {
	ctx := appengine.NewContext(req)
	model := &newMovieModel{}

	if req.Method == "POST" {
		title := req.FormValue("title")
		summary := req.FormValue("summary")
		poster, _, err := req.FormFile("poster")
		if err != nil {
			http.Error(res, err.Error(), 500)
			return
		}
		defer poster.Close()

		posterID, _ := uuid.NewV4()

		err = putFile(ctx, posterID.String(), poster)
		if err != nil {
			http.Error(res, err.Error(), 500)
			return
		}

		summary, err = renderMarkdown(ctx, summary)
		if err != nil {
			http.Error(res, err.Error(), 500)
			return
		}

		index, err := search.Open("movies")
		if err != nil {
			http.Error(res, err.Error(), 500)
			return
		}

		movie := &Movie{
			Title:    title,
			Summary:  search.HTML(summary),
			PosterID: posterID.String(),
		}

		id, err := index.Put(ctx, "", movie)
		if err != nil {
			http.Error(res, err.Error(), 500)
			return
		}
		model.CreatedID = id
	}

	err := tpl.ExecuteTemplate(res, "new-movie", model)
	if err != nil {
		http.Error(res, err.Error(), 500)
		return
	}
}
开发者ID:magj2006,项目名称:bootcamp-examples,代码行数:54,代码来源:newmovie.go


示例19: Index

func (s *TaskService) Index(ctx context.Context, t *Task) error {
	span := trace.FromContext(ctx).NewChild("trythings.task.Index")
	defer span.Finish()

	index, err := search.Open("Task")
	if err != nil {
		return err
	}
	_, err = index.Put(ctx, t.ID, t)
	if err != nil {
		return err
	}
	return nil
}
开发者ID:trythings,项目名称:trythings,代码行数:14,代码来源:task.go


示例20: handleGet

func handleGet(res http.ResponseWriter, req *http.Request) {
	ctx := appengine.NewContext(req)
	index, err := search.Open("example")
	if err != nil {
		http.Error(res, err.Error(), 500)
		return
	}
	var document Document
	err = index.Get(ctx, "7edf8426-e953-4378-8c1e-b2ad311356bb", &document)
	if err != nil {
		http.Error(res, err.Error(), 500)
		return
	}
	fmt.Fprintf(res, "%v", document)
}
开发者ID:magj2006,项目名称:bootcamp-examples,代码行数:15,代码来源:search.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang taskqueue.Add函数代码示例发布时间:2022-05-28
下一篇:
Golang memcache.Set函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap