code.gitea.io/gitea@v1.22.3/modules/indexer/code/internal/indexer.go (about)

     1  // Copyright 2023 The Gitea Authors. All rights reserved.
     2  // SPDX-License-Identifier: MIT
     3  
     4  package internal
     5  
     6  import (
     7  	"context"
     8  	"fmt"
     9  
    10  	"code.gitea.io/gitea/models/db"
    11  	repo_model "code.gitea.io/gitea/models/repo"
    12  	"code.gitea.io/gitea/modules/indexer/internal"
    13  )
    14  
    15  // Indexer defines an interface to index and search code contents
    16  type Indexer interface {
    17  	internal.Indexer
    18  	Index(ctx context.Context, repo *repo_model.Repository, sha string, changes *RepoChanges) error
    19  	Delete(ctx context.Context, repoID int64) error
    20  	Search(ctx context.Context, opts *SearchOptions) (int64, []*SearchResult, []*SearchResultLanguages, error)
    21  }
    22  
    23  type SearchOptions struct {
    24  	RepoIDs  []int64
    25  	Keyword  string
    26  	Language string
    27  
    28  	IsKeywordFuzzy bool
    29  
    30  	db.Paginator
    31  }
    32  
    33  // NewDummyIndexer returns a dummy indexer
    34  func NewDummyIndexer() Indexer {
    35  	return &dummyIndexer{
    36  		Indexer: internal.NewDummyIndexer(),
    37  	}
    38  }
    39  
    40  type dummyIndexer struct {
    41  	internal.Indexer
    42  }
    43  
    44  func (d *dummyIndexer) Index(ctx context.Context, repo *repo_model.Repository, sha string, changes *RepoChanges) error {
    45  	return fmt.Errorf("indexer is not ready")
    46  }
    47  
    48  func (d *dummyIndexer) Delete(ctx context.Context, repoID int64) error {
    49  	return fmt.Errorf("indexer is not ready")
    50  }
    51  
    52  func (d *dummyIndexer) Search(ctx context.Context, opts *SearchOptions) (int64, []*SearchResult, []*SearchResultLanguages, error) {
    53  	return 0, nil, nil, fmt.Errorf("indexer is not ready")
    54  }