From a50115d65f25c8040dbe6bf5151433b9f340dd81 Mon Sep 17 00:00:00 2001 From: Ted Unangst Date: Thu, 28 Nov 2019 02:14:07 -0500 Subject: [PATCH] negated search terms --- database.go | 20 ++++++++++++++++++-- docs/changelog.txt | 2 ++ docs/honk.1 | 7 +++++-- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/database.go b/database.go index 9cfe7b2..4851b6d 100644 --- a/database.go +++ b/database.go @@ -249,8 +249,10 @@ func gethonksbysearch(userid int64, q string, wanted int64) []*Honk { withhonker := 0 site := "" withsite := 0 + withnotq := 0 terms := strings.Split(q, " ") q = "%" + notq := "%" for _, t := range terms { if strings.HasPrefix(t, "site:") { site = t[5:] @@ -267,13 +269,27 @@ func gethonksbysearch(userid int64, q string, wanted int64) []*Honk { withhonker = 1 continue } + if t[0] == '-' { + if t == "-" { + continue + } + if len(notq) != 1 { + notq += " " + } + notq += t[1:] + continue + } if len(q) != 1 { q += " " } q += t } q += "%" - rows, err := stmtHonksBySearch.Query(wanted, userid, withsite, site, withhonker, honker, honker, q, userid) + notq += "%" + if notq != "%%" { + withnotq = 1 + } + rows, err := stmtHonksBySearch.Query(wanted, userid, withsite, site, withhonker, honker, honker, q, withnotq, notq, userid) honks := getsomehonks(rows, err) return honks } @@ -748,7 +764,7 @@ func prepareStatements(db *sql.DB) { stmtHonksByHonker = preparetodie(db, selecthonks+"join honkers on (honkers.xid = honks.honker or honkers.xid = honks.oonker) where honks.honkid > ? and honks.userid = ? and honkers.name = ?"+butnotthose+limit) stmtHonksByXonker = preparetodie(db, selecthonks+" where honks.honkid > ? and honks.userid = ? and (honker = ? or oonker = ?)"+butnotthose+limit) stmtHonksByCombo = preparetodie(db, selecthonks+" where honks.honkid > ? and honks.userid = ? and honks.honker in (select xid from honkers where honkers.userid = ? and honkers.combos like ?) "+butnotthose+" union "+selecthonks+"join onts on honks.honkid = onts.honkid where honks.honkid > ? and honks.userid = ? and onts.ontology in (select xid from honkers where combos like ?)"+butnotthose+limit) - stmtHonksBySearch = preparetodie(db, selecthonks+"where honks.honkid > ? and honks.userid = ? and (? = 0 or xid like ?) and (? = 0 or honks.honker = ? or honks.oonker = ?) and noise like ?"+butnotthose+limit) + stmtHonksBySearch = preparetodie(db, selecthonks+"where honks.honkid > ? and honks.userid = ? and (? = 0 or xid like ?) and (? = 0 or honks.honker = ? or honks.oonker = ?) and noise like ? and (? = 0 or noise not like ?)"+butnotthose+limit) stmtHonksByConvoy = preparetodie(db, selecthonks+"where honks.honkid > ? and (honks.userid = ? or (? = -1 and whofore = 2)) and convoy = ?"+limit) stmtHonksByOntology = preparetodie(db, selecthonks+"join onts on honks.honkid = onts.honkid where honks.honkid > ? and onts.ontology = ? and (honks.userid = ? or (? = -1 and honks.whofore = 2))"+limit) diff --git a/docs/changelog.txt b/docs/changelog.txt index 6cfd523..cbb945d 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -2,6 +2,8 @@ changelog -- next ++ Negated search -terms. + + A raw sendactivity API action for the bold. + More flexible meme names. diff --git a/docs/honk.1 b/docs/honk.1 index d9e679d..267e785 100644 --- a/docs/honk.1 +++ b/docs/honk.1 @@ -143,11 +143,14 @@ The following keywords are supported: Substring match on the post domain name. .It honker Exact match, either AP actor or honker nickname. +.It - +Negate term. .El .Pp Example: -.Dl honker:goose big moose -This query will find honks by the goose about the big moose. +.Dl honker:goose big moose -footloose +This query will find honks by the goose about the big moose, but excluding +those about footloose. .Ss Filtering Sometimes other users of the federation can get unruly. The honk filtering and censorship system,