engine

package
v0.0.0-...-e29e17f Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2020 License: Apache-2.0, Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrUnauthorized is the error returned when an unauthorized request is made
	ErrUnauthorized = errors.New("you are not authorized to perform this command against the connected server")
)

Functions

func SetHeader

func SetHeader(r *http.Request, header, value string)

SetHeader sets a given header with a value on a request

func WrapAPIErrors

func WrapAPIErrors(err error, rErrs []ResponseError) error

WrapAPIErrors transforms an api error response into one wrapped error

Types

type Engine

type Engine struct {
	Client      *http.Client
	APIEndpoint string
	IndexKey    string
	AccessKey   string
}

Engine represents the search engine

func NewEngine

func NewEngine(client *http.Client, indexKey, accessKey string) *Engine

NewEngine creates a new engine

func (*Engine) DownloadFile

func (e *Engine) DownloadFile(url string) error

DownloadFile attempts to download a file from the api

func (*Engine) ExistsAtIndexPath

func (e *Engine) ExistsAtIndexPath(path string) (bool, error)

ExistsAtIndexPath checks if a file already exists at this index path

func (*Engine) Index

func (e *Engine) Index(filePath, filename, indexPath string) error

Index stores and indexes a file with the API

func (*Engine) Ready

func (e *Engine) Ready() (bool, error)

Ready checks to see if the API is up and ready

func (*Engine) Search

func (e *Engine) Search(text string) (*SearchResponse, error)

Search returns all search results for a query

type Response

type Response struct {
	Results interface{}     `json:"results"`
	Errors  []ResponseError `json:"errors,omitempty"`
}

Response is the format used for all api responses

type ResponseError

type ResponseError struct {
	Message string `json:"message"`
}

ResponseError is the format used for api response errors

func (ResponseError) Error

func (a ResponseError) Error() string

Error implements the error interface

type SearchResponse

type SearchResponse struct {
	Distances []float32      `json:"distances"`
	Documents []SearchResult `json:"documents"`
}

SearchResponse represents the structure of a returned search query

type SearchResult

type SearchResult struct {
	Path         string  `json:"path"`
	DocumentName string  `json:"name"`
	DownloadURL  string  `json:"downloadURL"`
	Text         string  `json:"text"`
	Rank         float32 `json:"rel"`
}

SearchResult represents search results

Jump to

Keyboard shortcuts

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