mirror of
https://github.com/Theodor-Springmann-Stiftung/kgpz_web.git
synced 2025-10-29 09:05:30 +00:00
Refined orte
This commit is contained in:
361
app/kgpz.go
361
app/kgpz.go
@@ -221,6 +221,178 @@ func (k *KGPZ) Funcs() map[string]interface{} {
|
||||
e["contains"] = func(s, substr string) bool { return strings.Contains(s, substr) }
|
||||
e["lower"] = func(s string) string { return strings.ToLower(s) }
|
||||
|
||||
// Place helper functions
|
||||
e["GetModernCountryName"] = func(geoID string) string {
|
||||
if geoID == "" || k.Geonames == nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
geoPlace := k.Geonames.Place(geoID)
|
||||
if geoPlace == nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
// Map country names to German translations
|
||||
switch geoPlace.CountryName {
|
||||
case "France":
|
||||
return "heutiges Frankreich"
|
||||
case "United Kingdom":
|
||||
return "heutiges Großbritannien"
|
||||
case "Russia":
|
||||
return "heutiges Russland"
|
||||
case "Czech Republic", "Czechia":
|
||||
return "heutiges Tschechien"
|
||||
case "Netherlands", "The Netherlands":
|
||||
return "heutige Niederlande"
|
||||
case "Poland":
|
||||
return "heutiges Polen"
|
||||
case "Switzerland":
|
||||
return "heutige Schweiz"
|
||||
case "Latvia":
|
||||
return "heutiges Lettland"
|
||||
case "Sweden":
|
||||
return "heutiges Schweden"
|
||||
case "Austria":
|
||||
return "heutiges Österreich"
|
||||
case "Belgium":
|
||||
return "heutiges Belgien"
|
||||
case "Slovakia":
|
||||
return "heutige Slowakei"
|
||||
case "Finland":
|
||||
return "heutiges Finnland"
|
||||
case "Denmark":
|
||||
return "heutiges Dänemark"
|
||||
default:
|
||||
// Return original country name for unknown countries (excluding Germany)
|
||||
if geoPlace.CountryName != "Germany" && geoPlace.CountryName != "" {
|
||||
return geoPlace.CountryName
|
||||
}
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
e["GetFullPlaceInfo"] = func(geoID string, originalName string) string {
|
||||
if geoID == "" || k.Geonames == nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
geoPlace := k.Geonames.Place(geoID)
|
||||
if geoPlace == nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
// Only show info for places outside Germany
|
||||
if geoPlace.CountryName == "Germany" || geoPlace.CountryName == "" {
|
||||
return ""
|
||||
}
|
||||
|
||||
// Get the modern country name
|
||||
countryName := ""
|
||||
switch geoPlace.CountryName {
|
||||
case "France":
|
||||
countryName = "heutiges Frankreich"
|
||||
case "United Kingdom":
|
||||
countryName = "heutiges Großbritannien"
|
||||
case "Russia":
|
||||
countryName = "heutiges Russland"
|
||||
case "Czech Republic", "Czechia":
|
||||
countryName = "heutiges Tschechien"
|
||||
case "Netherlands", "The Netherlands":
|
||||
countryName = "heutige Niederlande"
|
||||
case "Poland":
|
||||
countryName = "heutiges Polen"
|
||||
case "Switzerland":
|
||||
countryName = "heutige Schweiz"
|
||||
case "Latvia":
|
||||
countryName = "heutiges Lettland"
|
||||
case "Sweden":
|
||||
countryName = "heutiges Schweden"
|
||||
case "Austria":
|
||||
countryName = "heutiges Österreich"
|
||||
case "Belgium":
|
||||
countryName = "heutiges Belgien"
|
||||
case "Slovakia":
|
||||
countryName = "heutige Slowakei"
|
||||
case "Finland":
|
||||
countryName = "heutiges Finnland"
|
||||
case "Denmark":
|
||||
countryName = "heutiges Dänemark"
|
||||
default:
|
||||
countryName = geoPlace.CountryName
|
||||
}
|
||||
|
||||
// Extract German alternate name (same logic as GetModernPlaceName)
|
||||
modernName := ""
|
||||
hasGermanName := false
|
||||
|
||||
for _, altName := range geoPlace.AlternateNames {
|
||||
if altName.Lang == "de" {
|
||||
hasGermanName = true
|
||||
if altName.IsPreferredName {
|
||||
modernName = altName.Name
|
||||
break
|
||||
} else if modernName == "" {
|
||||
modernName = altName.Name
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !hasGermanName {
|
||||
modernName = geoPlace.ToponymName
|
||||
}
|
||||
|
||||
// Combine country and modern place name
|
||||
result := countryName
|
||||
if modernName != "" && strings.ToLower(modernName) != strings.ToLower(originalName) {
|
||||
result += ", " + modernName
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
e["GetModernPlaceName"] = func(geoID string, originalName string) string {
|
||||
if geoID == "" || k.Geonames == nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
geoPlace := k.Geonames.Place(geoID)
|
||||
if geoPlace == nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
// Only show modern names for places outside Germany
|
||||
if geoPlace.CountryName == "Germany" || geoPlace.CountryName == "" {
|
||||
return ""
|
||||
}
|
||||
|
||||
// Extract German alternate name
|
||||
modernName := ""
|
||||
hasGermanName := false
|
||||
|
||||
for _, altName := range geoPlace.AlternateNames {
|
||||
if altName.Lang == "de" {
|
||||
hasGermanName = true
|
||||
if altName.IsPreferredName {
|
||||
modernName = altName.Name
|
||||
break
|
||||
} else if modernName == "" {
|
||||
modernName = altName.Name
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !hasGermanName {
|
||||
modernName = geoPlace.ToponymName
|
||||
}
|
||||
|
||||
// Only return if it's different from the original name
|
||||
if modernName != "" && strings.ToLower(modernName) != strings.ToLower(originalName) {
|
||||
return modernName
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
e["LookupPieces"] = k.Library.Pieces.ReverseLookup
|
||||
e["LookupWorks"] = k.Library.Works.ReverseLookup
|
||||
e["LookupIssues"] = k.Library.Issues.ReverseLookup
|
||||
@@ -263,6 +435,126 @@ func (k *KGPZ) Enrich() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// EnrichAndRebuildIndex ensures enrichment completes before rebuilding search index
|
||||
func (k *KGPZ) EnrichAndRebuildIndex() error {
|
||||
if k.Library == nil || k.Library.Agents == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
go func() {
|
||||
k.fsmu.Lock()
|
||||
defer k.fsmu.Unlock()
|
||||
|
||||
logging.Info("Starting enrichment process...")
|
||||
|
||||
// Fetch GND data for agents
|
||||
data := xmlmodels.AgentsIntoDataset(k.Library.Agents)
|
||||
k.GND.FetchPersons(data)
|
||||
k.GND.WriteCache(filepath.Join(k.Config.BaseDIR, k.Config.GNDPath))
|
||||
|
||||
// Fetch Geonames data for places
|
||||
if k.Library.Places != nil {
|
||||
placeData := xmlmodels.PlacesIntoDataset(k.Library.Places)
|
||||
k.Geonames.FetchPlaces(placeData)
|
||||
k.Geonames.WriteCache(filepath.Join(k.Config.BaseDIR, k.Config.GeoPath))
|
||||
}
|
||||
|
||||
logging.Info("Enrichment complete. Starting search index rebuild...")
|
||||
|
||||
// Clear existing indices before rebuilding
|
||||
k.ClearSearchIndices()
|
||||
|
||||
// Rebuild search index after enrichment is complete
|
||||
k.buildSearchIndexSync()
|
||||
}()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ClearSearchIndices removes all existing search indices
|
||||
func (k *KGPZ) ClearSearchIndices() error {
|
||||
if k.Search == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return k.Search.ClearAllIndices()
|
||||
}
|
||||
|
||||
// buildSearchIndexSync builds the search index synchronously (no goroutine)
|
||||
func (k *KGPZ) buildSearchIndexSync() error {
|
||||
if k.Library == nil || k.Library.Agents == nil || k.Search == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
wg := new(sync.WaitGroup)
|
||||
wg.Add(6)
|
||||
|
||||
go func() {
|
||||
for _, agent := range k.Library.Agents.Array {
|
||||
err := k.Search.Index(agent, k.Library)
|
||||
if err != nil {
|
||||
logging.Error(err, "Error indexing agent")
|
||||
}
|
||||
}
|
||||
wg.Done()
|
||||
}()
|
||||
|
||||
go func() {
|
||||
for _, place := range k.Library.Places.Array {
|
||||
err := k.Search.Index(place, k.Library)
|
||||
if err != nil {
|
||||
logging.Error(err, "Error indexing place")
|
||||
}
|
||||
}
|
||||
wg.Done()
|
||||
}()
|
||||
|
||||
go func() {
|
||||
for _, cat := range k.Library.Categories.Array {
|
||||
err := k.Search.Index(cat, k.Library)
|
||||
if err != nil {
|
||||
logging.Error(err, "Error indexing category")
|
||||
}
|
||||
}
|
||||
wg.Done()
|
||||
}()
|
||||
|
||||
go func() {
|
||||
for _, work := range k.Library.Works.Array {
|
||||
err := k.Search.Index(work, k.Library)
|
||||
if err != nil {
|
||||
logging.Error(err, "Error indexing work")
|
||||
}
|
||||
}
|
||||
wg.Done()
|
||||
}()
|
||||
|
||||
go func() {
|
||||
for _, issue := range k.Library.Issues.Array {
|
||||
err := k.Search.Index(issue, k.Library)
|
||||
if err != nil {
|
||||
logging.Error(err, "Error indexing issue")
|
||||
}
|
||||
}
|
||||
wg.Done()
|
||||
}()
|
||||
|
||||
go func() {
|
||||
for _, piece := range k.Library.Pieces.Array {
|
||||
err := k.Search.Index(piece, k.Library)
|
||||
if err != nil {
|
||||
logging.Error(err, "Error indexing piece")
|
||||
}
|
||||
}
|
||||
wg.Done()
|
||||
}()
|
||||
|
||||
wg.Wait()
|
||||
logging.Info("Search index built.")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (k *KGPZ) BuildSearchIndex() error {
|
||||
if k.Library == nil || k.Library.Agents == nil || k.Search == nil {
|
||||
return nil
|
||||
@@ -271,71 +563,7 @@ func (k *KGPZ) BuildSearchIndex() error {
|
||||
go func() {
|
||||
k.fsmu.Lock()
|
||||
defer k.fsmu.Unlock()
|
||||
wg := new(sync.WaitGroup)
|
||||
wg.Add(6)
|
||||
go func() {
|
||||
for _, agent := range k.Library.Agents.Array {
|
||||
err := k.Search.Index(agent, k.Library)
|
||||
if err != nil {
|
||||
logging.Error(err, "Error indexing agent")
|
||||
}
|
||||
}
|
||||
wg.Done()
|
||||
}()
|
||||
|
||||
go func() {
|
||||
for _, place := range k.Library.Places.Array {
|
||||
err := k.Search.Index(place, k.Library)
|
||||
if err != nil {
|
||||
logging.Error(err, "Error indexing place")
|
||||
}
|
||||
}
|
||||
wg.Done()
|
||||
}()
|
||||
|
||||
go func() {
|
||||
for _, cat := range k.Library.Categories.Array {
|
||||
err := k.Search.Index(cat, k.Library)
|
||||
if err != nil {
|
||||
logging.Error(err, "Error indexing category")
|
||||
}
|
||||
}
|
||||
wg.Done()
|
||||
}()
|
||||
|
||||
go func() {
|
||||
for _, work := range k.Library.Works.Array {
|
||||
err := k.Search.Index(work, k.Library)
|
||||
if err != nil {
|
||||
logging.Error(err, "Error indexing work")
|
||||
}
|
||||
}
|
||||
wg.Done()
|
||||
}()
|
||||
|
||||
go func() {
|
||||
for _, issue := range k.Library.Issues.Array {
|
||||
err := k.Search.Index(issue, k.Library)
|
||||
if err != nil {
|
||||
logging.Error(err, "Error indexing issue")
|
||||
}
|
||||
}
|
||||
wg.Done()
|
||||
}()
|
||||
|
||||
go func() {
|
||||
for _, piece := range k.Library.Pieces.Array {
|
||||
err := k.Search.Index(piece, k.Library)
|
||||
if err != nil {
|
||||
logging.Error(err, "Error indexing piece")
|
||||
}
|
||||
}
|
||||
wg.Done()
|
||||
}()
|
||||
|
||||
wg.Wait()
|
||||
logging.Info("Search index built.")
|
||||
|
||||
k.buildSearchIndexSync()
|
||||
}()
|
||||
return nil
|
||||
}
|
||||
@@ -380,8 +608,7 @@ func (k *KGPZ) Pull() {
|
||||
if changed {
|
||||
logging.ObjDebug(&k.Repo, "Remote changed. Reparsing")
|
||||
k.Serialize()
|
||||
k.Enrich()
|
||||
k.BuildSearchIndex()
|
||||
k.EnrichAndRebuildIndex()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user