diff options
author | 2023-12-10 14:15:41 +0100 | |
---|---|---|
committer | 2023-12-10 14:15:41 +0100 | |
commit | 3f070a442a5ffdd771a4937fe079d95672fa3e3f (patch) | |
tree | f6412bb7497d2e3d6cbe39021838adb2d00a8edf /internal/processing/search/accounts.go | |
parent | [bugfix] Ensure `pre` renders as expected, fix orderedCollectionPage (#2434) (diff) | |
download | gotosocial-3f070a442a5ffdd771a4937fe079d95672fa3e3f.tar.xz |
[bugfix] Narrow search scope for accounts starting with '@'; don't LOWER SQLite text searches (#2435)
Diffstat (limited to 'internal/processing/search/accounts.go')
-rw-r--r-- | internal/processing/search/accounts.go | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/internal/processing/search/accounts.go b/internal/processing/search/accounts.go index 17002a29b..7201d0688 100644 --- a/internal/processing/search/accounts.go +++ b/internal/processing/search/accounts.go @@ -74,13 +74,6 @@ func (p *Processor) Accounts( return nil, gtserror.NewErrorBadRequest(err, err.Error()) } - // Be nice and normalize query by prepending '@'. - // This will make it easier for accountsByNamestring - // to pick this up as a valid namestring. - if query[0] != '@' { - query = "@" + query - } - log. WithContext(ctx). WithFields(kv.Fields{ @@ -107,9 +100,7 @@ func (p *Processor) Accounts( // See if we have something that looks like a namestring. username, domain, err := util.ExtractNamestringParts(query) - if err != nil { - log.Warnf(ctx, "couldn't parse '%s' as namestring: %v", query, err) - } else { + if err == nil { if domain != "" { // Search was an exact namestring; // we can safely assume caller is @@ -121,7 +112,7 @@ func (p *Processor) Accounts( // Get all accounts we can find // that match the provided query. - if err := p.accountsByNamestring( + if err := p.accountsByUsernameDomain( ctx, requestingAccount, id.Highest, @@ -137,6 +128,23 @@ func (p *Processor) Accounts( err = gtserror.Newf("error searching by namestring: %w", err) return nil, gtserror.NewErrorInternalError(err) } + } else { + // Query Doesn't look like a + // namestring, use text search. + if err := p.accountsByText( + ctx, + requestingAccount.ID, + id.Highest, + id.Lowest, + limit, + offset, + query, + following, + appendAccount, + ); err != nil && !errors.Is(err, db.ErrNoEntries) { + err = gtserror.Newf("error searching by text: %w", err) + return nil, gtserror.NewErrorInternalError(err) + } } // Return whatever we got (if anything). |