<commit_before>package search

import (
	"math"
	"regexp"
	"sort"

	speeldoos "github.com/thijzert/speeldoos/pkg"
)

var containsRegexChars *regexp.Regexp

func init() {
	containsRegexChars = regexp.MustCompile("[\\(\\)\\{\\}\\\\\\[\\]\\|\\.]")
}

type resulterer interface {
	GetResult(perf speeldoos.Performance) Result
}

type Query struct {
	MinimalRelevance float64
	rootMatcher      resulterer
}

func Compile(q string) (Query, error) {
	return defaultConfig.Compile(q)
}

func (q Query) Search(lib *speeldoos.Library) []Result {
	var rv resultList

	carriers := lib.AllCarriers()
	for _, carrier := range carriers {
		for _, perf := range carrier.Carrier.Performances {
			res := q.rootMatcher.GetResult(perf)

			if res.Relevance.Relevance() >= q.MinimalRelevance {
				rv.Results = append(rv.Results, res)
			}
		}
	}

	sort.Sort(&rv)

	return rv.Results
}

type matcherNode struct {
	f StringMatcher
}
<commit_msg>If the query has zero minimal relevance, at least filter results that don't match at all<commit_after>package search

import (
	"math"
	"regexp"
	"sort"

	speeldoos "github.com/thijzert/speeldoos/pkg"
)

var containsRegexChars *regexp.Regexp

func init() {
	containsRegexChars = regexp.MustCompile("[\\(\\)\\{\\}\\\\\\[\\]\\|\\.]")
}

type resulterer interface {
	GetResult(perf speeldoos.Performance) Result
}

type Query struct {
	MinimalRelevance float64
	rootMatcher      resulterer
}

func Compile(q string) (Query, error) {
	return defaultConfig.Compile(q)
}

func (q Query) Search(lib *speeldoos.Library) []Result {
	var rv resultList

	carriers := lib.AllCarriers()
	for _, carrier := range carriers {
		for _, perf := range carrier.Carrier.Performances {
			res := q.rootMatcher.GetResult(perf)

			if res.Relevance.Match > 0 && res.Relevance.Relevance() >= q.MinimalRelevance {
				rv.Results = append(rv.Results, res)
			}
		}
	}

	sort.Sort(&rv)

	return rv.Results
}

type matcherNode struct {
	f StringMatcher
}

{'fraction_non_alphanumeric': 0.13794871794871794, 'fraction_numerical': 0.002564102564102564, 'mean_word_length': 3.8054187192118225, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '5588692', 'n_tokens_mistral': 749, 'n_tokens_neox': 688, 'n_words': 157}