示例#1
0
func (s *searchCmd) run(args []string) error {
	index, err := s.buildIndex()
	if err != nil {
		return err
	}

	if len(args) == 0 {
		s.showAllCharts(index)
		return nil
	}

	q := strings.Join(args, " ")
	res, err := index.Search(q, searchMaxScore, s.regexp)
	if err != nil {
		return nil
	}
	search.SortScore(res)

	fmt.Fprintln(s.out, s.formatSearchResults(res))

	return nil
}
示例#2
0
func (s *searchCmd) showAllCharts(i *search.Index) {
	res := i.All()
	search.SortScore(res)
	fmt.Fprintln(s.out, s.formatSearchResults(res))
}