mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2025-06-05 21:59:39 +02:00
[feature] Add from: search operator and account_id query param (#2943)
* Add from: search operator * Fix whitespace in Swagger YAML comment * Move query parsing into its own method * Document search * Clarify post search scope
This commit is contained in:
@@ -266,8 +266,9 @@ func (s *searchDB) accountText(following bool) *bun.SelectQuery {
|
||||
// ORDER BY "status"."id" DESC LIMIT 10
|
||||
func (s *searchDB) SearchForStatuses(
|
||||
ctx context.Context,
|
||||
accountID string,
|
||||
requestingAccountID string,
|
||||
query string,
|
||||
fromAccountID string,
|
||||
maxID string,
|
||||
minID string,
|
||||
limit int,
|
||||
@@ -295,9 +296,12 @@ func (s *searchDB) SearchForStatuses(
|
||||
// accountID or replying to accountID.
|
||||
WhereGroup(" AND ", func(q *bun.SelectQuery) *bun.SelectQuery {
|
||||
return q.
|
||||
Where("? = ?", bun.Ident("status.account_id"), accountID).
|
||||
WhereOr("? = ?", bun.Ident("status.in_reply_to_account_id"), accountID)
|
||||
Where("? = ?", bun.Ident("status.account_id"), requestingAccountID).
|
||||
WhereOr("? = ?", bun.Ident("status.in_reply_to_account_id"), requestingAccountID)
|
||||
})
|
||||
if fromAccountID != "" {
|
||||
q = q.Where("? = ?", bun.Ident("status.account_id"), fromAccountID)
|
||||
}
|
||||
|
||||
// Return only items with a LOWER id than maxID.
|
||||
if maxID == "" {
|
||||
|
@@ -107,11 +107,22 @@ func (suite *SearchTestSuite) TestSearchAccountsFossAny() {
|
||||
func (suite *SearchTestSuite) TestSearchStatuses() {
|
||||
testAccount := suite.testAccounts["local_account_1"]
|
||||
|
||||
statuses, err := suite.db.SearchForStatuses(context.Background(), testAccount.ID, "hello", "", "", 10, 0)
|
||||
statuses, err := suite.db.SearchForStatuses(context.Background(), testAccount.ID, "hello", "", "", "", 10, 0)
|
||||
suite.NoError(err)
|
||||
suite.Len(statuses, 1)
|
||||
}
|
||||
|
||||
func (suite *SearchTestSuite) TestSearchStatusesFromAccount() {
|
||||
testAccount := suite.testAccounts["local_account_1"]
|
||||
fromAccount := suite.testAccounts["local_account_2"]
|
||||
|
||||
statuses, err := suite.db.SearchForStatuses(context.Background(), testAccount.ID, "hi", fromAccount.ID, "", "", 10, 0)
|
||||
suite.NoError(err)
|
||||
if suite.Len(statuses, 1) {
|
||||
suite.Equal(fromAccount.ID, statuses[0].AccountID)
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *SearchTestSuite) TestSearchTags() {
|
||||
// Search with full tag string.
|
||||
tags, err := suite.db.SearchForTags(context.Background(), "welcome", "", "", 10, 0)
|
||||
|
@@ -27,8 +27,9 @@ type Search interface {
|
||||
// SearchForAccounts uses the given query text to search for accounts that accountID follows.
|
||||
SearchForAccounts(ctx context.Context, accountID string, query string, maxID string, minID string, limit int, following bool, offset int) ([]*gtsmodel.Account, error)
|
||||
|
||||
// SearchForStatuses uses the given query text to search for statuses created by accountID, or in reply to accountID.
|
||||
SearchForStatuses(ctx context.Context, accountID string, query string, maxID string, minID string, limit int, offset int) ([]*gtsmodel.Status, error)
|
||||
// SearchForStatuses uses the given query text to search for statuses created by requestingAccountID, or in reply to requestingAccountID.
|
||||
// If fromAccountID is used, the results are restricted to statuses created by fromAccountID.
|
||||
SearchForStatuses(ctx context.Context, requestingAccountID string, query string, fromAccountID string, maxID string, minID string, limit int, offset int) ([]*gtsmodel.Status, error)
|
||||
|
||||
// SearchForTags searches for tags that start with the given query text (case insensitive).
|
||||
SearchForTags(ctx context.Context, query string, maxID string, minID string, limit int, offset int) ([]*gtsmodel.Tag, error)
|
||||
|
Reference in New Issue
Block a user