<commit_before>package main

import "sort"
import "sync"

type View struct {
	Height int
	Query  string
	Rows   []string

	index int
}

func (v *View) Index() int {
	return v.index
}

func (v *View) Selected() string {
	return v.Rows[v.index]
}

func (v *View) Down() {
	if v.index < len(v.Rows)-1 {
		v.index++
	}
}

func (v *View) Up() {
	if v.index > 0 {
		v.index--
	}
}

type Picker struct {
	all     []Candidate
	visible int
}

func NewPicker(candidates []Candidate, visible int) *Picker {

	return &Picker{
		all:     candidates,
		visible: visible,
	}
}

type Candidate struct {
	value string
	score float64
}

func NewCandidate(s string) Candidate {
	return Candidate{
		value: s,
		score: 1.0,
	}
}

type CandidateSlice []Candidate

func (cs CandidateSlice) Len() int           { return len(cs) }
func (cs CandidateSlice) Swap(i, j int)      { cs[i], cs[j] = cs[j], cs[i] }
func (cs CandidateSlice) Less(i, j int) bool { return cs[i].score > cs[j].score }

func (p *Picker) Answer(query string) *View {
	var wg sync.WaitGroup
	wg.Add(len(p.all))
	for i := range p.all {
		candidate := &p.all[i]
		go func(c *Candidate) {
			c.score = Score(c.value, query)
			wg.Done()
		}(candidate)
	}
	wg.Wait()

	sort.Sort(CandidateSlice(p.all))

	lines := []string{}
	for i := 0; i < p.visible; i++ {
		if p.all[i].score == 0.0 {
			break
		}
		lines = append(lines, p.all[i].value)
	}

	return &View{
		index:  0,
		Height: p.visible,
		Rows:   lines,
		Query:  query,
	}<commit_msg>Keep the original candidates list for the blank search<commit_after>package main

import (
	"sort"
	"sync"
)

type View struct {
	Height int
	Query  string
	Rows   []string

	index int
}

func (v *View) Index() int {
	return v.index
}

func (v *View) Selected() string {
	return v.Rows[v.index]
}

func (v *View) Down() {
	if v.index < len(v.Rows)-1 {
		v.index++
	}
}

func (v *View) Up() {
	if v.index > 0 {
		v.index--
	}
}

type Picker struct {
	all     []Candidate
	visible int
	blank   *View
}

func NewPicker(candidates []Candidate, visible int) *Picker {
	picker := &Picker{
		all:     candidates,
		visible: visible,
	}
	blank := picker.doAnswer("")
	picker.blank = blank

	return picker
}

type Candidate struct {
	value string
	score float64
}

func NewCandidate(s string) Candidate {
	return Candidate{
		value: s,
		score: 1.0,
	}
}

type CandidateSlice []Candidate

func (cs CandidateSlice) Len() int           { return len(cs) }
func (cs CandidateSlice) Swap(i, j int)      { cs[i], cs[j] = cs[j], cs[i] }
func (cs CandidateSlice) Less(i, j int) bool { return cs[i].score > cs[j].score }

func (p *Picker) Answer(query string) *View {
	if query == "" {
		return p.blank
	}
	return p.doAnswer(query)
}

func (p *Picker) doAnswer(query string) *View {
	var wg sync.WaitGroup
	wg.Add(len(p.all))
	for i := range p.all {
		candidate := &p.all[i]
		go func(c *Candidate) {
			c.score = Score(c.value, query)
			wg.Done()
		}(candidate)
	}
	wg.Wait()

	sort.Sort(CandidateSlice(p.all))

	lines := []string{}
	for i := 0; i < p.visible; i++ {
		if p.all[i].score == 0.0 {
			break
		}
		lines = append(lines, p.all[i].value)
	}

	return &View{
		index:  0,
		Height: p.visible,
		Rows:   lines,
		Query:  query,
	}
{'fraction_non_alphanumeric': 0.15418227215980024, 'fraction_numerical': 0.006242197253433208, 'mean_word_length': 3.082802547770701, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4835546', 'n_tokens_mistral': 1341, 'n_tokens_neox': 1277, 'n_words': 355}