summaryrefslogtreecommitdiffstats
path: root/modules/indexer
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2019-02-19 23:22:42 +0800
committerLauris BH <lauris@nix.lv>2019-02-19 17:22:42 +0200
commit987a521e2f361f013344b5fbb9b013ea7700f53f (patch)
treea0bc3daea053403d6c110b475446d23c7d3fc110 /modules/indexer
parent830ae614560b0c504c00d693b63d9889bac1a2d8 (diff)
downloadgitea-987a521e2f361f013344b5fbb9b013ea7700f53f.tar.gz
gitea-987a521e2f361f013344b5fbb9b013ea7700f53f.zip
remove unused file (#6121)
Diffstat (limited to 'modules/indexer')
-rw-r--r--modules/indexer/issue.go143
1 files changed, 0 insertions, 143 deletions
diff --git a/modules/indexer/issue.go b/modules/indexer/issue.go
deleted file mode 100644
index 29c78307b6..0000000000
--- a/modules/indexer/issue.go
+++ /dev/null
@@ -1,143 +0,0 @@
-// Copyright 2017 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
-
-package indexer
-
-import (
- "code.gitea.io/gitea/modules/log"
- "code.gitea.io/gitea/modules/setting"
-
- "github.com/blevesearch/bleve"
- "github.com/blevesearch/bleve/analysis/analyzer/custom"
- "github.com/blevesearch/bleve/analysis/token/lowercase"
- "github.com/blevesearch/bleve/analysis/tokenizer/unicode"
- "github.com/ethantkoenig/rupture"
-)
-
-// issueIndexer (thread-safe) index for searching issues
-var issueIndexer bleve.Index
-
-const (
- issueIndexerAnalyzer = "issueIndexer"
- issueIndexerDocType = "issueIndexerDocType"
-
- issueIndexerLatestVersion = 1
-)
-
-// IssueIndexerData data stored in the issue indexer
-type IssueIndexerData struct {
- RepoID int64
- Title string
- Content string
- Comments []string
-}
-
-// Type returns the document type, for bleve's mapping.Classifier interface.
-func (i *IssueIndexerData) Type() string {
- return issueIndexerDocType
-}
-
-// IssueIndexerUpdate an update to the issue indexer
-type IssueIndexerUpdate struct {
- IssueID int64
- Data *IssueIndexerData
-}
-
-// AddToFlushingBatch adds the update to the given flushing batch.
-func (i IssueIndexerUpdate) AddToFlushingBatch(batch rupture.FlushingBatch) error {
- return batch.Index(indexerID(i.IssueID), i.Data)
-}
-
-// InitIssueIndexer initialize issue indexer
-func InitIssueIndexer(populateIndexer func() error) {
- var err error
- issueIndexer, err = openIndexer(setting.Indexer.IssuePath, issueIndexerLatestVersion)
- if err != nil {
- log.Fatal(4, "InitIssueIndexer: %v", err)
- }
- if issueIndexer != nil {
- return
- }
-
- if err = createIssueIndexer(setting.Indexer.IssuePath, issueIndexerLatestVersion); err != nil {
- log.Fatal(4, "InitIssuesIndexer: create index, %v", err)
- }
- if err = populateIndexer(); err != nil {
- log.Fatal(4, "InitIssueIndexer: populate index, %v", err)
- }
-}
-
-// createIssueIndexer create an issue indexer if one does not already exist
-func createIssueIndexer(path string, latestVersion int) error {
- mapping := bleve.NewIndexMapping()
- docMapping := bleve.NewDocumentMapping()
-
- numericFieldMapping := bleve.NewNumericFieldMapping()
- numericFieldMapping.IncludeInAll = false
- docMapping.AddFieldMappingsAt("RepoID", numericFieldMapping)
-
- textFieldMapping := bleve.NewTextFieldMapping()
- textFieldMapping.Store = false
- textFieldMapping.IncludeInAll = false
- docMapping.AddFieldMappingsAt("Title", textFieldMapping)
- docMapping.AddFieldMappingsAt("Content", textFieldMapping)
- docMapping.AddFieldMappingsAt("Comments", textFieldMapping)
-
- if err := addUnicodeNormalizeTokenFilter(mapping); err != nil {
- return err
- } else if err = mapping.AddCustomAnalyzer(issueIndexerAnalyzer, map[string]interface{}{
- "type": custom.Name,
- "char_filters": []string{},
- "tokenizer": unicode.Name,
- "token_filters": []string{unicodeNormalizeName, lowercase.Name},
- }); err != nil {
- return err
- }
-
- mapping.DefaultAnalyzer = issueIndexerAnalyzer
- mapping.AddDocumentMapping(issueIndexerDocType, docMapping)
- mapping.AddDocumentMapping("_all", bleve.NewDocumentDisabledMapping())
-
- var err error
- issueIndexer, err = bleve.New(path, mapping)
- if err != nil {
- return err
- }
-
- return rupture.WriteIndexMetadata(path, &rupture.IndexMetadata{
- Version: latestVersion,
- })
-}
-
-// IssueIndexerBatch batch to add updates to
-func IssueIndexerBatch() rupture.FlushingBatch {
- return rupture.NewFlushingBatch(issueIndexer, maxBatchSize)
-}
-
-// SearchIssuesByKeyword searches for issues by given conditions.
-// Returns the matching issue IDs
-func SearchIssuesByKeyword(repoID int64, keyword string) ([]int64, error) {
- indexerQuery := bleve.NewConjunctionQuery(
- numericEqualityQuery(repoID, "RepoID"),
- bleve.NewDisjunctionQuery(
- newMatchPhraseQuery(keyword, "Title", issueIndexerAnalyzer),
- newMatchPhraseQuery(keyword, "Content", issueIndexerAnalyzer),
- newMatchPhraseQuery(keyword, "Comments", issueIndexerAnalyzer),
- ))
- search := bleve.NewSearchRequestOptions(indexerQuery, 2147483647, 0, false)
-
- result, err := issueIndexer.Search(search)
- if err != nil {
- return nil, err
- }
-
- issueIDs := make([]int64, len(result.Hits))
- for i, hit := range result.Hits {
- issueIDs[i], err = idOfIndexerID(hit.ID)
- if err != nil {
- return nil, err
- }
- }
- return issueIDs, nil
-}