fix(query): use JaroWinkler distance and reweight metric components Switch from Hamming to JaroWinkler distance for package name matching, as JaroWinkler handles variable-length strings and gives a prefix-match bonus better suited to package search. Reweight the score components from sim*0.50 + simDesc*0.20 + popularity*0.30 to sim*0.35 + simDesc*0.15 + popularity*0.50 to better surface popular packages when name similarity is moderate. Roll back the unreleased version target from 13.0.0 to 12.6.0 to align with the next minor release after v12.5.7. Fix scanner.Err() check in parseStdin to surface I/O errors that were previously silently dropped.
91 lines
1.8 KiB
Go
91 lines
1.8 KiB
Go
package settings
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/Jguer/yay/v12/pkg/db"
|
|
"github.com/Jguer/yay/v12/pkg/text"
|
|
|
|
"github.com/leonelquinteros/gotext"
|
|
)
|
|
|
|
type configMigration interface {
|
|
// Description of what the migration does
|
|
fmt.Stringer
|
|
// return true if migration was done
|
|
Do(config *Configuration) bool
|
|
// Target version of the migration (e.g. "11.2.1")
|
|
// Should match the version of yay releasing this migration
|
|
TargetVersion() string
|
|
}
|
|
|
|
type configProviderMigration struct{}
|
|
|
|
func (migration *configProviderMigration) String() string {
|
|
return gotext.Get("Disable 'provides' setting by default")
|
|
}
|
|
|
|
func (migration *configProviderMigration) Do(config *Configuration) bool {
|
|
if config.Provides {
|
|
config.Provides = false
|
|
|
|
return true
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
func (migration *configProviderMigration) TargetVersion() string {
|
|
return "11.2.1"
|
|
}
|
|
|
|
type configSortByMigration struct{}
|
|
|
|
func (migration *configSortByMigration) String() string {
|
|
return gotext.Get("Reset 'sortby' setting to default")
|
|
}
|
|
|
|
func (migration *configSortByMigration) Do(config *Configuration) bool {
|
|
if config.SortBy != "" {
|
|
config.SortBy = ""
|
|
|
|
return true
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
func (migration *configSortByMigration) TargetVersion() string {
|
|
return "12.6.0"
|
|
}
|
|
|
|
func DefaultMigrations() []configMigration {
|
|
return []configMigration{
|
|
&configProviderMigration{},
|
|
&configSortByMigration{},
|
|
}
|
|
}
|
|
|
|
func (c *Configuration) RunMigrations(logger *text.Logger, migrations []configMigration,
|
|
configPath, newVersion string,
|
|
) error {
|
|
saveConfig := false
|
|
|
|
for _, migration := range migrations {
|
|
if db.VerCmp(migration.TargetVersion(), c.Version) > 0 {
|
|
if migration.Do(c) {
|
|
logger.Infoln("Config migration executed (",
|
|
migration.TargetVersion(), "):", migration)
|
|
|
|
saveConfig = true
|
|
}
|
|
}
|
|
}
|
|
|
|
if saveConfig {
|
|
return c.Save(configPath, newVersion)
|
|
}
|
|
|
|
return nil
|
|
}
|