places

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2022 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// StreetClass is the place class of streets.
	StreetClass = iota

	// LocationClass is place class of locations.
	LocationClass

	// HouseNumberClass is the place class of house numbers / buildings.
	HouseNumberClass
)

Variables

View Source
var DefaultConfig = &Config{
	MaxPrefixLength:    4,
	MinCompletionCount: 5,
	MinLev:             4,
	DistanceCut:        4,
	CacheTTL:           300 * time.Second,
}

DefaultConfig is the default configuration for Places.

Functions

func Abs added in v1.1.0

func Abs(x int) int

Abs returns the absolute value of x.

func Min added in v1.1.0

func Min(a, b int) int

Min returns the minimum of a and b.

func SanitizeString added in v1.1.0

func SanitizeString(s string) string

SanitizeString to unicode letters, spaces and minus

Types

type Class added in v1.0.1

type Class int32

Class enumerates different place types / classes.

func (Class) String added in v1.0.1

func (c Class) String() string

String implements the stringer interface for Class.

type Config added in v1.0.1

type Config struct {

	// MaxPrefixLength is the maximum prefixes length to precompute results for.
	MaxPrefixLength int `json:"maxPrefixLength"`

	// MinCompletionCount is the number of results to return.
	MinCompletionCount int `json:"minCompletionCount"`

	// MinLev is the minimum input length before doing Levenshtein comparison.
	MinLev int `json:"minLev"`

	// DistanceCut is used in result ranking. DistanceCut is the delta in distances
	// to ignore in favor of relevance (unless one of the results has a distance of
	// 0).
	DistanceCut int `json:"distanceCut"`

	// Duration to wait before evicting cache entries (in order to consider
	// potentially changed relevance values).
	CacheTTL time.Duration `json:"cacheTTL"`
}

Config is the configuration for Places.

func (Config) NewPlaces added in v1.0.1

func (config Config) NewPlaces(dataProvider Provider) (*Places, error)

NewPlaces initializes a new Places object.

type District added in v1.1.0

type District struct {
	Postcode string
	District string
}

type DistrictMap added in v1.1.0

type DistrictMap map[string]*District

type Metrics added in v0.2.0

type Metrics struct {
	StreetCount      int32         `json:"streetCount"`
	LocationCount    int32         `json:"locationCount"`
	HouseNumberCount int32         `json:"houseNumberCount"`
	PrefixCount      int           `json:"prefixCount"`
	QueryCount       int64         `json:"queryCount"`
	AvgLookupTime    time.Duration `json:"avgLookupTime"`
}

Metrics is the type to sore metrics.

type Place added in v1.0.1

type Place struct {
	ID           int64
	Class        Class
	Type         string
	Name         string
	Street       *Place
	HouseNumber  string
	District     *District
	Length       int
	Lat          float64
	Lon          float64
	Relevance    uint64
	SimpleName   string
	HouseNumbers []*Place
}

func (*Place) MarshalJSON added in v1.0.1

func (p *Place) MarshalJSON() ([]byte, error)

MarshalJSON marshall a place to JSON.

type PlaceMap added in v1.1.0

type PlaceMap map[int64]*Place

type Places

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

Places is where all happens.

func (*Places) Config added in v1.0.1

func (bp *Places) Config() Config

Config returns the configuration.

func (*Places) GetCompletions added in v0.3.0

func (bp *Places) GetCompletions(ctx context.Context, input string) []*Result

GetCompletions returns results for the given input.

func (*Places) GetPlace added in v0.3.0

func (bp *Places) GetPlace(ctx context.Context, placeID int64, houseNumber string) *Place

func (*Places) Metrics added in v0.2.0

func (bp *Places) Metrics() Metrics

Metrics returns current metrics.

type Provider added in v1.1.0

type Provider interface {
	Get() (DistrictMap, PlaceMap, *Metrics, error)
}

type Result added in v1.0.1

type Result struct {
	Distance int    `json:"distance"`
	Place    *Place `json:"place"`
}

Result wraps a place.

Jump to

Keyboard shortcuts

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