// MSearchHelp ...
354066
func (cm AsStandard) MSearchHelp(resource string) *metadata.MSearchHelp {
	msh := metadata.MSearchHelp{}
	mi := metadata.MISearchHelp
	for _, cd := range cm.Elements[mi.Name] {
		if cd.Attr["Resource"] != resource {
			continue
		}
		metadata.FieldTransfer(cd.Attr).To(&msh)
		for _, entry := range cd.Entries() {
			tmp := metadata.SearchHelp{}
			entry.SetFields(&tmp)
			msh.SearchHelp = append(msh.SearchHelp, tmp)
		}
	}
	return &msh
}
1124839
func (cmd *CLI) defineHelp() {
	if _, ok := cmd.flags["help"]; !ok {
		cmd.DefineBoolFlag("help", false, "show help and exit")
		cmd.flagHelp = cmd.flags["help"]
		if _, ok := cmd.aliases['h']; !ok {
			cmd.AliasFlag('h', "help")
		}
	}
}
67228
func (r *SearchRequest) SearchSource(searchSource *SearchSource) *SearchRequest {
	if searchSource == nil {
		r.searchSource = NewSearchSource()
		return r
	}
	r.searchSource = searchSource
	return r
}
288006
func resultTypeHelp(xT descLookupFunc, rt reflect.Type, fieldDescKey string) string {
	// Generate the JSON example for the result type.
	results, isComplex := reflectTypeToJSONExample(xT, rt, 0, fieldDescKey)

	// When this is a primitive type, add the associated JSON type and
	// result description into the final string, format it accordingly,
	// and return it.
	if !isComplex {
		return fmt.Sprintf("%s (%s) %s", results[0],
			reflectTypeToJSONType(xT, rt), xT(fieldDescKey))
	}

	// At this point, this is a complex type that already has the JSON types
	// and descriptions in the results.  Thus, use a tab writer to nicely
	// align the help text.
	var formatted bytes.Buffer
	w := new(tabwriter.Writer)
	w.Init(&formatted, 0, 4, 1, ' ', 0)
	for i, text := range results {
		if i == len(results)-1 {
			fmt.Fprintf(w, text)
		} else {
			fmt.Fprintln(w, text)
		}
	}
	w.Flush()
	return formatted.String()
}
814334
func (s MultiSimpleSearcher) Search(precise bool, terms ...string) (ComponentMatches, []error) {
	var errs []error
	componentMatches := ComponentMatches{}
	for _, searcher := range s {
		matches, err := searcher.Search(precise, terms...)
		if len(err) > 0 {
			errs = append(errs, err...)
			continue
		}
		componentMatches = append(componentMatches, matches...)
	}
	sort.Sort(ScoredComponentMatches(componentMatches))
	return componentMatches, errs
}
747249
func markdownHelper(body string) template.HTML {
	b := github_flavored_markdown.Markdown([]byte(body))
	return template.HTML(b)
}
1301158
func PrintHelp(flagMap map[string]reflect.StructField, defaultValmap map[string]reflect.Value, parsers map[reflect.Type]parse.Parser) error {
	return PrintHelpWithCommand(flagMap, defaultValmap, parsers, nil, nil)
}
64891
func (this *Context) FindAll(re interface{}) Collection {
    r := getRegexp(re)

    matches := r.FindAllSubmatch(this.Bytes(), -1)

    names := make(map[string]int)

    for k, v := range r.SubexpNames() {
        if v != "" {
            names[v] = k
        }
    }

    result := make(Collection, len(matches))
    for i, match := range matches {
        result[i] = &Context {
            Parent: this,
            List: match,
            Names: names,
        }
    }

    return result
}
375751
func methodHelp(xT descLookupFunc, rtp reflect.Type, defaults map[int]reflect.Value, method string, resultTypes []interface{}) string {
	// Start off with the method usage and help synopsis.
	help := fmt.Sprintf("%s\n\n%s\n", methodUsageText(rtp, defaults, method),
		xT(method+"--synopsis"))

	// Generate the help for each argument in the command.
	if argText := argHelp(xT, rtp, defaults, method); argText != "" {
		help += fmt.Sprintf("\n%s:\n%s", xT("help-arguments"),
			argText)
	} else {
		help += fmt.Sprintf("\n%s:\n%s\n", xT("help-arguments"),
			xT("help-arguments-none"))
	}

	// Generate the help text for each result type.
	resultTexts := make([]string, 0, len(resultTypes))
	for i := range resultTypes {
		rtp := reflect.TypeOf(resultTypes[i])
		fieldDescKey := fmt.Sprintf("%s--result%d", method, i)
		if resultTypes[i] == nil {
			resultText := xT("help-result-nothing")
			resultTexts = append(resultTexts, resultText)
			continue
		}

		resultText := resultTypeHelp(xT, rtp.Elem(), fieldDescKey)
		resultTexts = append(resultTexts, resultText)
	}

	// Add result types and descriptions.  When there is more than one
	// result type, also add the condition which triggers it.
	if len(resultTexts) > 1 {
		for i, resultText := range resultTexts {
			condKey := fmt.Sprintf("%s--condition%d", method, i)
			help += fmt.Sprintf("\n%s (%s):\n%s\n",
				xT("help-result"), xT(condKey), resultText)
		}
	} else if len(resultTexts) > 0 {
		help += fmt.Sprintf("\n%s:\n%s\n", xT("help-result"),
			resultTexts[0])
	} else {
		help += fmt.Sprintf("\n%s:\n%s\n", xT("help-result"),
			xT("help-result-nothing"))
	}
	return help
}
176350
func (c *Client) HelpRoot() (string, error) {
	if err := c.condDiscovery(); err != nil {
		return "", err
	}
	if c.helpRoot == "" {
		return "", ErrNoHelpRoot
	}
	return c.helpRoot, nil
}
606785
func (cmd *Cmd) help(line string) (stop bool) {
	fmt.Println("")

	if line == "--all" {
		fmt.Println("Available commands (use 'help <topic>'):")
		fmt.Println("================================================================")
		for _, c := range cmd.commandNames {
			fmt.Printf("%v: ", c)
			cmd.Commands[c].HelpFunc()
		}
	} else if len(line) == 0 {
		fmt.Println("Available commands (use 'help <topic>'):")
		fmt.Println("================================================================")

		max := 0

		for _, c := range cmd.commandNames {
			if len(c) > max {
				max = len(c)
			}
		}

		tp := pretty.NewTabPrinter(80 / (max + 1))
		tp.TabWidth(max + 1)

		for _, c := range cmd.commandNames {
			tp.Print(c)
		}
		tp.Println()
	} else {
		if c, ok := cmd.Commands[line]; ok {
			c.HelpFunc()
		} else {
			fmt.Println("unknown command or function")
		}
	}

	fmt.Println("")
	return
}
794812
func (maildir *Maildir) Search(kind, query string, start, limit int) (*data.Messages, int, error) {
	query = strings.ToLower(query)
	var filteredMessages = make([]data.Message, 0)

	var matched int

	err := filepath.Walk(maildir.Path, func(path string, info os.FileInfo, err error) error {
		if limit > 0 && len(filteredMessages) >= limit {
			return errors.New("reached limit")
		}

		if info.IsDir() {
			return nil
		}

		msg, err := maildir.Load(info.Name())
		if err != nil {
			log.Println(err)
			return nil
		}

		switch kind {
		case "to":
			for _, t := range msg.To {
				if strings.Contains(strings.ToLower(t.Mailbox+"@"+t.Domain), query) {
					if start > matched {
						matched++
						break
					}
					filteredMessages = append(filteredMessages, *msg)
					break
				}
			}
		case "from":
			if strings.Contains(strings.ToLower(msg.From.Mailbox+"@"+msg.From.Domain), query) {
				if start > matched {
					matched++
					break
				}
				filteredMessages = append(filteredMessages, *msg)
			}
		case "containing":
			if strings.Contains(strings.ToLower(msg.Raw.Data), query) {
				if start > matched {
					matched++
					break
				}
				filteredMessages = append(filteredMessages, *msg)
			}
		}

		return nil
	})

	if err != nil {
		log.Println(err)
	}

	msgs := data.Messages(filteredMessages)
	return &msgs, len(filteredMessages), nil
}
924054
func (exp *explorerUI) Search(w http.ResponseWriter, r *http.Request) {
	// The ?search= query.
	searchStr := r.URL.Query().Get("search")

	// Strip leading and tailing whitespace.
	searchStr = strings.TrimSpace(searchStr)

	if searchStr == "" {
		exp.StatusPage(w, "search failed", "The search term was empty.",
			searchStr, ExpStatusBadRequest)
		return
	}

	// Attempt to get a block hash by calling GetBlockHash of WiredDB or
	// BlockHash of ChainDB to see if the URL query value is a block index. Then
	// redirect to the block page if it is.
	idx, err := strconv.ParseInt(searchStr, 10, 0)
	if err == nil {
		_, err = exp.blockData.GetBlockHash(idx)
		if err == nil {
			http.Redirect(w, r, "/block/"+searchStr, http.StatusPermanentRedirect)
			return
		}
		_, err = exp.explorerSource.BlockHash(idx)
		if err == nil {
			http.Redirect(w, r, "/block/"+searchStr, http.StatusPermanentRedirect)
			return
		}
		exp.StatusPage(w, "search failed", "Block "+searchStr+
			" has not yet been mined", searchStr, ExpStatusNotFound)
		return
	}

	// Call GetExplorerAddress to see if the value is an address hash and
	// then redirect to the address page if it is.
	address, _, addrErr := exp.blockData.GetExplorerAddress(searchStr, 1, 0)
	switch addrErr {
	case txhelpers.AddressErrorNoError, txhelpers.AddressErrorZeroAddress:
		http.Redirect(w, r, "/address/"+searchStr, http.StatusPermanentRedirect)
		return
	case txhelpers.AddressErrorWrongNet:
		// Status page will provide a link, but the address page can too.
		message := fmt.Sprintf("The address %v is valid on %s, not %s",
			searchStr, address.Net, exp.NetName)
		exp.StatusPage(w, wrongNetwork, message, searchStr, ExpStatusWrongNetwork)
		return
	}

	// This is be unnecessarily duplicative and possible very slow for a very
	// active addresss.
	addrHist, _, _ := exp.explorerSource.AddressHistory(searchStr,
		1, 0, dbtypes.AddrTxnAll)
	if len(addrHist) > 0 {
		http.Redirect(w, r, "/address/"+searchStr, http.StatusPermanentRedirect)
		return
	}

	// Remaining possibilities are hashes, so verify the string is a hash.
	if _, err = chainhash.NewHashFromStr(searchStr); err != nil {
		exp.StatusPage(w, "search failed",
			"Search string is not a valid hash or address: "+searchStr,
			"", ExpStatusNotFound)
		return
	}

	// Attempt to get a block index by calling GetBlockHeight to see if the
	// value is a block hash and then redirect to the block page if it is.
	_, err = exp.blockData.GetBlockHeight(searchStr)
	// If block search failed, check the aux DB, which has data for side chain
	// and orphaned blocks.
	if err != nil {
		_, err = exp.explorerSource.BlockHeight(searchStr)
	}
	if err == nil {
		http.Redirect(w, r, "/block/"+searchStr, http.StatusPermanentRedirect)
		return
	}

	// Call GetExplorerTx to see if the value is a transaction hash and then
	// redirect to the tx page if it is.
	tx := exp.blockData.GetExplorerTx(searchStr)
	if tx != nil {
		http.Redirect(w, r, "/tx/"+searchStr, http.StatusPermanentRedirect)
		return
	}

	// Also check the aux DB as it may have transactions from orphaned blocks.
	dbTxs, err := exp.explorerSource.Transaction(searchStr)
	if err != nil && err != sql.ErrNoRows {
		log.Errorf("Searching for transaction failed: %v", err)
	}
	if dbTxs != nil {
		http.Redirect(w, r, "/tx/"+searchStr, http.StatusPermanentRedirect)
		return
	}

	// Check if the search term references a proposal token.
	proposalInfo, err := exp.proposalsSource.ProposalByToken(searchStr)
	if err == nil && proposalInfo.RefID != "" {
		http.Redirect(w, r, "/proposal/"+proposalInfo.RefID, http.StatusPermanentRedirect)
		return
	}

	message := "The search did not find any matching address, block, transaction or proposal token: " + searchStr
	exp.StatusPage(w, "search failed", message, "", ExpStatusNotFound)
}
96759
func NewSearchResult(Matches []*SearchMatch, More bool, Start uint64) *SearchResult {
	s := new(SearchResult)
	s.Matches = Matches
	s.More = More
	s.Start = Start
	return s
}
206174
func (c *Client) Search(index, q string) (*RpbSearchQueryResp, error) {
	return c.search(nil, index, q)
}
88725
func (cm AsStandard) MUpdateHelp(resource string) *metadata.MUpdateHelp {
	muh := metadata.MUpdateHelp{}
	for _, cd := range cm.Elements[metadata.MIUpdateHelp.Name] {
		if cd.Attr["Resource"] != resource {
			continue
		}
		metadata.FieldTransfer(cd.Attr).To(&muh)
		for _, entry := range cd.Entries() {
			tmp := metadata.UpdateHelp{}
			entry.SetFields(&tmp)
			muh.UpdateHelp = append(muh.UpdateHelp, tmp)
		}
	}
	return &muh
}
1370973
func (m Message) IsHelpRequest() bool {
	return strings.HasSuffix(m.Message, "help") || strings.HasPrefix(m.Message, "help")
}