From 98169d5ad193fe776c29cc40dcd7103bb13e9b7d Mon Sep 17 00:00:00 2001 From: Amine Hilaly Date: Fri, 5 Apr 2019 15:29:14 +0200 Subject: Support query with identity ID and truncated ID --- cache/filter.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cache/filter.go b/cache/filter.go index b26e7ae1..ca70bb2a 100644 --- a/cache/filter.go +++ b/cache/filter.go @@ -33,7 +33,9 @@ func AuthorFilter(query string) Filter { panic("missing identity in the cache") } - return strings.Contains(strings.ToLower(author.Name), query) || + return query == author.Id || + query == author.HumanId() || + strings.Contains(strings.ToLower(author.Name), query) || strings.Contains(strings.ToLower(author.Login), query) } @@ -67,6 +69,7 @@ func ActorFilter(query string) Filter { } if query == identityExcerpt.Id || + query == identityExcerpt.HumanId() || strings.Contains(strings.ToLower(identityExcerpt.Name), query) || query == strings.ToLower(identityExcerpt.Login) { return true @@ -88,6 +91,7 @@ func ParticipantFilter(query string) Filter { } if query == identityExcerpt.Id || + query == identityExcerpt.HumanId() || strings.Contains(strings.ToLower(identityExcerpt.Name), query) || query == strings.ToLower(identityExcerpt.Login) { return true -- cgit From 1d00ded250102c23c0a106e14d88875d342f7880 Mon Sep 17 00:00:00 2001 From: Amine Hilaly Date: Fri, 5 Apr 2019 16:28:41 +0200 Subject: implement identityExcerpt match method and integrate it into filters Update docs --- cache/filter.go | 15 +++------------ cache/identity_excerpt.go | 8 ++++++++ doc/queries.md | 1 + 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/cache/filter.go b/cache/filter.go index ca70bb2a..27e92cf3 100644 --- a/cache/filter.go +++ b/cache/filter.go @@ -33,10 +33,7 @@ func AuthorFilter(query string) Filter { panic("missing identity in the cache") } - return query == author.Id || - query == author.HumanId() || - strings.Contains(strings.ToLower(author.Name), query) || - strings.Contains(strings.ToLower(author.Login), query) + return author.Match(query) } // Legacy identity support @@ -68,10 +65,7 @@ func ActorFilter(query string) Filter { panic("missing identity in the cache") } - if query == identityExcerpt.Id || - query == identityExcerpt.HumanId() || - strings.Contains(strings.ToLower(identityExcerpt.Name), query) || - query == strings.ToLower(identityExcerpt.Login) { + if identityExcerpt.Match(query) { return true } } @@ -90,10 +84,7 @@ func ParticipantFilter(query string) Filter { panic("missing identity in the cache") } - if query == identityExcerpt.Id || - query == identityExcerpt.HumanId() || - strings.Contains(strings.ToLower(identityExcerpt.Name), query) || - query == strings.ToLower(identityExcerpt.Login) { + if identityExcerpt.Match(query) { return true } } diff --git a/cache/identity_excerpt.go b/cache/identity_excerpt.go index 2a13bc60..3ac13903 100644 --- a/cache/identity_excerpt.go +++ b/cache/identity_excerpt.go @@ -3,6 +3,7 @@ package cache import ( "encoding/gob" "fmt" + "strings" "github.com/MichaelMure/git-bug/identity" ) @@ -51,6 +52,13 @@ func (i *IdentityExcerpt) DisplayName() string { panic("invalid person data") } +// Match matches a query with the identity name, login and ID prefixes +func (i *IdentityExcerpt) Match(query string) bool { + return strings.HasPrefix(i.Id, query) || + strings.Contains(strings.ToLower(i.Name), query) || + strings.Contains(strings.ToLower(i.Login), query) +} + /* * Sorting */ diff --git a/doc/queries.md b/doc/queries.md index b93941d1..eb510185 100644 --- a/doc/queries.md +++ b/doc/queries.md @@ -11,6 +11,7 @@ A few tips: - queries are case insensitive. - you can combine as many qualifiers as you want. - you can use double quotes for multi-word search terms. For example, `author:"René Descartes"` searches for bugs opened by René Descartes, whereas `author:René Descartes` will throw an error since full-text search is not yet supported. +- instead of a complete ID, you can use any prefix length. For example `participant=9ed1a`. ## Filtering -- cgit