bangs

package
v0.0.0-...-c5d5a31 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2020 License: Apache-2.0 Imports: 9 Imported by: 3

Documentation

Overview

Package bangs provides functionality to query other websites

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bang

type Bang struct {
	Name      string            `json:"name"`
	FavIcon   string            `json:"favicon"`
	Triggers  []string          `json:"triggers"`
	Regions   map[string]string `json:"regions"`
	Functions []string          `json:"-"`
	Funcs     []fn              `json:"-"`
}

Bang holds a single !bang

type Bangs

type Bangs struct {
	Bangs []Bang `mapstructure:"bang"`
	Suggester
}

Bangs holds a map of !bangs

func New

func New(cfg Provider) (*Bangs, error)

New creates Bangs from a config file

func (*Bangs) CreateFunctions

func (b *Bangs) CreateFunctions() error

CreateFunctions creates []Funcs from []Functions. Is a workaround since I couldn't find a way to map a function type in a config file.

func (*Bangs) Detect

func (b *Bangs) Detect(q string, region language.Region, l language.Tag) (Bang, string, bool)

Detect lets us know if we have a !bang match.

func (*Bangs) Suggest

func (b *Bangs) Suggest(term string, size int) (Results, error)

Suggest is an autocomplete for !bangs

type ElasticSearch

type ElasticSearch struct {
	Client *elastic.Client
	Index  string
	Type   string
}

ElasticSearch holds the index name and the connection

func (*ElasticSearch) DeleteIndex

func (e *ElasticSearch) DeleteIndex() error

DeleteIndex will delete the existing index

func (*ElasticSearch) IndexExists

func (e *ElasticSearch) IndexExists() (bool, error)

IndexExists returns true if the index exists

func (*ElasticSearch) Setup

func (e *ElasticSearch) Setup(bangs []Bang) error

Setup recreates the completion index

func (*ElasticSearch) SuggestResults

func (e *ElasticSearch) SuggestResults(term string, size int) (Results, error)

SuggestResults retrieves !bang suggestions from Elasticsearch

type Provider

type Provider interface {
	ReadInConfig() error
	Unmarshal(interface{}, ...viper.DecoderConfigOption) error
}

Provider is a configuration provider

type Results

type Results struct {
	Suggestions []Suggestion `json:"suggestions"`
}

Results are the results of an autocomplete query

type Simple

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

Simple is a simple autocomplete suggester

func (*Simple) DeleteIndex

func (s *Simple) DeleteIndex() error

DeleteIndex will delete the existing index

func (*Simple) IndexExists

func (s *Simple) IndexExists() (bool, error)

IndexExists returns true if the index exists

func (*Simple) Setup

func (s *Simple) Setup(bangs []Bang) error

Setup recreates the completion index

func (*Simple) SuggestResults

func (s *Simple) SuggestResults(term string, size int) (Results, error)

SuggestResults handles autocomplete queries

type Suggester

type Suggester interface {
	IndexExists() (bool, error)
	DeleteIndex() error
	Setup([]Bang) error
	SuggestResults(term string, size int) (Results, error)
}

Suggester is a !bangs suggester/autocomplete

type Suggestion

type Suggestion struct {
	Trigger string `json:"trigger"`
	Name    string `json:"name"`
	FavIcon string `json:"favicon"`
}

Suggestion is an individual !bang autocomplete suggestion

Jump to

Keyboard shortcuts

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