FTS5-Suche

This commit is contained in:
Simon Martens
2025-02-22 19:08:36 +01:00
parent 29576ec7a0
commit 3d54725283
28 changed files with 795 additions and 77 deletions

View File

@@ -0,0 +1,17 @@
{{ $extendable := . }}
<div class="col-span-6 flex flex-row text-stone-700 gap-x-2">
<div>
<i class="ri-information-2-fill"></i>
</div>
<div class="font-sans hyphens-auto text-sm pt-1">
Die Suche durchsucht ganze Datensätze nach dem Vorkommen aller eingegebenen Suchbegriffe. Felder
können oben einzeln aus der Suche ausgeschlossen werden. Auch partielle Treffer in Worten werden
angezeigt. Wörter mit weniger als drei Zeichen, Sonderzeichen &ndash; auch Satzzeichen &ndash;
sowie die Groß- und Kleinschreibung werden dabei ignoriert
{{- if $extendable }}
(für mehr Optionen s. die &rarr; <a href="?extended=true">erweiterte Suche</a>)
{{- end -}}.
</div>
</div>

View File

@@ -0,0 +1,45 @@
{{ $model := index . 0 }}
{{ $extendable := index . 1 }}
<label for="q" class="hidden">Suchbegriffe</label>
<input
{{ if $model.q }}value="{{ $model.q }}"{{- end -}}
type="search"
name="q"
autofocus="true"
minlength="3"
required
placeholder="Suchbegriff (min. 3 Zeichen)"
class="w-full col-span-8
placeholder:italic" />
<button id="submitbutton" type="submit" class="col-span-2">Suchen</button>
{{ if $extendable }}
<a
href="/suche/{{ $model.type }}?extended=true"
class="whitespace-nowrap self-end block col-span-2">
<i class="ri-arrow-right-long-line"></i> Erweiterte Suche
</a>
{{ end }}
<script type="module">
const form = document.getElementById("searchform");
const submitBtn = document.getElementById("submitbutton");
function checkValidity() {
if (form.checkValidity()) {
submitBtn.disabled = false;
} else {
submitBtn.disabled = true;
}
}
checkValidity();
if (form && submitBtn) {
form.addEventListener("input", (event) => {
checkValidity();
});
}
</script>

View File

@@ -0,0 +1,193 @@
{{ $model := . }}
{{- $includeReferences := true -}}
{{- $includeAnnotations := true -}}
{{- $includeTitle := true -}}
{{- if eq $model.type "reihen" -}}
{{- if $model.options -}}
{{- $includeReferences = not (and $model.q (not (index $model.options "references"))) -}}
{{- $includeAnnotations = not (and $model.q (not (index $model.options "annotations"))) -}}
{{- $includeTitle = not (and $model.q (not (index $model.options "title"))) -}}
{{- end -}}
{{- end -}}
<form
id="searchform"
class="w-full font-serif"
method="get"
action="/suche/{{- $model.type -}}"
autocomplete="off">
{{- if eq $model.type "reihen" -}}
<!-- INFO: Reihen -->
{{- if not $model.extended -}}
<div class="grid grid-cols-12 gap-y-3 w-full gap-x-4">
{{ template "searchboxsimple" Arr . false }}
<fieldset class="selectgroup">
<div class="selectgroup-option">
<input
type="checkbox"
name="title"
id="title"
{{ if $includeTitle -}}
checked
{{- end -}} />
<label for="title">Titel</label>
</div>
<div class="selectgroup-option">
<input
type="checkbox"
name="annotations"
id="annotations"
{{ if $includeAnnotations -}}
checked
{{- end -}} />
<label for="annotations">Anmerkungen</label>
</div>
<div class="selectgroup-option">
<input
type="checkbox"
name="references"
id="references"
{{ if $includeReferences -}}
checked
{{- end -}} />
<label for="references">Nachweise</label>
</div>
</fieldset>
{{ template "infotextsimple" false }}
</div>
{{- else -}}
Extended search Reihen
{{- end -}}
<!-- INFO: Ende Reihen -->
{{- else if eq $model.type "personen" -}}
<!-- INFO: Personen -->
{{- if not $model.extended -}}
<div class="grid grid-cols-12 gap-y-3 w-full gap-x-4">
{{ template "searchboxsimple" Arr . false }}
<fieldset class="selectgroup">
<div class="selectgroup-option">
<input type="checkbox" name="names" id="names" checked />
<label for="names">Namen &amp; Pseudonyme</label>
</div>
<div class="selectgroup-option">
<input type="checkbox" name="biographical" id="biographical" checked />
<label for="biographical">Lebensdaten</label>
</div>
<div class="selectgroup-option">
<input type="checkbox" name="profession" id="profession" checked />
<label for="profession">Beruf(e)</label>
</div>
<div class="selectgroup-option">
<input type="checkbox" name="annotations" id="annotations" checked />
<label for="annotations">Anmerkungen</label>
</div>
<div class="selectgroup-option">
<input type="checkbox" name="references" id="references" checked />
<label for="references">Nachweise</label>
</div>
</fieldset>
{{ template "infotextsimple" false }}
</div>
{{- else -}}
Extended search Personen
{{- end -}}
<!-- INFO: Ende Personen -->
{{- else if eq $model.type "baende" -}}
<!-- INFO: Bände -->
{{- if not $model.extended -}}
<div class="grid grid-cols-12 gap-y-3 w-full gap-x-4">
{{ template "searchboxsimple" Arr . true }}
<fieldset class="selectgroup">
<div class="selectgroup-option">
<input type="checkbox" name="number" id="number" checked />
<label for="number">Almanach-Nr.</label>
</div>
<div class="selectgroup-option">
<input type="checkbox" name="title" id="title" checked />
<label for="title">Titel</label>
</div>
<div class="selectgroup-option">
<input type="checkbox" name="series" id="series" checked />
<label for="series">Reihentitel</label>
</div>
<div class="selectgroup-option">
<input type="checkbox" name="person" id="person" checked />
<label for="person">Personen &amp; Verlage</label>
</div>
<div class="selectgroup-option">
<input type="checkbox" name="pubdata" id="pubdata" checked />
<label for="pubdata">Orte</label>
</div>
<div class="selectgroup-option">
<input type="checkbox" name="year" id="year" checked />
<label for="year">Jahr</label>
</div>
<div class="selectgroup-option">
<input type="checkbox" name="references" id="references" checked />
<label for="references">Nachweise</label>
</div>
<div class="selectgroup-option">
<input type="checkbox" name="annotations" id="annotations" checked />
<label for="annotations">Anmerkungen</label>
</div>
</fieldset>
{{ template "infotextsimple" true }}
</div>
{{- else -}}
Extended search Bände
{{- end -}}
<!-- INFO: Ende Bände -->
{{- else if eq $model.type "beitraege" -}}
<!-- INFO: Beiträge -->
{{- if not $model.extended -}}
<div class="grid grid-cols-12 gap-y-3 w-full gap-x-4">
{{ template "searchboxsimple" Arr . true }}
<fieldset class="selectgroup">
<div class="selectgroup-option">
<input type="checkbox" name="number" id="number" checked />
<label for="number">Almanach-Nr.</label>
</div>
<div class="selectgroup-option">
<input type="checkbox" name="title" id="title" checked />
<label for="title">Titelinformationen</label>
</div>
<div class="selectgroup-option">
<input type="checkbox" name="entry" id="entry" checked />
<label for="entry">Bandtitel</label>
</div>
<div class="selectgroup-option">
<input type="checkbox" name="person" id="person" checked />
<label for="person">Personen &amp; Pseudonyme</label>
</div>
<div class="selectgroup-option">
<input type="checkbox" name="annotations" id="annotations" checked />
<label for="annotations">Anmerkungen</label>
</div>
</fieldset>
{{ template "infotextsimple" true }}
</div>
{{- else -}}
Extended search Beiträge
{{- end -}}
{{- end -}}
</form>
<script type="module">
let fieldset = document.querySelector("fieldset.selectgroup");
let checkboxes = Array.from(fieldset.querySelectorAll('input[type="checkbox"]'));
fieldset.addEventListener("change", (event) => {
let target = event.target;
if (target.type === "checkbox") {
let name = target.name;
let checked = target.checked;
if (!checked) {
let allchecked = checkboxes.filter((checkbox) => checkbox.checked);
if (allchecked.length === 0) {
target.checked = true;
}
}
}
});
</script>