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:
@ -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
|
||||
|
||||
Reference in New Issue
Block a user