Basis Suche Inhalte

This commit is contained in:
Simon Martens
2025-02-28 22:31:19 +01:00
parent 4581f34dd9
commit ca33ec7be3
20 changed files with 1290 additions and 594 deletions

View File

@@ -417,6 +417,8 @@ var PUBLIC_VIEW_RULE = types.Pointer("")
var PUBLIC_LIST_RULE = types.Pointer("")
const (
FTS_LIMIT = 100000
PLACES_TABLE = "places"
AGENTS_TABLE = "agents"
SERIES_TABLE = "series"

View File

@@ -204,6 +204,10 @@ func (e *Entry) MusenalmID() int {
return e.GetInt(MUSENALMID_FIELD)
}
func (e *Entry) MusenalmIDString() string {
return e.GetString(MUSENALMID_FIELD)
}
func (e *Entry) SetMusenalmID(musenalmID int) {
e.Set(MUSENALMID_FIELD, musenalmID)
}

View File

@@ -2,7 +2,6 @@ package dbmodels
import (
"errors"
"fmt"
"strconv"
"strings"
"unicode"
@@ -162,7 +161,6 @@ func NormalizeQuery(query string) Query {
}
for _, r := range query {
fmt.Printf("Rune: %v\n", r)
if r == '"' {
if isInQuotes {
addToken()
@@ -185,12 +183,6 @@ func NormalizeQuery(query string) Query {
at()
}
fmt.Printf("Query: %v\n", query)
fmt.Printf("Include: %v\n", include)
fmt.Printf("Exclude: %v\n", exclude)
fmt.Printf("UnsafeI: %v\n", unsafeI)
fmt.Printf("UnsafeE: %v\n", unsafeE)
return Query{
Include: include,
Exclude: exclude,

View File

@@ -1,6 +1,7 @@
package dbmodels
import (
"strconv"
"strings"
"github.com/Theodor-Springmann-Stiftung/musenalm/helpers/datatypes"
@@ -146,7 +147,7 @@ func (q *FTS5Query) Query() string {
query += " { " + strings.Join(m.Fields, " ") + " } : \"" + q.Escape(m.Value) + "\""
}
query += "'"
query += "' LIMIT " + strconv.Itoa(FTS_LIMIT)
return query
}

View File

@@ -14,7 +14,7 @@ import (
// For scanning, with an Iter_ prefix, yields single row results
func REntriesAgents_Agent(app core.App, id string) ([]*REntriesAgents, error) {
return TableByFields[[]*REntriesAgents](
return TableByFields[*REntriesAgents](
app,
RelationTableName(ENTRIES_TABLE, AGENTS_TABLE),
AGENTS_TABLE,
@@ -23,7 +23,7 @@ func REntriesAgents_Agent(app core.App, id string) ([]*REntriesAgents, error) {
}
func REntriesAgents_Entry(app core.App, id string) ([]*REntriesAgents, error) {
return TableByFields[[]*REntriesAgents](
return TableByFields[*REntriesAgents](
app,
RelationTableName(ENTRIES_TABLE, AGENTS_TABLE),
ENTRIES_TABLE,
@@ -32,7 +32,7 @@ func REntriesAgents_Entry(app core.App, id string) ([]*REntriesAgents, error) {
}
func REntriesAgents_Entries(app core.App, ids []any) ([]*REntriesAgents, error) {
return TableByFields[[]*REntriesAgents](
return TableByFields[*REntriesAgents](
app,
RelationTableName(ENTRIES_TABLE, AGENTS_TABLE),
ENTRIES_TABLE,
@@ -41,7 +41,7 @@ func REntriesAgents_Entries(app core.App, ids []any) ([]*REntriesAgents, error)
}
func RContentsAgents_Agent(app core.App, id string) ([]*RContentsAgents, error) {
return TableByFields[[]*RContentsAgents](
return TableByFields[*RContentsAgents](
app,
RelationTableName(CONTENTS_TABLE, AGENTS_TABLE),
AGENTS_TABLE,
@@ -50,7 +50,7 @@ func RContentsAgents_Agent(app core.App, id string) ([]*RContentsAgents, error)
}
func RContentsAgents_Contents(app core.App, id []any) ([]*RContentsAgents, error) {
return TableByFields[[]*RContentsAgents](
return TableByFields[*RContentsAgents](
app,
RelationTableName(CONTENTS_TABLE, AGENTS_TABLE),
CONTENTS_TABLE,
@@ -59,7 +59,7 @@ func RContentsAgents_Contents(app core.App, id []any) ([]*RContentsAgents, error
}
func RContentsAgents_Content(app core.App, id string) ([]*RContentsAgents, error) {
return TableByFields[[]*RContentsAgents](
return TableByFields[*RContentsAgents](
app,
RelationTableName(CONTENTS_TABLE, AGENTS_TABLE),
CONTENTS_TABLE,
@@ -68,7 +68,7 @@ func RContentsAgents_Content(app core.App, id string) ([]*RContentsAgents, error
}
func REntriesSeries_Entries(app core.App, ids []any) ([]*REntriesSeries, error) {
return TableByFields[[]*REntriesSeries](
return TableByFields[*REntriesSeries](
app,
RelationTableName(ENTRIES_TABLE, SERIES_TABLE),
ENTRIES_TABLE,
@@ -77,7 +77,7 @@ func REntriesSeries_Entries(app core.App, ids []any) ([]*REntriesSeries, error)
}
func REntriesSeries_Entry(app core.App, id string) ([]*REntriesSeries, error) {
return TableByFields[[]*REntriesSeries](
return TableByFields[*REntriesSeries](
app,
RelationTableName(ENTRIES_TABLE, SERIES_TABLE),
ENTRIES_TABLE,
@@ -86,7 +86,7 @@ func REntriesSeries_Entry(app core.App, id string) ([]*REntriesSeries, error) {
}
func REntriesSeries_Seriess(app core.App, ids []any) ([]*REntriesSeries, error) {
return TableByFields[[]*REntriesSeries](
return TableByFields[*REntriesSeries](
app,
RelationTableName(ENTRIES_TABLE, SERIES_TABLE),
SERIES_TABLE,
@@ -100,7 +100,7 @@ func Agents_ID(app core.App, id string) (*Agent, error) {
}
func Agents_IDs(app core.App, ids []any) ([]*Agent, error) {
return TableByIDs[[]*Agent](app, AGENTS_TABLE, ids)
return TableByIDs[*Agent](app, AGENTS_TABLE, ids)
}
func Entries_ID(app core.App, id string) (*Entry, error) {
@@ -114,11 +114,11 @@ func Entries_MusenalmID(app core.App, id string) (*Entry, error) {
}
func Entries_IDs(app core.App, ids []any) ([]*Entry, error) {
return TableByIDs[[]*Entry](app, ENTRIES_TABLE, ids)
return TableByIDs[*Entry](app, ENTRIES_TABLE, ids)
}
func Series_IDs(app core.App, ids []any) ([]*Series, error) {
return TableByIDs[[]*Series](app, SERIES_TABLE, ids)
return TableByIDs[*Series](app, SERIES_TABLE, ids)
}
func Series_MusenalmID(app core.App, id string) (*Series, error) {
@@ -132,15 +132,15 @@ func Series_ID(app core.App, id string) (*Series, error) {
}
func Places_IDs(app core.App, ids []any) ([]*Place, error) {
return TableByIDs[[]*Place](app, PLACES_TABLE, ids)
return TableByIDs[*Place](app, PLACES_TABLE, ids)
}
func Contents_IDs(app core.App, ids []any) ([]*Content, error) {
return TableByIDs[[]*Content](app, CONTENTS_TABLE, ids)
return TableByIDs[*Content](app, CONTENTS_TABLE, ids)
}
func Contents_Entry(app core.App, id string) ([]*Content, error) {
return TableByFields[[]*Content](
return TableByFields[*Content](
app,
CONTENTS_TABLE,
ENTRIES_TABLE,

View File

@@ -2,6 +2,7 @@ package dbmodels
import (
"iter"
"reflect"
"github.com/pocketbase/dbx"
"github.com/pocketbase/pocketbase/core"
@@ -61,6 +62,11 @@ import (
// github.com/pocketbase/pocketbase/apis.NewRouter.BodyLimit.func7(0xc0002da000)
//
// /home
const (
QUERY_PARTITION_SIZE = 1200
)
func Iter_TableByField[T interface{}](app core.App, table, field string, value interface{}) (iter.Seq2[*T, error], error) {
rows, err := app.RecordQuery(table).
Where(dbx.HashExp{field: value}).
@@ -111,13 +117,42 @@ func TableByField[T interface{}](app core.App, table, field string, value string
return ret, nil
}
func TableByFields[T interface{}](app core.App, table, field string, values any) (T, error) {
var ret T
err := app.RecordQuery(table).
Where(dbx.HashExp{field: values}).
All(&ret)
if err != nil {
return ret, err
func TableByFields[T interface{}](app core.App, table, field string, values any) ([]T, error) {
var ret []T
if reflect.TypeOf(values).Kind() == reflect.Slice {
v := values.([]any)
if len(v) > QUERY_PARTITION_SIZE {
for i := 0; i < len(v); i += QUERY_PARTITION_SIZE {
part := v[i:]
if len(part) > QUERY_PARTITION_SIZE {
part = part[:QUERY_PARTITION_SIZE]
}
var partret []T
err := app.RecordQuery(table).
Where(dbx.HashExp{field: part}).
All(&partret)
if err != nil {
return ret, err
}
ret = append(ret, partret...)
}
} else {
err := app.RecordQuery(table).
Where(dbx.HashExp{field: values}).
All(&ret)
if err != nil {
return ret, err
}
}
} else {
err := app.RecordQuery(table).
Where(dbx.HashExp{field: values}).
All(&ret)
if err != nil {
return ret, err
}
}
return ret, nil
@@ -135,13 +170,32 @@ func TableByID[T interface{}](app core.App, table, id string) (T, error) {
return ret, nil
}
func TableByIDs[T interface{}](app core.App, table string, ids []any) (T, error) {
var ret T
err := app.RecordQuery(table).
Where(dbx.HashExp{ID_FIELD: ids}).
All(&ret)
if err != nil {
return ret, err
func TableByIDs[T interface{}](app core.App, table string, ids []any) ([]T, error) {
var ret []T
if len(ids) > QUERY_PARTITION_SIZE {
for i := 0; i < len(ids); i += QUERY_PARTITION_SIZE {
part := ids[i:]
if len(part) > QUERY_PARTITION_SIZE {
part = part[:QUERY_PARTITION_SIZE]
}
var partret []T
err := app.RecordQuery(table).
Where(dbx.HashExp{ID_FIELD: part}).
All(&partret)
if err != nil {
return ret, err
}
ret = append(ret, partret...)
}
} else {
err := app.RecordQuery(table).
Where(dbx.HashExp{ID_FIELD: ids}).
All(&ret)
if err != nil {
return ret, err
}
}
return ret, nil