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