negated search terms

master
Ted Unangst 5 years ago
parent 5435dd1b3f
commit a50115d65f

@ -249,8 +249,10 @@ func gethonksbysearch(userid int64, q string, wanted int64) []*Honk {
withhonker := 0 withhonker := 0
site := "" site := ""
withsite := 0 withsite := 0
withnotq := 0
terms := strings.Split(q, " ") terms := strings.Split(q, " ")
q = "%" q = "%"
notq := "%"
for _, t := range terms { for _, t := range terms {
if strings.HasPrefix(t, "site:") { if strings.HasPrefix(t, "site:") {
site = t[5:] site = t[5:]
@ -267,13 +269,27 @@ func gethonksbysearch(userid int64, q string, wanted int64) []*Honk {
withhonker = 1 withhonker = 1
continue continue
} }
if t[0] == '-' {
if t == "-" {
continue
}
if len(notq) != 1 {
notq += " "
}
notq += t[1:]
continue
}
if len(q) != 1 { if len(q) != 1 {
q += " " q += " "
} }
q += t q += t
} }
q += "%" 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) honks := getsomehonks(rows, err)
return honks 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) 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) 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) 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) 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) 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)

@ -2,6 +2,8 @@ changelog
-- next -- next
+ Negated search -terms.
+ A raw sendactivity API action for the bold. + A raw sendactivity API action for the bold.
+ More flexible meme names. + More flexible meme names.

@ -143,11 +143,14 @@ The following keywords are supported:
Substring match on the post domain name. Substring match on the post domain name.
.It honker .It honker
Exact match, either AP actor or honker nickname. Exact match, either AP actor or honker nickname.
.It -
Negate term.
.El .El
.Pp .Pp
Example: Example:
.Dl honker:goose big moose .Dl honker:goose big moose -footloose
This query will find honks by the goose about the big moose. This query will find honks by the goose about the big moose, but excluding
those about footloose.
.Ss Filtering .Ss Filtering
Sometimes other users of the federation can get unruly. Sometimes other users of the federation can get unruly.
The honk filtering and censorship system, The honk filtering and censorship system,

Loading…
Cancel
Save