10 examples of 'golang search' in Go

Every line of 'golang search' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Go code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
14func (c ChannelRepository) Search(search string) ([]models.ChannelModel, error) {
15 var channels []models.ChannelModel
16 var err error
17 if err := app.DB.Where("name LIKE ?", "%"+search+"%").Find(&channels).Error; err != nil {
18 return channels, err
19 }
20
21 return channels, err
22}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

109func (b *Batch) search(from, size, page int) error {
110 p := map[string]interface{}{
111 "query": b.Opts.Batch.Query,
112 "from": from,
113 "size": size,
114 }
115
116 res, _, err := b.Post("/v1/collection/"+b.Opts.Batch.CollectionID+"/search", p)
117
118 results := &SearchResult{}
119 if err := json.Unmarshal(res, results); err != nil {
120 b.Log.Fatalf("Failed to search collection: %s", err)
121 }
122
123 // Our JSON output should be human readable
124 m, err := json.MarshalIndent(results.Data, "", " ")
125 if err != nil {
126 b.Log.Fatalf("Could not display search results: %s", err)
127 }
128
129 // Display JSON results
130 fmt.Println(string(m))
131
132 // Total is the total number of results for the entire query, not the page
133 if results.Total > (from + PageSize) {
134 page++
135
136 nextPageSize := PageSize
137 remaining := results.Total - (page * PageSize)
138 if remaining < PageSize {
139 nextPageSize = remaining
140 }
141
142 fmt.Printf("--- Press [Enter] for more %d results, %d results total remaining ---\n", nextPageSize, remaining)
143
144 input, _ := bufio.NewReader(os.Stdin).ReadByte()
145 if input == EnterKey {
146 return b.search(from+PageSize, PageSize, page)
147 }
148 }
149
150 return nil
151}
76func (itemSearch *ItemSearch) Search(keywords string, maxiumNumberOfResults int) []Result {
77
78 // routes
79 if isRouteSearch(keywords) {
80 routeComponents := strings.Replace(keywords, "/", " ", -1)
81 return itemSearch.routesFullTextIndex.Search(routeComponents, maxiumNumberOfResults)
82 }
83
84 // items
85 return itemSearch.itemContentFullTextIndex.Search(keywords, maxiumNumberOfResults)
86}
140func (b *GetParticipantsQueryBuilder) Search(paramQ string) *GetParticipantsQueryBuilder {
141 b.req.Filter = &tg.ChannelParticipantsSearch{
142 Q: paramQ,
143 }
144 return b
145}
78func (*userDao) Search(key string) ([]model.User, error) {
79 var users []model.User
80 key = "%" + key + "%"
81 err := db.DB.Where("phone_number like ? or nickname like ?", key, key).Find(&users).Error
82 if err != nil {
83 return nil, gerrors.WrapError(err)
84 }
85 return users, nil
86}
118func (n *RoleEndpoint) Search(query string, limit, offset int) (result []*m.Role, total int64, err error) {
119
120 result, total, err = n.adaptors.Role.Search(query, limit, offset)
121
122 return
123}
204func (n *ScriptEndpoint) Search(query string, limit, offset int) (devices []*m.Script, total int64, err error) {
205
206 devices, total, err = n.adaptors.Script.Search(query, limit, offset)
207
208 return
209}
65func (n *WorkflowScenarioEndpoint) Search(query string, limit, offset int) (result []*m.WorkflowScenario, total int64, err error) {
66
67 result, total, err = n.adaptors.WorkflowScenario.Search(query, limit, offset)
68
69 return
70}
22func (c *Client) Search(options *SearchOptions) (res []*je.Job, err error) {
23 url := fmt.Sprintf("%s/search", c.url)
24
25 filter := options.Filter
26
27 switch {
28 case filter.ID != "":
29 url += fmt.Sprintf("/%s", filter.ID)
30 case filter.Name != "":
31 url += fmt.Sprintf("?q=name:%s", filter.Name)
32 case filter.State != "":
33 url += fmt.Sprintf("?q=state:%d", je.ParseState(filter.State))
34 }
35
36 return c.request("GET", url, nil)
37}
81func (r *catalogRepo) Search(title string) ([]catalog.Book, error) {
82 books := make([]catalog.Book, 0)
83 db := r.db.New()
84 q := fmt.Sprintf("%%%s%%", title)
85 if err := db.Where("title ILIKE ?", q).Find(&books).Error; err != nil {
86 return books, err
87 }
88 return books, nil
89}

Related snippets