94 lines
1.8 KiB
Go
94 lines
1.8 KiB
Go
|
package ports
|
||
|
|
||
|
import (
|
||
|
"bytes"
|
||
|
"context"
|
||
|
"encoding"
|
||
|
"encoding/base64"
|
||
|
"fmt"
|
||
|
|
||
|
"code.icb4dc0.de/prskr/searcherside/core/dto"
|
||
|
)
|
||
|
|
||
|
type IndexType string
|
||
|
|
||
|
func (i IndexType) String() string {
|
||
|
return string(i)
|
||
|
}
|
||
|
|
||
|
const (
|
||
|
IndexTypeBleve IndexType = "bleve"
|
||
|
)
|
||
|
|
||
|
var (
|
||
|
_ encoding.TextMarshaler = (*IndexKey)(nil)
|
||
|
_ encoding.TextUnmarshaler = (*IndexKey)(nil)
|
||
|
)
|
||
|
|
||
|
type IndexKey struct {
|
||
|
Module string
|
||
|
Instance string
|
||
|
}
|
||
|
|
||
|
func (i *IndexKey) MarshalText() (text []byte, err error) {
|
||
|
return []byte(base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%s:%s", i.Module, i.Instance)))), nil
|
||
|
}
|
||
|
|
||
|
func (i *IndexKey) UnmarshalText(text []byte) error {
|
||
|
out := make([]byte, base64.StdEncoding.DecodedLen(len(text)))
|
||
|
if n, err := base64.StdEncoding.Decode(out, text); err != nil {
|
||
|
return err
|
||
|
} else {
|
||
|
split := bytes.Split(out[:n], []byte(":"))
|
||
|
if len(split) != 2 {
|
||
|
return fmt.Errorf("expected to split into module and instance but got %d", len(split))
|
||
|
}
|
||
|
|
||
|
i.Module = string(split[0])
|
||
|
i.Instance = string(split[1])
|
||
|
}
|
||
|
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
type IngestIndexRequest struct {
|
||
|
Module string
|
||
|
Instance string
|
||
|
Hash string
|
||
|
FilePath string
|
||
|
}
|
||
|
|
||
|
type IngestIndexResult struct {
|
||
|
Type IndexType
|
||
|
Path string
|
||
|
}
|
||
|
|
||
|
type IndexSearchRequest struct {
|
||
|
ExactSearch bool
|
||
|
MaxHits int
|
||
|
Query string
|
||
|
}
|
||
|
|
||
|
type ArchiveIndexRequest struct {
|
||
|
Path string
|
||
|
Hash string
|
||
|
Type IndexType
|
||
|
}
|
||
|
|
||
|
type IndexCurator interface {
|
||
|
Ingest(ctx context.Context, request IngestIndexRequest) error
|
||
|
Searcher(key IndexKey) (Searcher, error)
|
||
|
}
|
||
|
|
||
|
type Indexer interface {
|
||
|
IngestIndex(ctx context.Context, request IngestIndexRequest) (IngestIndexResult, error)
|
||
|
}
|
||
|
|
||
|
type Searcher interface {
|
||
|
Search(ctx context.Context, req IndexSearchRequest) (dto.SearchResponse, error)
|
||
|
}
|
||
|
|
||
|
type Archiver interface {
|
||
|
ArchiveIndex(request ArchiveIndexRequest) error
|
||
|
}
|