mirror of
https://github.com/Theodor-Springmann-Stiftung/kgpz_web.git
synced 2025-12-16 12:05:30 +00:00
Search Index Build
This commit is contained in:
@@ -2,8 +2,11 @@ package xmlprovider
|
||||
|
||||
import "fmt"
|
||||
|
||||
type XMLItem interface {
|
||||
type IXMLItem interface {
|
||||
fmt.Stringer
|
||||
// INFO:
|
||||
// - Keys should be unique
|
||||
// - Keys[0] has the special meaning of the primary key (for FTS etc.)
|
||||
Keys() []string
|
||||
Name() string
|
||||
}
|
||||
@@ -12,13 +15,13 @@ type ILibrary interface {
|
||||
Parse(meta ParseMeta) error
|
||||
}
|
||||
|
||||
type ResolvingMap[T XMLItem] map[string][]Resolved[T]
|
||||
type ResolvingMap[T IXMLItem] map[string][]Resolved[T]
|
||||
|
||||
type ReferenceResolver[T XMLItem] interface {
|
||||
type ReferenceResolver[T IXMLItem] interface {
|
||||
References() ResolvingMap[T]
|
||||
}
|
||||
|
||||
type Resolved[T XMLItem] struct {
|
||||
type Resolved[T IXMLItem] struct {
|
||||
Item *T
|
||||
Reference string
|
||||
Category string
|
||||
|
||||
@@ -7,13 +7,13 @@ import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
type Resolver[T XMLItem] struct {
|
||||
type Resolver[T IXMLItem] struct {
|
||||
// INFO: map[type][ID]
|
||||
index map[string]map[string][]Resolved[T]
|
||||
mu sync.RWMutex
|
||||
}
|
||||
|
||||
func NewResolver[T XMLItem]() *Resolver[T] {
|
||||
func NewResolver[T IXMLItem]() *Resolver[T] {
|
||||
return &Resolver[T]{index: make(map[string]map[string][]Resolved[T])}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ func (p ParseMeta) Failed(path string) bool {
|
||||
}
|
||||
|
||||
// An XMLProvider is a struct that holds holds serialized XML data of a specific type. It combines multiple parses IF a succeeded parse can not serialize the data from a path.
|
||||
type XMLProvider[T XMLItem] struct {
|
||||
type XMLProvider[T IXMLItem] struct {
|
||||
// INFO: map is type map[string]*T
|
||||
Items sync.Map
|
||||
// INFO: map is type [string]ItemInfo
|
||||
@@ -50,7 +50,7 @@ type XMLProvider[T XMLItem] struct {
|
||||
Array []T
|
||||
}
|
||||
|
||||
func NewXMLProvider[T XMLItem]() *XMLProvider[T] {
|
||||
func NewXMLProvider[T IXMLItem]() *XMLProvider[T] {
|
||||
return &XMLProvider[T]{Resolver: *NewResolver[T]()}
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ func (p *XMLProvider[T]) addResolvable(item T) {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *XMLProvider[T]) ReverseLookup(item XMLItem) []Resolved[T] {
|
||||
func (p *XMLProvider[T]) ReverseLookup(item IXMLItem) []Resolved[T] {
|
||||
// INFO: this runs just once for the first key
|
||||
ret := make([]Resolved[T], 0)
|
||||
keys := item.Keys()
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
func Sort[T XMLItem](i, j T) int {
|
||||
func Sort[T IXMLItem](i, j T) int {
|
||||
|
||||
keys_a := i.Keys()
|
||||
keys_b := j.Keys()
|
||||
|
||||
Reference in New Issue
Block a user