diff options
| author | 2024-05-31 03:57:42 -0700 | |
|---|---|---|
| committer | 2024-05-31 12:57:42 +0200 | |
| commit | 04bcde08a1b9994ceb384749c2fe095d6d9eee8c (patch) | |
| tree | e18afb15643e9ffa5732c3902b4257b8361578bd /internal/db/bundb | |
| parent | [feature] Implement Filter API v2 (#2936) (diff) | |
| download | gotosocial-04bcde08a1b9994ceb384749c2fe095d6d9eee8c.tar.xz | |
[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
Diffstat (limited to 'internal/db/bundb')
| -rw-r--r-- | internal/db/bundb/search.go | 10 | ||||
| -rw-r--r-- | internal/db/bundb/search_test.go | 13 | 
2 files changed, 19 insertions, 4 deletions
| diff --git a/internal/db/bundb/search.go b/internal/db/bundb/search.go index f8ae529f7..e54cb78e7 100644 --- a/internal/db/bundb/search.go +++ b/internal/db/bundb/search.go @@ -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 == "" { diff --git a/internal/db/bundb/search_test.go b/internal/db/bundb/search_test.go index 75a2d8c8e..cf24b2881 100644 --- a/internal/db/bundb/search_test.go +++ b/internal/db/bundb/search_test.go @@ -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) | 
