Improve Result Quality
This commit is contained in:
parent
3e59d043a7
commit
18353fc268
@ -26,7 +26,7 @@ type ResultsModel struct {
|
||||
|
||||
type ResultView struct {
|
||||
CDSViewModel
|
||||
Score float32
|
||||
Score float64
|
||||
}
|
||||
|
||||
type ResultsModelBuffer struct {
|
||||
@ -37,7 +37,7 @@ func NewResultsModel() *ResultsModel {
|
||||
return &ResultsModel{}
|
||||
}
|
||||
|
||||
func (r *ResultsModel) AppendResultsModelViews(cdsView *CDSViewModel, score float32) {
|
||||
func (r *ResultsModel) AppendResultsModelViews(cdsView *CDSViewModel, score float64) {
|
||||
resultView := ResultView{
|
||||
CDSViewModel: *cdsView,
|
||||
Score: score,
|
||||
|
@ -35,8 +35,9 @@ import (
|
||||
type fuzzyResult struct {
|
||||
CDSViewTechnicalName string
|
||||
hits int
|
||||
perfectHits int
|
||||
averageDistance float32
|
||||
score float32
|
||||
score float64
|
||||
}
|
||||
|
||||
type resultBuffer struct {
|
||||
@ -118,26 +119,27 @@ func BuildBuffer(searchTerm string) error {
|
||||
var fuzzyResults []fuzzyResult
|
||||
|
||||
for viewName, targets := range searchTargets {
|
||||
totalHits := 0
|
||||
perfectHits := 0
|
||||
var (
|
||||
totalHits, perfectHits int
|
||||
totalDistance float32
|
||||
)
|
||||
|
||||
var totalDistance float32
|
||||
totalDistance = 1
|
||||
for i, splitSearchTerm := range splitSearchTerms {
|
||||
if splitSearchTerm == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
ranks := fuzzy.RankFindFold(splitSearchTerm, targets)
|
||||
|
||||
hits := len(ranks)
|
||||
/*if hits == 0 {
|
||||
if i < len(splitSearchTerm)-3 {
|
||||
totalDistance += 500
|
||||
}
|
||||
continue
|
||||
}*/
|
||||
|
||||
totalHits += hits
|
||||
|
||||
if hits == 0 {
|
||||
totalDistance += 100
|
||||
continue
|
||||
}
|
||||
|
||||
var averageDistance float32 = 0
|
||||
for _, rank := range ranks {
|
||||
averageDistance += float32(rank.Distance)
|
||||
@ -154,7 +156,8 @@ func BuildBuffer(searchTerm string) error {
|
||||
CDSViewTechnicalName: viewName,
|
||||
hits: totalHits,
|
||||
averageDistance: totalDistance,
|
||||
score: (float32(len(targets)) / float32(totalHits)) / float32(perfectHits),
|
||||
perfectHits: perfectHits,
|
||||
score: (float64(totalDistance) / float64(totalHits)) * (float64(len(targets)) / float64(totalHits)),
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -165,6 +168,11 @@ func BuildBuffer(searchTerm string) error {
|
||||
}
|
||||
|
||||
slices.SortFunc(fuzzyResults, func(a, b fuzzyResult) int {
|
||||
if a.perfectHits < b.perfectHits {
|
||||
return 1
|
||||
} else if a.perfectHits > b.perfectHits {
|
||||
return -1
|
||||
}
|
||||
if a.score > b.score {
|
||||
return 1
|
||||
} else if a.score < b.score {
|
||||
|
Loading…
Reference in New Issue
Block a user