From aaf20de797b39c4d9a0236e203726fca08213c61 Mon Sep 17 00:00:00 2001 From: kim Date: Sun, 17 Oct 2021 11:43:28 +0100 Subject: [PATCH] fix search logic to match new mention matching logic Signed-off-by: kim --- internal/processing/search.go | 35 ++++++++++++++++------------------- internal/util/statustools.go | 5 ----- 2 files changed, 16 insertions(+), 24 deletions(-) diff --git a/internal/processing/search.go b/internal/processing/search.go index c5bfd722b..c5c648ba0 100644 --- a/internal/processing/search.go +++ b/internal/processing/search.go @@ -53,7 +53,7 @@ func (p *processor) SearchGet(ctx context.Context, authed *oauth.Auth, searchQue var foundOne bool // check if the query is something like @whatever_username@example.org -- this means it's a remote account - if !foundOne && util.IsMention(searchQuery.Query) { + if _, domain, err := util.ExtractMentionParts(searchQuery.Query); err == nil && domain != "" { l.Debug("search term is a mention, looking it up...") foundAccount, err := p.searchAccountByMention(ctx, authed, searchQuery.Query, searchQuery.Resolve) if err == nil && foundAccount != nil { @@ -64,25 +64,22 @@ func (p *processor) SearchGet(ctx context.Context, authed *oauth.Auth, searchQue } // check if the query is a URI and just do a lookup for that, straight up - if uri, err := url.Parse(query); err == nil && !foundOne { - // 1. check if it's a status - if foundStatus, err := p.searchStatusByURI(ctx, authed, uri, searchQuery.Resolve); err == nil && foundStatus != nil { - foundStatuses = append(foundStatuses, foundStatus) - foundOne = true - l.Debug("got a status by searching by URI") - } - - // 2. check if it's an account - if foundAccount, err := p.searchAccountByURI(ctx, authed, uri, searchQuery.Resolve); err == nil && foundAccount != nil { - foundAccounts = append(foundAccounts, foundAccount) - foundOne = true - l.Debug("got an account by searching by URI") - } - } - if !foundOne { - // we haven't found anything yet so search for text now - l.Debug("nothing found by mention or by URI, will fall back to searching by text now") + if uri, err := url.Parse(query); err == nil { + // 1. check if it's a status + if foundStatus, err := p.searchStatusByURI(ctx, authed, uri, searchQuery.Resolve); err == nil && foundStatus != nil { + foundStatuses = append(foundStatuses, foundStatus) + foundOne = true + l.Debug("got a status by searching by URI") + } + + // 2. check if it's an account + if foundAccount, err := p.searchAccountByURI(ctx, authed, uri, searchQuery.Resolve); err == nil && foundAccount != nil { + foundAccounts = append(foundAccounts, foundAccount) + foundOne = true + l.Debug("got an account by searching by URI") + } + } } /* diff --git a/internal/util/statustools.go b/internal/util/statustools.go index 362c9fd95..030372b50 100644 --- a/internal/util/statustools.go +++ b/internal/util/statustools.go @@ -77,8 +77,3 @@ func ExtractMentionParts(mention string) (username, domain string, err error) { return "", "", fmt.Errorf("couldn't match mention %s", mention) } } - -// IsMention returns true if the passed string looks like @whatever@example.org -func IsMention(mention string) bool { - return regexes.MentionName.MatchString(strings.ToLower(mention)) -}