mirror of
https://github.com/Theodor-Springmann-Stiftung/musenalm.git
synced 2025-10-29 09:15:33 +00:00
Suche nach Musenalm-ID implementiert
This commit is contained in:
@@ -5,7 +5,7 @@ tmp_dir = "tmp"
|
||||
[build]
|
||||
args_bin = []
|
||||
full_bin = "./tmp/musenalm --dir ./pb_data serve"
|
||||
cmd = "go build -tags=dev,fts5 -o ./tmp/musenalm ."
|
||||
cmd = "go build -tags=dev,fts5,sqlite_icu -o ./tmp/musenalm ."
|
||||
delay = 400
|
||||
exclude_dir = [
|
||||
"views/assets",
|
||||
|
||||
@@ -1,12 +1,26 @@
|
||||
package dbmodels
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/pocketbase/dbx"
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
)
|
||||
|
||||
type EntriesAgents map[string][]*REntriesAgents
|
||||
|
||||
func EntriesForID(app core.App, query int) ([]*Entry, error) {
|
||||
entries := []*Entry{}
|
||||
err := app.RecordQuery(ENTRIES_TABLE).
|
||||
Where(dbx.HashExp{MUSENALMID_FIELD: strconv.Itoa(query)}).
|
||||
All(&entries)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return entries, nil
|
||||
}
|
||||
|
||||
func YearsForEntries(app core.App) ([]int, error) {
|
||||
rec := []core.Record{}
|
||||
err := app.RecordQuery(ENTRIES_TABLE).
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
"golang.org/x/text/cases"
|
||||
"golang.org/x/text/collate"
|
||||
"golang.org/x/text/language"
|
||||
"golang.org/x/text/unicode/norm"
|
||||
)
|
||||
|
||||
type SeriesEntries map[string][]*REntriesSeries
|
||||
@@ -22,13 +21,25 @@ func SortSeriessesByTitle(series []*Series) {
|
||||
})
|
||||
}
|
||||
|
||||
func MusenalmIDSearchSeries(app core.App, query string) ([]*Series, error) {
|
||||
series := []*Series{}
|
||||
err := app.RecordQuery(SERIES_TABLE).
|
||||
Where(dbx.Like(MUSENALMID_FIELD, query).Match(true, false)).
|
||||
All(&series)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return series, nil
|
||||
}
|
||||
|
||||
func BasicSearchSeries(app core.App, query string) ([]*Series, []*Series, error) {
|
||||
query = strings.TrimSpace(query)
|
||||
query = datatypes.DeleteTags(query)
|
||||
query = datatypes.NormalizeString(query)
|
||||
query = datatypes.RemovePunctuation(query)
|
||||
query = cases.Lower(language.German).String(query)
|
||||
query = norm.NFKD.String(query)
|
||||
// TODO: how to normalize, which unicode normalization to use?
|
||||
|
||||
if query == "" {
|
||||
return []*Series{}, []*Series{}, nil
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
package seed
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/Theodor-Springmann-Stiftung/musenalm/helpers/datatypes"
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
"golang.org/x/text/unicode/norm"
|
||||
)
|
||||
|
||||
func NormalizeString(s string) string {
|
||||
s = strings.TrimSpace(s)
|
||||
s = strings.ReplaceAll(s, "<div>", "")
|
||||
s = strings.ReplaceAll(s, "</div>", "")
|
||||
s = datatypes.NormalizeString(s)
|
||||
s = norm.NFC.String(s)
|
||||
return s
|
||||
}
|
||||
|
||||
|
||||
@@ -150,15 +150,17 @@ func (p *ReihenPage) PlaceRequest(app core.App, engine *templating.Engine, e *co
|
||||
return p.Get(e, engine, data)
|
||||
}
|
||||
|
||||
// BUG: Umlaute werden nicht korrekt gesucht
|
||||
// BUG: alternative treffer haben keine relations
|
||||
// TODO: Suche nach Musenalm-ID
|
||||
// TODO: Suchverhalten bei gefilterten Personen, Orten und Jahren
|
||||
// TODO: FTS-Suche für alt. Ergebnisse
|
||||
func (p *ReihenPage) SearchRequest(app core.App, engine *templating.Engine, e *core.RequestEvent) error {
|
||||
search := e.Request.URL.Query().Get(PARAM_SEARCH)
|
||||
data := map[string]interface{}{}
|
||||
data[PARAM_SEARCH] = search
|
||||
// INFO: normalization happens in the db query
|
||||
series, altseries, err := dbmodels.BasicSearchSeries(app, search)
|
||||
|
||||
if err != nil {
|
||||
return Error404(e, engine, err, data)
|
||||
}
|
||||
@@ -171,6 +173,50 @@ func (p *ReihenPage) SearchRequest(app core.App, engine *templating.Engine, e *c
|
||||
if err != nil {
|
||||
return Error404(e, engine, err, data)
|
||||
}
|
||||
|
||||
rmap2, bmap2, err := dbmodels.EntriesForSeriesses(app, altseries)
|
||||
if err != nil {
|
||||
return Error404(e, engine, err, data)
|
||||
}
|
||||
|
||||
for k, v := range rmap2 {
|
||||
rmap[k] = v
|
||||
}
|
||||
for k, v := range bmap2 {
|
||||
bmap[k] = v
|
||||
}
|
||||
|
||||
// Searching for MUSENALM-ID
|
||||
if searchint, err := strconv.Atoi(search); err == nil {
|
||||
identries, err := dbmodels.EntriesForID(app, searchint)
|
||||
if err != nil {
|
||||
return Error404(e, engine, err, data)
|
||||
}
|
||||
|
||||
if len(identries) != 0 {
|
||||
|
||||
idseries, rmap3, bmap3, err := dbmodels.SeriesForEntries(app, identries)
|
||||
if err != nil {
|
||||
return Error404(e, engine, err, data)
|
||||
}
|
||||
|
||||
dbmodels.SortSeriessesByTitle(idseries)
|
||||
data["idseries"] = idseries
|
||||
|
||||
if err != nil {
|
||||
return Error404(e, engine, err, data)
|
||||
}
|
||||
|
||||
for k, v := range rmap3 {
|
||||
rmap[k] = v
|
||||
}
|
||||
|
||||
for k, v := range bmap3 {
|
||||
bmap[k] = v
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
data["entries"] = bmap
|
||||
data["relations"] = rmap
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
{{ $model := index . 0 }}
|
||||
{{ $r := index . 1 }}
|
||||
{{ $showidseries := index . 2 }}
|
||||
|
||||
{{ $bds := index $model.relations $r.Id }}
|
||||
|
||||
@@ -9,13 +10,15 @@
|
||||
{{ if $r.References }}
|
||||
<div class="text-sm font-sans px-2 py-1 bg-stone-100">{{ $r.References }}</div>
|
||||
{{ end }}
|
||||
{{ if $model.musenalmid }}
|
||||
{{ if $showidseries }}
|
||||
{{ range $_, $rel := $bds }}
|
||||
<div class="font-sans text-sm px-2 py-1 bg-stone-100 searchable my-0.5">
|
||||
Almanach-Nr.
|
||||
<span class="reihen-text">
|
||||
{{ (index $model.entries
|
||||
$rel.Entry).MusenalmID
|
||||
}}
|
||||
</span>
|
||||
</div>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
[&>*]:px-12 [&>*]:pt-8 -mr-36 [&>*]:bg-slate-100">
|
||||
{{ if .agents }}
|
||||
<div class="">
|
||||
<h2 class="mb-6">Personen, Verlage & Druckereien</h2>
|
||||
<h2 class="mb-6">Herausgeber:innen, Verlage & Druckereien</h2>
|
||||
<filter-list
|
||||
id="agent-list"
|
||||
data-url="/reihen/?agent="
|
||||
|
||||
@@ -26,31 +26,47 @@ let mark_instance = new Mark(elements);
|
||||
</script>
|
||||
{{ end }}
|
||||
|
||||
{{ if or .series .altseries }}
|
||||
|
||||
<div class="-ml-16">
|
||||
{{ if and .search .idseries }}
|
||||
<div class="mb-1 max-w-[60rem] hyphens-auto">
|
||||
{{ range $id, $r := .series }}
|
||||
{{ template "_reihe" (Arr $model $r) }}
|
||||
{{ range $id, $r := .idseries }}
|
||||
{{ template "_reihe" (Arr $model $r true) }}
|
||||
{{ end }}
|
||||
</div>
|
||||
{{ end }}
|
||||
|
||||
{{ if .series }}
|
||||
<div class="mb-1 max-w-[60rem] hyphens-auto">
|
||||
{{ range $id, $r := .series }}
|
||||
{{ template "_reihe" (Arr $model $r false) }}
|
||||
{{ end }}
|
||||
</div>
|
||||
{{ end }}
|
||||
|
||||
{{ if and .search .altseries }}
|
||||
{{ if .idseries }}
|
||||
<div class="border-b text-sm font-sans text-right pb-0.5">
|
||||
Treffer in Almanach-Nummer ↑
|
||||
</div>
|
||||
{{ end }}
|
||||
|
||||
{{ if .series }}
|
||||
<div class="border-b text-xs font-sans text-right pb-0.5">
|
||||
<div class="border-b text-sm font-sans text-right pb-0.5">
|
||||
Treffer in Reihentiteln ↑
|
||||
</div>
|
||||
{{ end }}
|
||||
<div class="border-t mb-1.5 text-xs font-sans text-right pt-0.5">
|
||||
<div class="border-t mb-1.5 text-sm font-sans text-right pt-0.5">
|
||||
Treffer in Anmerkungen, Verweisen etc. ↓
|
||||
</div>
|
||||
<div class="mb-1 max-w-[60rem] hyphens-auto">
|
||||
{{ range $id, $r := .altseries }}
|
||||
{{ template "_reihe" (Arr $model $r) }}
|
||||
{{ template "_reihe" (Arr $model $r false) }}
|
||||
{{ end }}
|
||||
</div>
|
||||
{{ end }}
|
||||
</div>
|
||||
{{ else }}
|
||||
{{ if not (or .series .altseries .idseries) }}
|
||||
<div class="mt-8">
|
||||
Keine Reihen
|
||||
{{ if .search }}für {{ .search }}{{ end }}
|
||||
|
||||
Reference in New Issue
Block a user