Monorepo for Tangled tangled.org

appview: add basic issue indexer (wip) #494

merged opened by boltless.me targeting master from boltless.me/core: feat/search
  • Heavily inspired by gitea
  • add GetAllIssues which only receives a paginator and gathers all issues ignoring repoAt field

Signed-off-by: Seongmin Lee boltlessengineer@proton.me

Labels

None yet.

assignee

None yet.

Participants 2
AT URI
at://did:plc:xasnlahkri4ewmbuzly2rlc5/sh.tangled.repo.pull/3lwecnvoz4z22
+31 -24
Interdiff #7 #8
.gitignore

This file has not been changed.

appview/indexer/base36/base36.go

This file has not been changed.

appview/indexer/bleve/batch.go

This file has not been changed.

appview/indexer/indexer.go

This file has not been changed.

+7 -24
appview/indexer/issues/indexer.go
··· 4 4 import ( 5 5 "context" 6 6 "errors" 7 + "log" 7 8 "os" 8 9 9 10 "github.com/blevesearch/bleve/v2" ··· 33 34 l := tlog.FromContext(ctx) 34 35 existed, err := ix.intialize(ctx) 35 36 if err != nil { 36 - l.Error("failed to initialize issue indexer", "err", err) 37 + log.Fatalln("failed to initialize issue indexer", err) 37 38 } 38 39 if !existed { 39 40 l.Debug("Populating the issue indexer") 40 41 err := PopulateIndexer(ctx, ix, e) 41 42 if err != nil { 42 - l.Error("failed to populate issue indexer", "err", err) 43 + log.Fatalln("failed to populate issue indexer", err) 43 44 } 44 45 } 45 46 l.Info("Initialized the issue indexer") ··· 150 151 151 152 if opts.Keyword != "" { 152 153 queries = append(queries, bleve.NewDisjunctionQuery( 153 - matchAndQuery(opts.Keyword, "title"), 154 - matchAndQuery(opts.Keyword, "body"), 154 + bleveutil.MatchAndQuery("title", opts.Keyword), 155 + bleveutil.MatchAndQuery("body", opts.Keyword), 155 156 )) 156 157 } 157 - queries = append(queries, keywordFieldQuery(opts.RepoAt, "repo_at")) 158 - queries = append(queries, boolFieldQuery(opts.IsOpen, "is_open")) 158 + queries = append(queries, bleveutil.KeywordFieldQuery("repo_at", opts.RepoAt)) 159 + queries = append(queries, bleveutil.BoolFieldQuery("is_open", opts.IsOpen)) 159 160 // TODO: append more queries 160 161 161 162 var indexerQuery query.Query = bleve.NewConjunctionQuery(queries...) ··· 176 177 ret.Hits[i] = id 177 178 } 178 179 return ret, nil 179 - } 180 - 181 - func matchAndQuery(keyword, field string) query.Query { 182 - q := bleve.NewMatchQuery(keyword) 183 - q.FieldVal = field 184 - return q 185 - } 186 - 187 - func boolFieldQuery(val bool, field string) query.Query { 188 - q := bleve.NewBoolFieldQuery(val) 189 - q.FieldVal = field 190 - return q 191 - } 192 - 193 - func keywordFieldQuery(keyword, field string) query.Query { 194 - q := bleve.NewTermQuery(keyword) 195 - q.FieldVal = field 196 - return q 197 180 }
appview/indexer/notifier.go

This file has not been changed.

appview/issues/issues.go

This file has not been changed.

appview/models/search.go

This file has not been changed.

appview/pages/pages.go

This file has not been changed.

appview/pagination/page.go

This file has not been changed.

appview/state/router.go

This file has not been changed.

appview/state/state.go

This file has not been changed.

+24
appview/indexer/bleve/query.go
··· 1 + package bleveutil 2 + 3 + import ( 4 + "github.com/blevesearch/bleve/v2" 5 + "github.com/blevesearch/bleve/v2/search/query" 6 + ) 7 + 8 + func MatchAndQuery(field, keyword string) query.Query { 9 + q := bleve.NewMatchQuery(keyword) 10 + q.FieldVal = field 11 + return q 12 + } 13 + 14 + func BoolFieldQuery(field string, val bool) query.Query { 15 + q := bleve.NewBoolFieldQuery(val) 16 + q.FieldVal = field 17 + return q 18 + } 19 + 20 + func KeywordFieldQuery(field, keyword string) query.Query { 21 + q := bleve.NewTermQuery(keyword) 22 + q.FieldVal = field 23 + return q 24 + }

History

15 rounds 2 comments
sign up or login to add to the discussion
1 commit
expand
appview: add basic issue indexer
expand 0 comments
pull request successfully merged
1 commit
expand
appview: add basic issue indexer
expand 0 comments
1 commit
expand
appview: add basic issue indexer
expand 0 comments
1 commit
expand
appview: add basic issue indexer
expand 0 comments
1 commit
expand
appview: add basic issue indexer
expand 0 comments
1 commit
expand
appview: add basic issue indexer
expand 0 comments
1 commit
expand
appview: add basic issue indexer
expand 0 comments
1 commit
expand
appview: add basic issue indexer
expand 0 comments
1 commit
expand
appview: add basic issue indexer
expand 1 comment

this changeset largely lgtm!

1 commit
expand
appview: add basic issue indexer
expand 0 comments
1 commit
expand
appview: add basic issue indexer
expand 0 comments
1 commit
expand
appview: add basic issue indexer
expand 1 comment
  • this is an N+1 query, because we first get all issues and then make one query for each issue. understandably this only needs to happen when populating the indices but we could improve this by just making one query
  • we can use a pagination free API for getting issues with comments while populating indexer
  • more of a note to self: search index should also handle issue deletions
1 commit
expand
appview: add basic issue indexer
expand 0 comments
1 commit
expand
appview: add basic issue indexer
expand 0 comments
1 commit
expand
appview: add basic issue indexer (wip)
expand 0 comments