// Search searches for a set of tags in the database to find a policy match
343078
func (m *PolicyDB) Search(tags *policy.TagStore) (int, interface{}) {

	count := make([]int, m.numberOfPolicies+1)

	skip := make([]bool, m.numberOfPolicies+1)

	// Disable all policies that fail the not key exists
	copiedTags := tags.GetSlice()
	var k, v string

	for _, t := range copiedTags {
		if err := m.tagSplit(t, &k, &v); err != nil {
			continue
		}
		for _, policy := range m.notStarTable[k] {
			skip[policy.index] = true
		}
	}

	// Go through the list of tags
	for _, t := range copiedTags {

		// Search for matches of t (tag id)
		if index, action := searchInMapTable(m.equalIDMapTable[t], count, skip); index >= 0 {
			return index, action
		}

		if err := m.tagSplit(t, &k, &v); err != nil {
			continue
		}

		// Search for matches of k=v
		if index, action := searchInMapTable(m.equalMapTable[k][v], count, skip); index >= 0 {
			return index, action
		}

		// Search for matches in prefixes
		for _, i := range m.equalPrefixes[k] {
			if i <= len(v) {
				if index, action := searchInMapTable(m.equalMapTable[k][v[:i]], count, skip); index >= 0 {
					return index, action
				}
			}
		}

		// Parse all of the policies that have a key that matches the incoming tag key
		// and a not equal operator and that has a not match rule
		for value, policies := range m.notEqualMapTable[k] {
			if v == value {
				continue
			}

			if index, action := searchInMapTable(policies, count, skip); index >= 0 {
				return index, action
			}
		}
	}

	if m.defaultNotExistsPolicy != nil && !skip[m.defaultNotExistsPolicy.index] {
		return m.defaultNotExistsPolicy.index, m.defaultNotExistsPolicy.actions
	}

	return -1, nil
}
93636
func (n *Node) search(qname string) (*Node, bool) {
	for n != nil {
		switch c := Less(n.Elem, qname); {
		case c == 0:
			return n, true
		case c < 0:
			n = n.Left
		default:
			n = n.Right
		}
	}

	return n, false
}
370130
func (f *FST) Search(aut Automaton, startKeyInclusive, endKeyExclusive []byte) (*FSTIterator, error) {
	return newIterator(f, startKeyInclusive, endKeyExclusive, aut)
}
1268468
func (idx *Indexer) Search(ctx context.Context, uid gregor1.UID, query, origQuery string,
	opts chat1.SearchOpts, hitUICh chan chat1.ChatSearchInboxHit, indexUICh chan chat1.ChatSearchIndexStatus) (res *chat1.ChatSearchInboxResults, err error) {
	defer idx.Trace(ctx, func() error { return err }, "Indexer.Search")()
	defer func() {
		// get a selective sync to run after the search completes even if we
		// errored.
		idx.PokeSync(ctx)

		if hitUICh != nil {
			close(hitUICh)
		}
		if indexUICh != nil {
			close(indexUICh)
		}
	}()
	if idx.G().GetEnv().GetDisableSearchIndexer() {
		idx.Debug(ctx, "Search: Search indexer is disabled, results will be inaccurate.")
	}

	idx.CancelSync(ctx)
	sess := newSearchSession(query, origQuery, uid, hitUICh, indexUICh, idx, opts)
	return sess.run(ctx)
}
345246
func (c *Verification) Search(m *VerifySearchRequest) (*VerifySearchResponse, error) {
	var verifySearchResponse *VerifySearchResponse

	if !c.client.useOauth {
		m.apiKey = c.client.apiKey
		m.apiSecret = c.client.apiSecret
	}

	var r *http.Request
	buf, err := json.Marshal(m)
	if err != nil {
		return nil, errors.New("invalid message struct - unable to convert to JSON")
	}

	b := bytes.NewBuffer(buf)
	r, err = http.NewRequest("POST", apiRootv2+"/verify/search/json", b)
	if err != nil {
		return nil, err
	}

	r.Header.Add("Accept", "application/json")
	r.Header.Add("Content-Type", "application/json")

	resp, err := c.client.HTTPClient.Do(r)
	if err != nil {
		return nil, err
	}

	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return nil, err
	}

	err = json.Unmarshal(body, &verifySearchResponse)
	if err != nil {
		return nil, err
	}

	return verifySearchResponse, nil
}
365630
func (treeNode *TreeNode) Search(patternNode PatternNode) []*TreeNode {
	results := []*TreeNode{}

	// Current node
	if treeNode.compare(patternNode) {
		results = append(results, treeNode)
	}

	// Current node's children
	for _, child := range treeNode.Children {
		for _, subResult := range child.Search(patternNode) {
			results = append(results, subResult)
		}
	}

	return results
}
434876
func Search(searchBy SearchKey, propertyName string) (*SearchResult, error) {
	req, err := client.NewJSONRequest(
		Config,
		"POST",
		"/papi/v1/search/find-by-value",
		map[string]string{(string)(searchBy): propertyName},
	)

	if err != nil {
		return nil, err
	}

	res, err := client.Do(Config, req)

	if client.IsError(res) {
		return nil, client.NewAPIError(res)
	}


	results := &SearchResult{}
	if err = client.BodyJSON(res, results); err != nil {
		return nil, err
	}

	if len(results.Versions.Items) == 0 {
		return nil, nil
	}

	return results, nil
}
1173705
func TagsQueryFilter(query ...string) Filter {
	tagQl := strings.Join(query, " AND ")
	return Param("tags", tagQl)
}
655285
func TagsFilter(t map[string]string) Filter {
	j := tagsEncoder(t, false)
	return Param("tags", j)
}
588481
func (f *Facade) SearchRegistryLibraryByTag(ctx datastore.Context, library, tagname string) ([]registry.Image, error) {
	defer ctx.Metrics().Stop(ctx.Metrics().Start("Facade.SearchRegistryLibraryByTag"))
	rImages, err := f.registryStore.SearchLibraryByTag(ctx, library, tagname)
	if err != nil {
		return nil, err
	}
	return rImages, nil
}
731278
func (search *Search) Tags(tag string) (*SearchResult, error) {
	insta := search.inst
	body, err := insta.sendRequest(
		&reqOptions{
			Endpoint: urlSearchTag,
			Query: map[string]string{
				"is_typeahead": "true",
				"rank_token":   insta.rankToken,
				"q":            tag,
			},
		},
	)
	if err != nil {
		return nil, err
	}

	res := &SearchResult{}
	err = json.Unmarshal(body, res)
	return res, err
}
538511
func (c *Client) Search(path, query string) (list []os.FileInfo, err error) {
	var start uint64

more:
	out, err := c.Files.Search(&dropbox.SearchInput{
		Mode:  dropbox.SearchModeFilename,
		Path:  path,
		Query: query,
		Start: start,
	})

	if err != nil {
		return
	}

	for _, match := range out.Matches {
		list = append(list, &FileInfo{match.Metadata})
	}

	if out.More {
		start = out.Start
		goto more
	}

	return
}
1373177
func (q *QueryDsl) Search(searchFor string) *QueryDsl {
	//I don't think this is right, it is not a filter.query, it should be q query?
	qs := NewQueryString("", "")
	q.QueryEmbed.Qs = &qs
	q.QueryEmbed.Qs.Query = searchFor
	return q
}
1187458
func (c *FakeEvents) Search(scheme *runtime.Scheme, objOrRef runtime.Object) (*v1.EventList, error) {
	action := core.NewRootListAction(eventsResource, eventsKind, metav1.ListOptions{})
	if c.ns != "" {
		action = core.NewListAction(eventsResource, eventsKind, c.ns, metav1.ListOptions{})
	}
	obj, err := c.Fake.Invokes(action, &v1.EventList{})
	if obj == nil {
		return nil, err
	}

	return obj.(*v1.EventList), err
}
782875
func (n *node) search(line string) *Template {
	separator := n.separator
	return n.recursiveSearch(strings.Split(line, separator))
}
570039
func (m *GormIdentityRepository) Search(ctx context.Context, q string, start int, limit int) ([]Identity, int, error) {

	db := m.db.Model(&Identity{})
	db = db.Offset(start)
	db = db.Limit(limit)
	// FIXME : returning the identities.id just for the sake of consistency with the other User APIs.
	db = db.Select("count(*) over () as cnt2 ,identities.id as identity_id,identities.username,users.*")
	db = db.Joins("LEFT JOIN users ON identities.user_id = users.id")
	db = db.Where("LOWER(users.full_name) like ?", "%"+strings.ToLower(q)+"%")
	db = db.Or("users.email like ?", "%"+strings.ToLower(q)+"%")
	db = db.Or("lower(identities.username) like ?", "%"+strings.ToLower(q)+"%")
	db = db.Group("identities.id,identities.username,users.id")
	//db = db.Preload("user")

	rows, err := db.Rows()
	defer closeable.Close(ctx, rows)
	if err != nil {
		return nil, 0, err
	}

	result := []Identity{}
	value := Identity{}
	columns, err := rows.Columns()
	if err != nil {
		return nil, 0, errors.NewInternalError(ctx, err)
	}

	// need to set up a result for Scan() in order to extract total count.
	var count int
	var identityID string
	var identityUsername string
	var ignore interface{}
	columnValues := make([]interface{}, len(columns))

	for index := range columnValues {
		columnValues[index] = &ignore
	}
	columnValues[0] = &count
	// FIXME When our User Profile endpoints start giving "user" response
	// instead of "identity" response, the identity.ID would be less relevant.

	for rows.Next() {
		columnValues[1] = &identityID
		columnValues[2] = &identityUsername
		db.ScanRows(rows, &value.User)

		if err = rows.Scan(columnValues...); err != nil {
			return nil, 0, errors.NewInternalError(ctx, err)
		}

		value.ID, err = uuid.FromString(identityID)
		if err != nil {
			return nil, 0, errors.NewInternalError(ctx, err)
		}

		value.Username = identityUsername

		result = append(result, value)
	}

	return result, count, nil
}
190612
func (i *ComponentInput) Search() error {
	if i.Searcher == nil {
		return ErrNoMatch{Value: i.Value, Qualifier: "no searcher defined"}
	}
	matches, err := i.Searcher.Search(false, i.Value)
	if matches != nil {
		i.SearchMatches = matches
	}
	return errors.NewAggregate(err)
}