feat(search): find companies by stock symbol

Index exact symbols from selected primary listings, preserve canonical company identities, and add BABA as an explicit alias for Alibaba's primary identity. Update bilingual help and cover symbol collisions, aliases, and DTO stability.

Refs #25

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-11-22 18:31:46 +01:00
parent f7b057efa3
commit f97ae18d6c
10 changed files with 354 additions and 19 deletions

View File

@ -28,6 +28,7 @@ type CompanyCatalog interface {
var ErrUnknownCompany = errors.New("unknown company")
type Catalog struct {
symbolIDs map[string][]string
aliases map[string]map[string]bool
companies []Company
byID map[string]Company
@ -94,7 +95,7 @@ func readCatalog(input io.Reader) (*Catalog, error) {
return nil, errors.New("invalid company snapshot columns")
}
}
c := &Catalog{byID: map[string]Company{}}
c := &Catalog{byID: map[string]Company{}, symbolIDs: map[string][]string{}}
scores := map[string]float64{}
for {
row, err := r.Read()
@ -126,6 +127,10 @@ func readCatalog(input io.Reader) (*Catalog, error) {
return nil, errors.New("invalid listing score")
}
}
// Index every locally selected primary symbol, before grouping identities.
// Search still returns the existing canonical Company and Yahoo listing.
key := normalizeExactSymbol(company.YahooSymbol)
c.symbolIDs[key] = append(c.symbolIDs[key], company.CompanyID)
if old, exists := c.byID[company.CompanyID]; exists {
// The upstream primary selector can keep multiple equally primary venues
// for one ISIN. Prefer its score, then a stable representative among those