New query rules, big multi-user query optimization

This commit is contained in:
Zed 2020-06-17 14:16:48 +02:00
parent 2127af71b4
commit bc0ccb483a

View file

@ -51,25 +51,22 @@ proc genQueryParam*(query: Query): string =
if query.kind == users: if query.kind == users:
return query.text return query.text
let rewrite = rewriteReplies and query.fromUser.len > 0 and
query.kind notin {tweets, replies}
for i, user in query.fromUser: for i, user in query.fromUser:
if rewrite:
param &= &"(from:{user}(to:{user} OR -filter:replies)) "
else:
param &= &"from:{user} " param &= &"from:{user} "
if i < query.fromUser.high: if i < query.fromUser.high:
param &= "OR " param &= "OR "
if query.fromUser.len > 0 and query.kind in {posts, media}:
param &= "filter:self_threads OR-filter:replies "
if "nativeretweets" notin query.excludes: if "nativeretweets" notin query.excludes:
param &= "include:nativeretweets " param &= "include:nativeretweets "
let rewrite = query.fromUser.len > 0 and query.kind in {posts, media}
for f in query.filters: for f in query.filters:
filters.add "filter:" & f filters.add "filter:" & f
for e in query.excludes: for e in query.excludes:
if rewrite and e == "replies": continue if e == "nativeretweets": continue
filters.add "-filter:" & e filters.add "-filter:" & e
for i in query.includes: for i in query.includes:
filters.add "include:" & i filters.add "include:" & i
@ -82,10 +79,10 @@ proc genQueryParam*(query: Query): string =
if query.near.len > 0: if query.near.len > 0:
result &= &" near:\"{query.near}\" within:15mi" result &= &" near:\"{query.near}\" within:15mi"
if query.text.len > 0: if query.text.len > 0:
if result.len > 0:
result &= " " & query.text result &= " " & query.text
else:
if rewrite and result.len >= 500: result = query.text
return genQueryParam(query, rewriteReplies=false)
proc genQueryUrl*(query: Query): string = proc genQueryUrl*(query: Query): string =
if query.kind notin {tweets, users}: return if query.kind notin {tweets, users}: return