Skip to content

Commit 34399cf

Browse files
sillyguodongwolfogrelunny
authored
Make issue and code search support camel case (#22829)
Fixes #22714 ### Changes: 1. Add a token filter which named "camelCase" between custom unicode token filter and "to_lower" token filter when add custom analyzer. ### Notice: If users want this feature to work, they should delete folder under {giteaPath}/data/indexers and restart application. Then application will create a new IndexMapping. ### Screenshots: ![image](https://user-images.githubusercontent.com/33891828/217715692-c18c41f2-57a1-4727-861c-470935c8e0c8.png) ### Others: I originally attempted to give users the ability to configure the "token_filters" in the "app.ini" file. But I found that if users does not strictly follow a right order to register "token_filters", they won't get the expected results. I think it is difficult to ask users to do this. So I finally give up this idea. --------- Co-authored-by: Jason Song <i@wolfogre.com> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
1 parent 00f695d commit 34399cf

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

modules/indexer/code/bleve.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/blevesearch/bleve/v2"
2828
analyzer_custom "github.com/blevesearch/bleve/v2/analysis/analyzer/custom"
2929
analyzer_keyword "github.com/blevesearch/bleve/v2/analysis/analyzer/keyword"
30+
"github.com/blevesearch/bleve/v2/analysis/token/camelcase"
3031
"github.com/blevesearch/bleve/v2/analysis/token/lowercase"
3132
"github.com/blevesearch/bleve/v2/analysis/token/unicodenorm"
3233
"github.com/blevesearch/bleve/v2/analysis/tokenizer/unicode"
@@ -107,7 +108,7 @@ func (d *RepoIndexerData) Type() string {
107108
const (
108109
repoIndexerAnalyzer = "repoIndexerAnalyzer"
109110
repoIndexerDocType = "repoIndexerDocType"
110-
repoIndexerLatestVersion = 5
111+
repoIndexerLatestVersion = 6
111112
)
112113

113114
// createBleveIndexer create a bleve repo indexer if one does not already exist
@@ -138,7 +139,7 @@ func createBleveIndexer(path string, latestVersion int) (bleve.Index, error) {
138139
"type": analyzer_custom.Name,
139140
"char_filters": []string{},
140141
"tokenizer": unicode.Name,
141-
"token_filters": []string{unicodeNormalizeName, lowercase.Name},
142+
"token_filters": []string{unicodeNormalizeName, camelcase.Name, lowercase.Name},
142143
}); err != nil {
143144
return nil, err
144145
}

modules/indexer/issues/bleve.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515

1616
"github.com/blevesearch/bleve/v2"
1717
"github.com/blevesearch/bleve/v2/analysis/analyzer/custom"
18+
"github.com/blevesearch/bleve/v2/analysis/token/camelcase"
1819
"github.com/blevesearch/bleve/v2/analysis/token/lowercase"
1920
"github.com/blevesearch/bleve/v2/analysis/token/unicodenorm"
2021
"github.com/blevesearch/bleve/v2/analysis/tokenizer/unicode"
@@ -27,7 +28,7 @@ import (
2728
const (
2829
issueIndexerAnalyzer = "issueIndexer"
2930
issueIndexerDocType = "issueIndexerDocType"
30-
issueIndexerLatestVersion = 1
31+
issueIndexerLatestVersion = 2
3132
)
3233

3334
// indexerID a bleve-compatible unique identifier for an integer id
@@ -134,7 +135,7 @@ func createIssueIndexer(path string, latestVersion int) (bleve.Index, error) {
134135
"type": custom.Name,
135136
"char_filters": []string{},
136137
"tokenizer": unicode.Name,
137-
"token_filters": []string{unicodeNormalizeName, lowercase.Name},
138+
"token_filters": []string{unicodeNormalizeName, camelcase.Name, lowercase.Name},
138139
}); err != nil {
139140
return nil, err
140141
}

0 commit comments

Comments
 (0)