summaryrefslogtreecommitdiffstats
path: root/modules/indexer
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2022-01-20 18:46:10 +0100
committerGitHub <noreply@github.com>2022-01-20 18:46:10 +0100
commit54e9ee37a7a301dbe74d46fd3c87712e6120e9bf (patch)
tree1be12fb072625c1b896b9d72f7912b018aad502b /modules/indexer
parent1d98d205f5825f40110e6628b61a97c91ac7f72d (diff)
downloadgitea-54e9ee37a7a301dbe74d46fd3c87712e6120e9bf.tar.gz
gitea-54e9ee37a7a301dbe74d46fd3c87712e6120e9bf.zip
format with gofumpt (#18184)
* gofumpt -w -l . * gofumpt -w -l -extra . * Add linter * manual fix * change make fmt
Diffstat (limited to 'modules/indexer')
-rw-r--r--modules/indexer/code/bleve.go12
-rw-r--r--modules/indexer/code/elastic_search.go10
-rw-r--r--modules/indexer/code/git.go2
-rw-r--r--modules/indexer/code/indexer.go4
-rw-r--r--modules/indexer/code/indexer_test.go78
-rw-r--r--modules/indexer/code/wrapped.go5
-rw-r--r--modules/indexer/issues/bleve.go6
-rw-r--r--modules/indexer/issues/bleve_test.go62
-rw-r--r--modules/indexer/issues/db.go5
-rw-r--r--modules/indexer/issues/elastic_search.go8
-rw-r--r--modules/indexer/issues/indexer_test.go1
-rw-r--r--modules/indexer/stats/db.go3
12 files changed, 89 insertions, 107 deletions
diff --git a/modules/indexer/code/bleve.go b/modules/indexer/code/bleve.go
index 64e974dc18..cfadcfebd8 100644
--- a/modules/indexer/code/bleve.go
+++ b/modules/indexer/code/bleve.go
@@ -38,8 +38,10 @@ import (
"github.com/go-enry/go-enry/v2"
)
-const unicodeNormalizeName = "unicodeNormalize"
-const maxBatchSize = 16
+const (
+ unicodeNormalizeName = "unicodeNormalize"
+ maxBatchSize = 16
+)
// numericEqualityQuery a numeric equality query for the given value and field
func numericEqualityQuery(value int64, field string) *query.NumericRangeQuery {
@@ -158,9 +160,7 @@ func createBleveIndexer(path string, latestVersion int) (bleve.Index, error) {
return indexer, nil
}
-var (
- _ Indexer = &BleveIndexer{}
-)
+var _ Indexer = &BleveIndexer{}
// BleveIndexer represents a bleve indexer implementation
type BleveIndexer struct {
@@ -337,7 +337,7 @@ func (b *BleveIndexer) Search(repoIDs []int64, language, keyword string, page, p
}
if len(repoIDs) > 0 {
- var repoQueries = make([]query.Query, 0, len(repoIDs))
+ repoQueries := make([]query.Query, 0, len(repoIDs))
for _, repoID := range repoIDs {
repoQueries = append(repoQueries, numericEqualityQuery(repoID, "RepoID"))
}
diff --git a/modules/indexer/code/elastic_search.go b/modules/indexer/code/elastic_search.go
index eb57d4d68a..9bd2fa301e 100644
--- a/modules/indexer/code/elastic_search.go
+++ b/modules/indexer/code/elastic_search.go
@@ -35,9 +35,7 @@ const (
esMultiMatchTypePhrasePrefix = "phrase_prefix"
)
-var (
- _ Indexer = &ElasticSearchIndexer{}
-)
+var _ Indexer = &ElasticSearchIndexer{}
// ElasticSearchIndexer implements Indexer interface
type ElasticSearchIndexer struct {
@@ -131,7 +129,7 @@ func (b *ElasticSearchIndexer) init() (bool, error) {
return false, err
}
if !exists {
- var mapping = defaultMapping
+ mapping := defaultMapping
createIndex, err := b.client.CreateIndex(b.realIndexerName()).BodyString(mapping).Do(ctx)
if err != nil {
@@ -327,7 +325,7 @@ func convertResult(searchResult *elastic.SearchResult, kw string, pageSize int)
}
repoID, fileName := parseIndexerID(hit.Id)
- var res = make(map[string]interface{})
+ res := make(map[string]interface{})
if err := json.Unmarshal(hit.Source, &res); err != nil {
return 0, nil, nil, err
}
@@ -378,7 +376,7 @@ func (b *ElasticSearchIndexer) Search(repoIDs []int64, language, keyword string,
query := elastic.NewBoolQuery()
query = query.Must(kwQuery)
if len(repoIDs) > 0 {
- var repoStrs = make([]interface{}, 0, len(repoIDs))
+ repoStrs := make([]interface{}, 0, len(repoIDs))
for _, repoID := range repoIDs {
repoStrs = append(repoStrs, repoID)
}
diff --git a/modules/indexer/code/git.go b/modules/indexer/code/git.go
index 247354054c..ae73f5690d 100644
--- a/modules/indexer/code/git.go
+++ b/modules/indexer/code/git.go
@@ -73,7 +73,7 @@ func parseGitLsTreeOutput(stdout []byte) ([]fileUpdate, error) {
if err != nil {
return nil, err
}
- var idxCount = 0
+ idxCount := 0
updates := make([]fileUpdate, len(entries))
for _, entry := range entries {
if isIndexable(entry) {
diff --git a/modules/indexer/code/indexer.go b/modules/indexer/code/indexer.go
index a17484cae5..4c7a1d4f17 100644
--- a/modules/indexer/code/indexer.go
+++ b/modules/indexer/code/indexer.go
@@ -78,9 +78,7 @@ type IndexerData struct {
RepoID int64
}
-var (
- indexerQueue queue.UniqueQueue
-)
+var indexerQueue queue.UniqueQueue
func index(ctx context.Context, indexer Indexer, repoID int64) error {
repo, err := repo_model.GetRepositoryByID(repoID)
diff --git a/modules/indexer/code/indexer_test.go b/modules/indexer/code/indexer_test.go
index 71d58c08c5..0f9915c84b 100644
--- a/modules/indexer/code/indexer_test.go
+++ b/modules/indexer/code/indexer_test.go
@@ -25,45 +25,43 @@ func testIndexer(name string, t *testing.T, indexer Indexer) {
var repoID int64 = 1
err := index(git.DefaultContext, indexer, repoID)
assert.NoError(t, err)
- var (
- keywords = []struct {
- RepoIDs []int64
- Keyword string
- IDs []int64
- Langs int
- }{
- {
- RepoIDs: nil,
- Keyword: "Description",
- IDs: []int64{repoID},
- Langs: 1,
- },
- {
- RepoIDs: []int64{2},
- Keyword: "Description",
- IDs: []int64{},
- Langs: 0,
- },
- {
- RepoIDs: nil,
- Keyword: "repo1",
- IDs: []int64{repoID},
- Langs: 1,
- },
- {
- RepoIDs: []int64{2},
- Keyword: "repo1",
- IDs: []int64{},
- Langs: 0,
- },
- {
- RepoIDs: nil,
- Keyword: "non-exist",
- IDs: []int64{},
- Langs: 0,
- },
- }
- )
+ keywords := []struct {
+ RepoIDs []int64
+ Keyword string
+ IDs []int64
+ Langs int
+ }{
+ {
+ RepoIDs: nil,
+ Keyword: "Description",
+ IDs: []int64{repoID},
+ Langs: 1,
+ },
+ {
+ RepoIDs: []int64{2},
+ Keyword: "Description",
+ IDs: []int64{},
+ Langs: 0,
+ },
+ {
+ RepoIDs: nil,
+ Keyword: "repo1",
+ IDs: []int64{repoID},
+ Langs: 1,
+ },
+ {
+ RepoIDs: []int64{2},
+ Keyword: "repo1",
+ IDs: []int64{},
+ Langs: 0,
+ },
+ {
+ RepoIDs: nil,
+ Keyword: "non-exist",
+ IDs: []int64{},
+ Langs: 0,
+ },
+ }
for _, kw := range keywords {
t.Run(kw.Keyword, func(t *testing.T) {
@@ -72,7 +70,7 @@ func testIndexer(name string, t *testing.T, indexer Indexer) {
assert.EqualValues(t, len(kw.IDs), total)
assert.Len(t, langs, kw.Langs)
- var ids = make([]int64, 0, len(res))
+ ids := make([]int64, 0, len(res))
for _, hit := range res {
ids = append(ids, hit.RepoID)
assert.EqualValues(t, "# repo1\n\nDescription for repo1", hit.Content)
diff --git a/modules/indexer/code/wrapped.go b/modules/indexer/code/wrapped.go
index e7b5b89eef..56baadd6fc 100644
--- a/modules/indexer/code/wrapped.go
+++ b/modules/indexer/code/wrapped.go
@@ -12,9 +12,7 @@ import (
repo_model "code.gitea.io/gitea/models/repo"
)
-var (
- indexer = newWrappedIndexer()
-)
+var indexer = newWrappedIndexer()
// ErrWrappedIndexerClosed is the error returned if the indexer was closed before it was ready
var ErrWrappedIndexerClosed = fmt.Errorf("Indexer closed before ready")
@@ -80,7 +78,6 @@ func (w *wrappedIndexer) Search(repoIDs []int64, language, keyword string, page,
return 0, nil, nil, err
}
return indexer.Search(repoIDs, language, keyword, page, pageSize, isMatch)
-
}
func (w *wrappedIndexer) Close() {
diff --git a/modules/indexer/issues/bleve.go b/modules/indexer/issues/bleve.go
index db12874e84..d986a0e55e 100644
--- a/modules/indexer/issues/bleve.go
+++ b/modules/indexer/issues/bleve.go
@@ -156,9 +156,7 @@ func createIssueIndexer(path string, latestVersion int) (bleve.Index, error) {
return index, nil
}
-var (
- _ Indexer = &BleveIndexer{}
-)
+var _ Indexer = &BleveIndexer{}
// BleveIndexer implements Indexer interface
type BleveIndexer struct {
@@ -256,7 +254,7 @@ func (b *BleveIndexer) Search(keyword string, repoIDs []int64, limit, start int)
return nil, err
}
- var ret = SearchResult{
+ ret := SearchResult{
Hits: make([]Match, 0, len(result.Hits)),
}
for _, hit := range result.Hits {
diff --git a/modules/indexer/issues/bleve_test.go b/modules/indexer/issues/bleve_test.go
index 036b318d85..df036fb573 100644
--- a/modules/indexer/issues/bleve_test.go
+++ b/modules/indexer/issues/bleve_test.go
@@ -53,43 +53,41 @@ func TestBleveIndexAndSearch(t *testing.T) {
})
assert.NoError(t, err)
- var (
- keywords = []struct {
- Keyword string
- IDs []int64
- }{
- {
- Keyword: "search",
- IDs: []int64{1},
- },
- {
- Keyword: "test1",
- IDs: []int64{1},
- },
- {
- Keyword: "test2",
- IDs: []int64{1},
- },
- {
- Keyword: "support",
- IDs: []int64{1, 2},
- },
- {
- Keyword: "chinese",
- IDs: []int64{1, 2},
- },
- {
- Keyword: "help",
- IDs: []int64{},
- },
- }
- )
+ keywords := []struct {
+ Keyword string
+ IDs []int64
+ }{
+ {
+ Keyword: "search",
+ IDs: []int64{1},
+ },
+ {
+ Keyword: "test1",
+ IDs: []int64{1},
+ },
+ {
+ Keyword: "test2",
+ IDs: []int64{1},
+ },
+ {
+ Keyword: "support",
+ IDs: []int64{1, 2},
+ },
+ {
+ Keyword: "chinese",
+ IDs: []int64{1, 2},
+ },
+ {
+ Keyword: "help",
+ IDs: []int64{},
+ },
+ }
for _, kw := range keywords {
res, err := indexer.Search(kw.Keyword, []int64{2}, 10, 0)
assert.NoError(t, err)
- var ids = make([]int64, 0, len(res.Hits))
+ ids := make([]int64, 0, len(res.Hits))
for _, hit := range res.Hits {
ids = append(ids, hit.ID)
}
diff --git a/modules/indexer/issues/db.go b/modules/indexer/issues/db.go
index d0cca4fd18..f02cbddce8 100644
--- a/modules/indexer/issues/db.go
+++ b/modules/indexer/issues/db.go
@@ -7,8 +7,7 @@ package issues
import "code.gitea.io/gitea/models"
// DBIndexer implements Indexer interface to use database's like search
-type DBIndexer struct {
-}
+type DBIndexer struct{}
// Init dummy function
func (db *DBIndexer) Init() (bool, error) {
@@ -35,7 +34,7 @@ func (db *DBIndexer) Search(kw string, repoIDs []int64, limit, start int) (*Sear
if err != nil {
return nil, err
}
- var result = SearchResult{
+ result := SearchResult{
Total: total,
Hits: make([]Match, 0, limit),
}
diff --git a/modules/indexer/issues/elastic_search.go b/modules/indexer/issues/elastic_search.go
index 3af64ed30e..187b69b749 100644
--- a/modules/indexer/issues/elastic_search.go
+++ b/modules/indexer/issues/elastic_search.go
@@ -16,9 +16,7 @@ import (
"github.com/olivere/elastic/v7"
)
-var (
- _ Indexer = &ElasticSearchIndexer{}
-)
+var _ Indexer = &ElasticSearchIndexer{}
// ElasticSearchIndexer implements Indexer interface
type ElasticSearchIndexer struct {
@@ -102,7 +100,7 @@ func (b *ElasticSearchIndexer) Init() (bool, error) {
}
if !exists {
- var mapping = defaultMapping
+ mapping := defaultMapping
createIndex, err := b.client.CreateIndex(b.indexerName).BodyString(mapping).Do(ctx)
if err != nil {
@@ -195,7 +193,7 @@ func (b *ElasticSearchIndexer) Search(keyword string, repoIDs []int64, limit, st
query := elastic.NewBoolQuery()
query = query.Must(kwQuery)
if len(repoIDs) > 0 {
- var repoStrs = make([]interface{}, 0, len(repoIDs))
+ repoStrs := make([]interface{}, 0, len(repoIDs))
for _, repoID := range repoIDs {
repoStrs = append(repoStrs, repoID)
}
diff --git a/modules/indexer/issues/indexer_test.go b/modules/indexer/issues/indexer_test.go
index ba35e37fd8..ee6ebcdd18 100644
--- a/modules/indexer/issues/indexer_test.go
+++ b/modules/indexer/issues/indexer_test.go
@@ -71,7 +71,6 @@ func TestBleveSearchIssues(t *testing.T) {
ids, err = SearchIssuesByKeyword([]int64{1}, "good")
assert.NoError(t, err)
assert.EqualValues(t, []int64{1}, ids)
-
}
func TestDBSearchIssues(t *testing.T) {
diff --git a/modules/indexer/stats/db.go b/modules/indexer/stats/db.go
index 9d2942a266..e425b95d20 100644
--- a/modules/indexer/stats/db.go
+++ b/modules/indexer/stats/db.go
@@ -15,8 +15,7 @@ import (
)
// DBIndexer implements Indexer interface to use database's like search
-type DBIndexer struct {
-}
+type DBIndexer struct{}
// Index repository status function
func (db *DBIndexer) Index(id int64) error {