diff options
Diffstat (limited to 'cache')
-rw-r--r-- | cache/filter.go | 18 | ||||
-rw-r--r-- | cache/repo_cache_bug.go | 21 | ||||
-rw-r--r-- | cache/repo_cache_test.go | 20 |
3 files changed, 56 insertions, 3 deletions
diff --git a/cache/filter.go b/cache/filter.go index 2ac56ab5..c167fe71 100644 --- a/cache/filter.go +++ b/cache/filter.go @@ -38,6 +38,16 @@ func AuthorFilter(query string) Filter { } } +// MetadataFilter return a Filter that match a bug metadata at creation time +func MetadataFilter(pair query.StringPair) Filter { + return func(excerpt *BugExcerpt, resolver resolver) bool { + if value, ok := excerpt.CreateMetadata[pair.Key]; ok { + return value == pair.Value + } + return false + } +} + // LabelFilter return a Filter that match a label func LabelFilter(label string) Filter { return func(excerpt *BugExcerpt, resolver resolver) bool { @@ -109,6 +119,7 @@ func NoLabelFilter() Filter { type Matcher struct { Status []Filter Author []Filter + Metadata []Filter Actor []Filter Participant []Filter Label []Filter @@ -127,6 +138,9 @@ func compileMatcher(filters query.Filters) *Matcher { for _, value := range filters.Author { result.Author = append(result.Author, AuthorFilter(value)) } + for _, value := range filters.Metadata { + result.Metadata = append(result.Metadata, MetadataFilter(value)) + } for _, value := range filters.Actor { result.Actor = append(result.Actor, ActorFilter(value)) } @@ -153,6 +167,10 @@ func (f *Matcher) Match(excerpt *BugExcerpt, resolver resolver) bool { return false } + if match := f.orMatch(f.Metadata, excerpt, resolver); !match { + return false + } + if match := f.orMatch(f.Participant, excerpt, resolver); !match { return false } diff --git a/cache/repo_cache_bug.go b/cache/repo_cache_bug.go index c05f30cf..c019da68 100644 --- a/cache/repo_cache_bug.go +++ b/cache/repo_cache_bug.go @@ -8,12 +8,14 @@ import ( "sort" "strings" "time" + "unicode/utf8" + + "github.com/blevesearch/bleve" "github.com/MichaelMure/git-bug/bug" "github.com/MichaelMure/git-bug/entity" "github.com/MichaelMure/git-bug/query" "github.com/MichaelMure/git-bug/repository" - "github.com/blevesearch/bleve" ) const bugCacheFile = "bug-cache" @@ -523,11 +525,24 @@ func (c *RepoCache) addBugToSearchIndex(snap *bug.Snapshot) error { Text []string }{} + // See https://github.com/blevesearch/bleve/issues/1576 + var sb strings.Builder + normalize := func(text string) string { + sb.Reset() + for _, field := range strings.Fields(text) { + if utf8.RuneCountInString(field) < 100 { + sb.WriteString(field) + sb.WriteRune(' ') + } + } + return sb.String() + } + for _, comment := range snap.Comments { - searchableBug.Text = append(searchableBug.Text, comment.Message) + searchableBug.Text = append(searchableBug.Text, normalize(comment.Message)) } - searchableBug.Text = append(searchableBug.Text, snap.Title) + searchableBug.Text = append(searchableBug.Text, normalize(snap.Title)) index, err := c.repo.GetBleveIndex("bug") if err != nil { diff --git a/cache/repo_cache_test.go b/cache/repo_cache_test.go index 35dc4ffd..fab8fff0 100644 --- a/cache/repo_cache_test.go +++ b/cache/repo_cache_test.go @@ -1,7 +1,9 @@ package cache import ( + "strings" "testing" + "time" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -278,3 +280,21 @@ func checkBugPresence(t *testing.T, cache *RepoCache, bug *BugCache, presence bo require.Equal(t, bug, b) } } + +func TestLongDescription(t *testing.T) { + // See https://github.com/MichaelMure/git-bug/issues/606 + + text := strings.Repeat("x", 65536) + + repo := repository.CreateGoGitTestRepo(false) + defer repository.CleanupTestRepos(repo) + + backend, err := NewRepoCache(repo) + require.NoError(t, err) + + i, err := backend.NewIdentity("René Descartes", "rene@descartes.fr") + require.NoError(t, err) + + _, _, err = backend.NewBugRaw(i, time.Now().Unix(), text, text, nil, nil) + require.NoError(t, err) +} |