Monorepo for Tangled tangled.org

wip: add indexer mappings #495

merged opened by boltless.me targeting master from boltless.me/core: feat/search
Labels

None yet.

assignee

None yet.

Participants 2
AT URI
at://did:plc:xasnlahkri4ewmbuzly2rlc5/sh.tangled.repo.pull/3lwecnvoz5322
+34 -4
Interdiff #2 #3
appview/db/issues.go

This file has not been changed.

+34 -4
appview/indexer/issues/indexer.go
··· 1 package issues_indexer 2 3 import ( ··· 7 "os" 8 9 "github.com/blevesearch/bleve/v2" 10 "github.com/blevesearch/bleve/v2/index/upsidedown" 11 "github.com/blevesearch/bleve/v2/mapping" 12 "github.com/blevesearch/bleve/v2/search/query" ··· 18 ) 19 20 const ( 21 - issueIndexerDocType = "issueIndexerDocType" 22 ) 23 24 type Indexer struct { ··· 72 docMapping.AddFieldMappingsAt("repo_at", keywordFieldMapping) 73 docMapping.AddFieldMappingsAt("is_open", boolFieldMapping) 74 75 mapping.AddDocumentMapping(issueIndexerDocType, docMapping) 76 mapping.AddDocumentMapping("_all", bleve.NewDocumentDisabledMapping()) 77 mapping.DefaultMapping = bleve.NewDocumentDisabledMapping() ··· 200 201 if opts.Keyword != "" { 202 queries = append(queries, bleve.NewDisjunctionQuery( 203 - matchAndQuery(opts.Keyword, "title"), 204 - matchAndQuery(opts.Keyword, "body"), 205 )) 206 } 207 queries = append(queries, keywordFieldQuery(opts.RepoAt, "repo_at")) ··· 228 return ret, nil 229 } 230 231 - func matchAndQuery(keyword, field string) query.Query { 232 q := bleve.NewMatchQuery(keyword) 233 q.FieldVal = field 234 return q 235 } 236
··· 1 + // heavily inspired by gitea's model (basically copy-pasted) 2 package issues_indexer 3 4 import ( ··· 8 "os" 9 10 "github.com/blevesearch/bleve/v2" 11 + "github.com/blevesearch/bleve/v2/analysis/analyzer/custom" 12 + "github.com/blevesearch/bleve/v2/analysis/token/camelcase" 13 + "github.com/blevesearch/bleve/v2/analysis/token/lowercase" 14 + "github.com/blevesearch/bleve/v2/analysis/token/unicodenorm" 15 + "github.com/blevesearch/bleve/v2/analysis/tokenizer/unicode" 16 "github.com/blevesearch/bleve/v2/index/upsidedown" 17 "github.com/blevesearch/bleve/v2/mapping" 18 "github.com/blevesearch/bleve/v2/search/query" ··· 24 ) 25 26 const ( 27 + issueIndexerAnalyzer = "issueIndexer" 28 + issueIndexerDocType = "issueIndexerDocType" 29 + 30 + unicodeNormalizeName = "uicodeNormalize" 31 ) 32 33 type Indexer struct { ··· 81 docMapping.AddFieldMappingsAt("repo_at", keywordFieldMapping) 82 docMapping.AddFieldMappingsAt("is_open", boolFieldMapping) 83 84 + err := mapping.AddCustomTokenFilter(unicodeNormalizeName, map[string]any{ 85 + "type": unicodenorm.Name, 86 + "form": unicodenorm.NFC, 87 + }) 88 + if err != nil { 89 + return nil, err 90 + } 91 + 92 + err = mapping.AddCustomAnalyzer(issueIndexerAnalyzer, map[string]any{ 93 + "type": custom.Name, 94 + "char_filters": []string{}, 95 + "tokenizer": unicode.Name, 96 + "token_filters": []string{unicodeNormalizeName, camelcase.Name, lowercase.Name}, 97 + }) 98 + if err != nil { 99 + return nil, err 100 + } 101 + 102 + mapping.DefaultAnalyzer = issueIndexerAnalyzer 103 mapping.AddDocumentMapping(issueIndexerDocType, docMapping) 104 mapping.AddDocumentMapping("_all", bleve.NewDocumentDisabledMapping()) 105 mapping.DefaultMapping = bleve.NewDocumentDisabledMapping() ··· 228 229 if opts.Keyword != "" { 230 queries = append(queries, bleve.NewDisjunctionQuery( 231 + matchAndQuery(opts.Keyword, "title", issueIndexerAnalyzer, 0), 232 + matchAndQuery(opts.Keyword, "body", issueIndexerAnalyzer, 0), 233 )) 234 } 235 queries = append(queries, keywordFieldQuery(opts.RepoAt, "repo_at")) ··· 256 return ret, nil 257 } 258 259 + func matchAndQuery(keyword, field, analyzer string, fuzziness int) query.Query { 260 q := bleve.NewMatchQuery(keyword) 261 q.FieldVal = field 262 + q.Analyzer = analyzer 263 + q.Fuzziness = fuzziness 264 return q 265 } 266

History

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