search

package
v0.0.0-...-920eab1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 5, 2022 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add

func Add(entry *IndexData)

func AddEntry

func AddEntry(src DbSource)

func Analyze

func Analyze(source string) []string

func GenerateIndexer

func GenerateIndexer()

func LoadDb

func LoadDb(recordsFile io.Reader, indexFile io.Reader) error

func ResetMemoryDb

func ResetMemoryDb()

func SaveDb

func SaveDb(recFile io.Writer, idxFile io.Writer) error

func Tokenize

func Tokenize(source string) []string

takes in a source of text and converts into an array of stemmed tokens (filtering out stop words and punctuation) This gets called when ingesting new data and when searching TODO: or is it better to just "generateAllPossibleVarations" of a word on the client side, then wouldn't need to stem on the backend?

func WriteRecordsToFile

func WriteRecordsToFile(input io.Writer)

Types

type ApolloIndexer

type ApolloIndexer struct {
	// contains filtered or unexported fields
}

func NewApolloIndexer

func NewApolloIndexer() *ApolloIndexer

func (*ApolloIndexer) AddEntries

func (s *ApolloIndexer) AddEntries(entries []*IndexData)

func (*ApolloIndexer) AddEntry

func (s *ApolloIndexer) AddEntry(entry *IndexData)

func (*ApolloIndexer) AddSrcToDb

func (s *ApolloIndexer) AddSrcToDb(data []*IndexData)

func (*ApolloIndexer) Search

func (s *ApolloIndexer) Search(keywords string) ([]SearchResult, error)

type BleveIndexer

type BleveIndexer struct {
	// contains filtered or unexported fields
}

func NewBleveIndexer

func NewBleveIndexer() *BleveIndexer

func OpenBleveIndexer

func OpenBleveIndexer(bleveDir string) *BleveIndexer

func (*BleveIndexer) AddEntry

func (s *BleveIndexer) AddEntry(entry *IndexData)

func (*BleveIndexer) AddSrcToDb

func (s *BleveIndexer) AddSrcToDb(entries []*IndexData)

func (*BleveIndexer) ExactSearch

func (s *BleveIndexer) ExactSearch(keywords string) ([]SearchResult, error)

func (*BleveIndexer) Search

func (s *BleveIndexer) Search(keywords string) ([]SearchResult, error)

type DataApi

type DataApi interface {
	Search(string) ([]SearchResult, error)
}

type DbSource

type DbSource interface {
	TransformToData() ([]*IndexData, error)
}

type DummyFile

type DummyFile struct {
	Content string
	Title   string
}

func (DummyFile) TransformToData

func (d DummyFile) TransformToData() ([]*IndexData, error)

type Id

type Id string

type IndexData

type IndexData struct {
	Title       string   `json:"title"`
	Link        string   `json:"link"`
	Content     string   `json:"content"`
	Tags        []string `json:"tags"`
	Provider    string   `json:"provider"`
	ContentType string   `json:"contentType"`
}

type Indexer

type Indexer interface {
	AddSrcToDb([]*IndexData)
	Search(string) ([]SearchResult, error)
}

func NewPersistentBleveIndexer

func NewPersistentBleveIndexer(bleveDir string) Indexer

type OpenedBleveIndexer

type OpenedBleveIndexer struct {
	// contains filtered or unexported fields
}

func (*OpenedBleveIndexer) AddSrcToDb

func (s *OpenedBleveIndexer) AddSrcToDb(entries []*IndexData)

func (*OpenedBleveIndexer) ExactSearch

func (s *OpenedBleveIndexer) ExactSearch(keywords string) ([]SearchResult, error)

func (*OpenedBleveIndexer) Search

func (s *OpenedBleveIndexer) Search(keywords string) ([]SearchResult, error)

type Record

type Record struct {
	//unique identifier
	ID Id `json:"id"`
	//title
	Title string `json:"title"`
	//potential link to the source if applicable
	Link string `json:"link"`
	//text content to display on results page
	Content string `json:"content"`
	//map of tokens to their frequency
	TokenFrequency map[string]int `json:"tokenFrequency"`
	Provider       string         `json:"provider"`
}

database unit for all sources

func ReadRecord

func ReadRecord(id Id) (Record, error)

func ReadRecordFromFile

func ReadRecordFromFile(file io.Reader, id Id) (Record, error)

type SearchResult

type SearchResult struct {
	Title       string  `json:"title"`
	Link        string  `json:"link"`
	Content     string  `json:"content"`
	Provider    string  `json:"provider"`
	Matches     int     `json:"matches"`
	ContentType string  `json:"contentType"`
	Score       float64 `json:"score"`
}
type SearchResult struct {
	IndexData
	Matches     int    `json:"matches"`
}

func BatchDuplicateResults

func BatchDuplicateResults(slice []SearchResult) []SearchResult
func Search(query string) ([]SearchResult, error)

OR match

type Searcher

type Searcher struct {
	// contains filtered or unexported fields
}

func NewSearcher

func NewSearcher() *Searcher

func NewSearcherUsingIndexer

func NewSearcherUsingIndexer(idx Indexer) *Searcher

func (*Searcher) AddApiClient

func (s *Searcher) AddApiClient(src DataApi)

func (*Searcher) AddSrcToDb

func (s *Searcher) AddSrcToDb(src DbSource)

func (Searcher) Search

func (s Searcher) Search(keywords string) ([]SearchResult, error)

type SearcherI

type SearcherI interface {
	AddApiClient(DataApi)
	AddSrcToDb(DbSource)
	Search(string) ([]SearchResult, error)
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL