feat(go-services): inventory-go search — object_class_name (exact, gem context)
Loads the ObjectClass enum map and adds object_class_name via translate_object_class, including the context-aware Gem(11) classification (crystal/mana stone/gem/aetheria by item name, using the original name before the material prefix). The rare aetheria-by-IntValues path is documented as not reproduced (needs original_json). Validated vs Python: 0 mismatches over 600 rows (3 queries incl. a 'crystal' text search that exercises the gem context) for object_class_name, name, material_name, item_set_name, value. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
50360f72c4
commit
1294ec4418
2 changed files with 58 additions and 14 deletions
|
|
@ -15,6 +15,7 @@ import (
|
|||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strconv"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
|
|
@ -26,6 +27,7 @@ var buildVersion = "dev"
|
|||
type Server struct {
|
||||
pool *pgxpool.Pool
|
||||
attributeSets map[string]string // AttributeSetInfo: set-id -> set name
|
||||
objectClasses map[int]string // ObjectClass: id -> name
|
||||
log *slog.Logger
|
||||
}
|
||||
|
||||
|
|
@ -43,13 +45,14 @@ func main() {
|
|||
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
|
||||
defer stop()
|
||||
|
||||
srv := &Server{log: logger, attributeSets: map[string]string{}}
|
||||
srv := &Server{log: logger, attributeSets: map[string]string{}, objectClasses: map[int]string{}}
|
||||
|
||||
if sets, err := loadAttributeSets(enumPath); err != nil {
|
||||
logger.Warn("could not load enum AttributeSetInfo (set names will be unknown)", "err", err, "path", enumPath)
|
||||
if sets, classes, err := loadEnums(enumPath); err != nil {
|
||||
logger.Warn("could not load enum DB (set/class names will be unknown)", "err", err, "path", enumPath)
|
||||
} else {
|
||||
srv.attributeSets = sets
|
||||
logger.Info("loaded enum AttributeSetInfo", "sets", len(sets))
|
||||
srv.objectClasses = classes
|
||||
logger.Info("loaded enum DB", "sets", len(sets), "object_classes", len(classes))
|
||||
}
|
||||
|
||||
if dsn == "" {
|
||||
|
|
@ -159,13 +162,13 @@ func (s *Server) dbErr(w http.ResponseWriter, where string, err error) {
|
|||
writeJSON(w, http.StatusInternalServerError, map[string]any{"detail": "Internal server error"})
|
||||
}
|
||||
|
||||
// loadAttributeSets reads the comprehensive enum DB and extracts AttributeSetInfo
|
||||
// (set-id -> name), mirroring load_comprehensive_enums (dictionaries first, then
|
||||
// enums). Only the slice needed for /sets/list is decoded.
|
||||
func loadAttributeSets(path string) (map[string]string, error) {
|
||||
// loadEnums reads the comprehensive enum DB and extracts AttributeSetInfo
|
||||
// (set-id -> name) and ObjectClass (id -> name), mirroring
|
||||
// load_comprehensive_enums (dictionaries first, then enums).
|
||||
func loadEnums(path string) (sets map[string]string, classes map[int]string, err error) {
|
||||
b, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
var db struct {
|
||||
Dictionaries map[string]struct {
|
||||
|
|
@ -174,17 +177,26 @@ func loadAttributeSets(path string) (map[string]string, error) {
|
|||
Enums map[string]struct {
|
||||
Values map[string]string `json:"values"`
|
||||
} `json:"enums"`
|
||||
ObjectClasses struct {
|
||||
Values map[string]string `json:"values"`
|
||||
} `json:"object_classes"`
|
||||
}
|
||||
if err := json.Unmarshal(b, &db); err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
sets = map[string]string{}
|
||||
if d, ok := db.Dictionaries["AttributeSetInfo"]; ok && len(d.Values) > 0 {
|
||||
return d.Values, nil
|
||||
sets = d.Values
|
||||
} else if e, ok := db.Enums["AttributeSetInfo"]; ok {
|
||||
sets = e.Values
|
||||
}
|
||||
if e, ok := db.Enums["AttributeSetInfo"]; ok {
|
||||
return e.Values, nil
|
||||
classes = map[int]string{}
|
||||
for k, v := range db.ObjectClasses.Values {
|
||||
if n, err := strconv.Atoi(k); err == nil {
|
||||
classes[n] = v
|
||||
}
|
||||
}
|
||||
return map[string]string{}, nil
|
||||
return sets, classes, nil
|
||||
}
|
||||
|
||||
func envOr(key, def string) string {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue