add limit to search
This commit is contained in:
parent
41682f1712
commit
b4d2de6ec8
@ -323,10 +323,10 @@ type Database interface {
|
|||||||
GetPostingStats(granularity, begin, end int64) (PostingStats, error)
|
GetPostingStats(granularity, begin, end int64) (PostingStats, error)
|
||||||
|
|
||||||
// peform search query
|
// peform search query
|
||||||
SearchQuery(prefix, group, text string, chnl chan PostModel) error
|
SearchQuery(prefix, group, text string, chnl chan PostModel, limit int) error
|
||||||
|
|
||||||
// find posts with similar hash
|
// find posts with similar hash
|
||||||
SearchByHash(prefix, group, posthash string, chnl chan PostModel) error
|
SearchByHash(prefix, group, posthash string, chnl chan PostModel, limit int) error
|
||||||
|
|
||||||
// get full thread model
|
// get full thread model
|
||||||
GetThreadModel(prefix, root_msgid string) (ThreadModel, error)
|
GetThreadModel(prefix, root_msgid string) (ThreadModel, error)
|
||||||
|
@ -1112,10 +1112,11 @@ func (self *httpFrontend) handle_api_find(wr http.ResponseWriter, r *http.Reques
|
|||||||
}
|
}
|
||||||
donechnl <- 0
|
donechnl <- 0
|
||||||
}(wr)
|
}(wr)
|
||||||
|
limit := 50
|
||||||
if len(h) > 0 {
|
if len(h) > 0 {
|
||||||
self.daemon.database.SearchByHash(self.prefix, g, h, chnl)
|
self.daemon.database.SearchByHash(self.prefix, g, h, chnl, limit)
|
||||||
} else {
|
} else {
|
||||||
self.daemon.database.SearchQuery(self.prefix, g, s, chnl)
|
self.daemon.database.SearchQuery(self.prefix, g, s, chnl, limit)
|
||||||
}
|
}
|
||||||
chnl <- nil
|
chnl <- nil
|
||||||
<-donechnl
|
<-donechnl
|
||||||
|
@ -219,10 +219,10 @@ func (self *PostgresDatabase) prepareStatements() {
|
|||||||
GetMessageIDByCIDR: "SELECT message_id FROM ArticlePosts WHERE addr IN ( SELECT encaddr FROM EncryptedAddrs WHERE addr_cidr <<= cidr($1) )",
|
GetMessageIDByCIDR: "SELECT message_id FROM ArticlePosts WHERE addr IN ( SELECT encaddr FROM EncryptedAddrs WHERE addr_cidr <<= cidr($1) )",
|
||||||
GetMessageIDByEncryptedIP: "SELECT message_id FROM ArticlePosts WHERE addr = $1",
|
GetMessageIDByEncryptedIP: "SELECT message_id FROM ArticlePosts WHERE addr = $1",
|
||||||
GetPostsBefore: "SELECT message_id FROM ArticlePosts WHERE time_posted < $1",
|
GetPostsBefore: "SELECT message_id FROM ArticlePosts WHERE time_posted < $1",
|
||||||
SearchQuery_1: "SELECT newsgroup, message_id, ref_id FROM ArticlePosts WHERE message LIKE $1 ORDER BY time_posted DESC",
|
SearchQuery_1: "SELECT newsgroup, message_id, ref_id FROM ArticlePosts WHERE message LIKE $1 ORDER BY time_posted DESC LIMIT $2",
|
||||||
SearchQuery_2: "SELECT newsgroup, message_id, ref_id FROM ArticlePosts WHERE newsgroup = $1 AND message LIKE $2 ORDER BY time_posted DESC",
|
SearchQuery_2: "SELECT newsgroup, message_id, ref_id FROM ArticlePosts WHERE newsgroup = $1 AND message LIKE $2 ORDER BY time_posted DESC LIMIT $3",
|
||||||
SearchByHash_1: "SELECT message_newsgroup, message_id, message_ref_id FROM Articles WHERE message_id_hash LIKE $1 ORDER BY time_obtained DESC",
|
SearchByHash_1: "SELECT message_newsgroup, message_id, message_ref_id FROM Articles WHERE message_id_hash LIKE $1 ORDER BY time_obtained DESC LIMIT $2",
|
||||||
SearchByHash_2: "SELECT message_newsgroup, message_id, message_ref_id FROM Articles WHERE message_newsgroup = $2 AND message_id_hash LIKE $1 ORDER BY time_obtained DESC",
|
SearchByHash_2: "SELECT message_newsgroup, message_id, message_ref_id FROM Articles WHERE message_newsgroup = $2 AND message_id_hash LIKE $1 ORDER BY time_obtained DESC LIMIT $3",
|
||||||
GetNNTPPostsInGroup: "SELECT message_no, ArticlePosts.message_id, subject, time_posted, ref_id, name, path FROM ArticleNumbers INNER JOIN ArticlePosts ON ArticleNumbers.message_id = ArticlePosts.message_id WHERE ArticlePosts.newsgroup = $1 ORDER BY message_no",
|
GetNNTPPostsInGroup: "SELECT message_no, ArticlePosts.message_id, subject, time_posted, ref_id, name, path FROM ArticleNumbers INNER JOIN ArticlePosts ON ArticleNumbers.message_id = ArticlePosts.message_id WHERE ArticlePosts.newsgroup = $1 ORDER BY message_no",
|
||||||
GetCitesByPostHashLike: "SELECT message_id, message_ref_id FROM Articles WHERE message_id_hash LIKE $1",
|
GetCitesByPostHashLike: "SELECT message_id, message_ref_id FROM Articles WHERE message_id_hash LIKE $1",
|
||||||
GetYearlyPostHistory: "WITH times(endtime, begintime) AS ( SELECT CAST(EXTRACT(epoch from i) AS BIGINT) AS endtime, CAST(EXTRACT(epoch from i - interval '1 month') AS BIGINT) AS begintime FROM generate_series(now() - interval '10 year', now(), '1 month'::interval) i ) SELECT begintime, endtime, ( SELECT count(*) FROM ArticlePosts WHERE time_posted > begintime AND time_posted < endtime) FROM times",
|
GetYearlyPostHistory: "WITH times(endtime, begintime) AS ( SELECT CAST(EXTRACT(epoch from i) AS BIGINT) AS endtime, CAST(EXTRACT(epoch from i - interval '1 month') AS BIGINT) AS begintime FROM generate_series(now() - interval '10 year', now(), '1 month'::interval) i ) SELECT begintime, endtime, ( SELECT count(*) FROM ArticlePosts WHERE time_posted > begintime AND time_posted < endtime) FROM times",
|
||||||
@ -1970,14 +1970,14 @@ func (self *PostgresDatabase) GetPostingStats(gran, begin, end int64) (st Postin
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *PostgresDatabase) SearchQuery(prefix, group string, text string, chnl chan PostModel) (err error) {
|
func (self *PostgresDatabase) SearchQuery(prefix, group string, text string, chnl chan PostModel, limit int) (err error) {
|
||||||
if text != "" && strings.Count(text, "%") == 0 {
|
if text != "" && strings.Count(text, "%") == 0 {
|
||||||
text = "%" + text + "%"
|
text = "%" + text + "%"
|
||||||
var rows *sql.Rows
|
var rows *sql.Rows
|
||||||
if group == "" {
|
if group == "" {
|
||||||
rows, err = self.conn.Query(self.stmt[SearchQuery_1], text)
|
rows, err = self.conn.Query(self.stmt[SearchQuery_1], text, limit)
|
||||||
} else {
|
} else {
|
||||||
rows, err = self.conn.Query(self.stmt[SearchQuery_2], group, text)
|
rows, err = self.conn.Query(self.stmt[SearchQuery_2], group, text, limit)
|
||||||
}
|
}
|
||||||
if err == nil {
|
if err == nil {
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
@ -1991,15 +1991,15 @@ func (self *PostgresDatabase) SearchQuery(prefix, group string, text string, chn
|
|||||||
close(chnl)
|
close(chnl)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
func (self *PostgresDatabase) SearchByHash(prefix, group, text string, chnl chan PostModel) (err error) {
|
func (self *PostgresDatabase) SearchByHash(prefix, group, text string, chnl chan PostModel, limit int) (err error) {
|
||||||
if text != "" && strings.Count(text, "%") == 0 {
|
if text != "" && strings.Count(text, "%") == 0 {
|
||||||
text = "%" + text + "%"
|
text = "%" + text + "%"
|
||||||
var rows *sql.Rows
|
var rows *sql.Rows
|
||||||
if group == "" {
|
if group == "" {
|
||||||
rows, err = self.conn.Query(self.stmt[SearchByHash_1], text)
|
rows, err = self.conn.Query(self.stmt[SearchByHash_1], text, limit)
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
rows, err = self.conn.Query(self.stmt[SearchByHash_2], text, group)
|
rows, err = self.conn.Query(self.stmt[SearchByHash_2], text, group, limit)
|
||||||
}
|
}
|
||||||
if err == nil {
|
if err == nil {
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
|
Reference in New Issue
Block a user