all repos — honk @ 67e3355d0a33fc01e2d3bde42656e1f0807773a7

my fork of honk

create a plain column and use that for search
Ted Unangst tedu@tedunangst.com
Mon, 31 Jul 2023 19:46:55 -0400
commit

67e3355d0a33fc01e2d3bde42656e1f0807773a7

parent

ecb128359cc8ba608aad7ae1ae7a09a2a6b2b212

4 files changed, 48 insertions(+), 11 deletions(-)

jump to
M database.godatabase.go

@@ -30,6 +30,7 @@ "sync"

"time" "humungus.tedunangst.com/r/webs/cache" + "humungus.tedunangst.com/r/webs/htfilter" "humungus.tedunangst.com/r/webs/httpsig" "humungus.tedunangst.com/r/webs/login" "humungus.tedunangst.com/r/webs/mz"

@@ -342,8 +343,7 @@ params = append(params, honker)

continue } t = "%" + t + "%" - queries = append(queries, negate+"(noise like ? or precis like ?)") - params = append(params, t) + queries = append(queries, negate+"(plain like ?)") params = append(params, t) }

@@ -789,6 +789,27 @@

return chatter } +func (honk *Honk) Plain() string { + var plain []string + var filt htfilter.Filter + filt.WithLinks = true + if honk.Precis != "" { + t, _ := filt.TextOnly(honk.Precis) + plain = append(plain, t) + } + if honk.Format == "html" { + t, _ := filt.TextOnly(honk.Noise) + plain = append(plain, t) + } else { + plain = append(plain, honk.Noise) + } + for _, d := range honk.Donks { + plain = append(plain, d.Name) + plain = append(plain, d.Desc) + } + return strings.Join(plain, " ") +} + func savehonk(h *Honk) error { dt := h.Date.UTC().Format(dbtimeformat) aud := strings.Join(h.Audience, " ")

@@ -799,10 +820,11 @@ if err != nil {

elog.Printf("can't begin tx: %s", err) return err } + plain := h.Plain() res, err := tx.Stmt(stmtSaveHonk).Exec(h.UserID, h.What, h.Honker, h.XID, h.RID, dt, h.URL, aud, h.Noise, h.Convoy, h.Whofore, h.Format, h.Precis, - h.Oonker, h.Flags) + h.Oonker, h.Flags, plain) if err == nil { h.ID, _ = res.LastInsertId() err = saveextras(tx, h)

@@ -833,10 +855,11 @@ if err != nil {

elog.Printf("can't begin tx: %s", err) return err } + plain := h.Plain() err = deleteextras(tx, h.ID, false) if err == nil { - _, err = tx.Stmt(stmtUpdateHonk).Exec(h.Precis, h.Noise, h.Format, h.Whofore, dt, h.ID) + _, err = tx.Stmt(stmtUpdateHonk).Exec(h.Precis, h.Noise, h.Format, h.Whofore, dt, plain, h.ID) } if err == nil { err = saveextras(tx, h)

@@ -1171,9 +1194,9 @@ stmtSaveMeta = preparetodie(db, "insert into honkmeta (honkid, genus, json) values (?, ?, ?)")

stmtDeleteAllMeta = preparetodie(db, "delete from honkmeta where honkid = ?") stmtDeleteSomeMeta = preparetodie(db, "delete from honkmeta where honkid = ? and genus not in ('oldrev')") stmtDeleteOneMeta = preparetodie(db, "delete from honkmeta where honkid = ? and genus = ?") - stmtSaveHonk = preparetodie(db, "insert into honks (userid, what, honker, xid, rid, dt, url, audience, noise, convoy, whofore, format, precis, oonker, flags) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)") + stmtSaveHonk = preparetodie(db, "insert into honks (userid, what, honker, xid, rid, dt, url, audience, noise, convoy, whofore, format, precis, oonker, flags, plain) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)") stmtDeleteHonk = preparetodie(db, "delete from honks where honkid = ?") - stmtUpdateHonk = preparetodie(db, "update honks set precis = ?, noise = ?, format = ?, whofore = ?, dt = ? where honkid = ?") + stmtUpdateHonk = preparetodie(db, "update honks set precis = ?, noise = ?, format = ?, whofore = ?, dt = ?, plain = ? where honkid = ?") stmtSaveOnt = preparetodie(db, "insert into onts (ontology, honkid) values (?, ?)") stmtDeleteOnts = preparetodie(db, "delete from onts where honkid = ?") stmtSaveDonk = preparetodie(db, "insert into donks (honkid, chonkid, fileid) values (?, ?, ?)")
M honk.gohonk.go

@@ -152,10 +152,10 @@ if strings.HasPrefix(noise[idx:], "#<span>") {

idx += 6 } idx += 1 - if idx + len(ont) >= len(noise) { + if idx+len(ont) >= len(noise) { return false } - test := noise[idx:idx+len(ont)] + test := noise[idx : idx+len(ont)] test = strings.ToLower(test) if test == ont { return true
M schema.sqlschema.sql

@@ -1,5 +1,4 @@

- -create table honks (honkid integer primary key, userid integer, what text, honker text, xid text, rid text, dt text, url text, audience text, noise text, convoy text, whofore integer, format text, precis text, oonker text, flags integer); +create table honks (honkid integer primary key, userid integer, what text, honker text, xid text, rid text, dt text, url text, audience text, noise text, convoy text, whofore integer, format text, precis text, oonker text, flags integer, plain text); create table chonks (chonkid integer primary key, userid integer, xid text, who txt, target text, dt text, noise text, format text); create table donks (honkid integer, chonkid integer, fileid integer); create table filemeta (fileid integer primary key, xid text, name text, description text, url text, media text, local integer);
M upgradedb.goupgradedb.go

@@ -20,7 +20,7 @@ "database/sql"

"os" ) -var myVersion = 43 +var myVersion = 44 type dbexecer interface { Exec(query string, args ...interface{}) (sql.Result, error)

@@ -42,6 +42,16 @@

if dbversion < 40 { elog.Fatal("database is too old to upgrade") } + try := func(s string, args ...interface{}) { + _, err := db.Exec(s, args...) + if err != nil { + elog.Fatalf("can't run %s: %s", s, err) + } + } + setV := func(ver int64) { + try("update config set value = ? where key = 'dbversion'", ver) + } + switch dbversion { case 40: doordie(db, "PRAGMA journal_mode=WAL")

@@ -87,6 +97,11 @@ doordie(db, "delete from honkmeta where genus = 'wonkles' or genus = 'guesses'")

doordie(db, "update config set value = 43 where key = 'dbversion'") fallthrough case 43: + try("alter table honks add column plain text") + try("update honks set plain = ''") + setV(44) + fallthrough + case 44: default: elog.Fatalf("can't upgrade unknown version %d", dbversion)