func (this *ThisAllBusinesses) Search(pattern string) {
	m := gofuzz.New()
	this.filteredBusinesses = nil

	for _, business := range this.allBusinesses {
		pos, score := m.Search(business.Name, pattern, 0)
		if pos == 0 {
			if score == 0 {
				this.filteredBusinesses = append(this.filteredBusinesses, business)
			}
		}
	}
}
func (this *ThisAllCategories) Search(pattern string) {
	m := gofuzz.New()
	this.filteredCategories = nil

	for _, category := range this.allCategories {
		pos, score := m.Search(category.Category, pattern, 0)
		if pos == 0 {
			if score == 0 {
				this.filteredCategories = append(this.filteredCategories, category)
			}
		}
	}
}
Beispiel #3
0
func search(q string, n int) *Items {
	items := NewItems()
	q = strings.TrimSpace(q)
	if len(q) < 3 {
		return items
	}
	names := make(map[string]struct{})
	fuzz := gofuzz.New()
	fuzz.Threshold = 0.2
	scores = make([]float64, 0)
LOOP:
	for cat, symbols := range chars {
		for _, row := range symbols {
			pos, score := fuzz.Search(row[0], q, 0)
			if pos != -1 {
				if _, found := names[row[0]]; found {
					continue
				}
				names[row[0]] = struct{}{}
				scores = append(scores, score)
				i := NewItem(row[0])
				i.SetSubtitle(fmt.Sprintf("%s %X", row[1], []rune(row[1])[0]))
				i.SetIcon(iconPath(cat, row[1]))
				i.Run("showChar", row[0], row[1])
				i.SetAction("unisym")
				i.SetActionReturnsItems(true)
				i.SetActionRunsInBackground(false)
				items.Add(i)
				n -= 1
				if n == 0 {
					break LOOP
				}
			}
		}
	}
	sort.Sort(byScore(*items))
	return items
}
Beispiel #4
0
func searchPosts(posts []*pinboard.Post, query string) []*pinboard.Post {
	var out []*pinboard.Post
	scores = make([]float64, 0)
	f := gofuzz.New()
	f.Threshold = 0.4
	if len(query) > f.MaxBits {
		query = query[:f.MaxBits]
	}

	for _, post := range posts {
		totalScore := float64(1)
		var score float64
		_, score = f.Search(post.Title, query, 0)
		if score < totalScore {
			totalScore = score
		}
		_, score = f.Search(post.URL, query, 0)
		if score < totalScore {
			totalScore = score
		}
		_, score = f.Search(post.Tag, query, 0)
		if score < totalScore {
			totalScore = score
		}
		_, score = f.Search(post.Description, query, 0)
		if score < totalScore {
			totalScore = score
		}
		if totalScore < 1 {
			out = append(out, post)
			scores = append(scores, totalScore)
		}
	}

	sort.Sort(byScore(out))
	return out
}