Ejemplo n.º 1
0
// Query product
func (p *Suggest) Onproduct() *exit.Exit {
	var query = strings.TrimSpace(p.Query)
	if query == "" {
		return exit.Json("{service:'no suggestions'}")
	}

	// search
	suggest.EnsureLoaded()
	items, err := suggest.Lookup(query, suggest.Product)
	if err != nil {
		return exit.Error(err)
	}

	// translate
	sj := &ProductSuggestions{Query: query}
	sj.Suggestions = make([]ProductSuggestionItem, len(items))
	for idx, item := range items {
		sj.Suggestions[idx] = ProductSuggestionItem{
			Id:          item.Id,
			ProductId:   item.SN,
			Name:        item.Text,
			QueryString: item.QuickString,
			// Data: fmt.Sprint(item.Id),
			// Value: item.QuickString + "||" + item.Text,
		}
	}

	return exit.MarshalJson(sj)
}
Ejemplo n.º 2
0
func (p *Suggest) Setup() *exit.Exit {
	if strings.TrimSpace(p.Query) == "" {
		return exit.Json("{service:'/service'}")
	}
	suggest.EnsureLoaded()

	// search
	items, err := suggest.Lookup(p.Query, p.Type)
	if err != nil {
		return exit.Error(err)
	}
	// translate
	sj := &SuggestJson{Query: p.Query}
	sj.Suggestions = make([]SuggestionJsonItem, len(items))
	for idx, item := range items {
		// fmt.Println("item.SN:", item.Id, item.SN)
		sj.Suggestions[idx] = SuggestionJsonItem{
			Value: item.QuickString + "||" + item.Text,
			Data:  fmt.Sprint(item.Id),
			Id:    item.SN,
			Type:  item.Type,
		}
	}

	return exit.MarshalJson(sj)
}