Documentation
¶
Overview ¶
Package search is the datastream search index.
A builder takes sites, then stations, then datastreams for one organization. The first record sets OrganizationID. Later records must use that same id. Finish writes that organization's shard. FinishPrivate keeps shown and exact geometry and every datastream. FinishPublic copies shown into the exact fields and keeps public_ok datastreams only. The index stays in place, so Finish may be called again with the other mode. Open loads those bytes into an immutable shard and builds the shown and exact R-trees. Query reads the shard. Combine merges one result per organization and clusters the sites once. An interval may carry a group id. Query.GroupIDs filters on that id. GroupIDs lists the ids on intervals in play. ReducePicker turns organization and group catalogs, the checked ids, and those lists into the picker rows.
WriteContainer and ParseContainer frame public shards in an uncompressed DSPC container. VersionFile marshals the current.json pointer. An empty Encoding means the object is raw. This package does not compress.
The caller chooses the geometry name and whether member-only datastreams are included. This package does not open sockets, and it does not decide who may see a site.
Index ¶
- Constants
- Variables
- func Measurement(i int) string
- func WriteContainer(chunks []ContainerChunk) ([]byte, error)
- type BenchCase
- type Box
- type Builder
- func (b *Builder) AddDatastream(datastream Datastream) error
- func (b *Builder) AddDatastreams(datastreams []Datastream) error
- func (b *Builder) AddSite(site Site) error
- func (b *Builder) AddSites(sites []Site) error
- func (b *Builder) AddStation(station Station) error
- func (b *Builder) AddStations(stations []Station) error
- func (b *Builder) Finish(mode FinishMode) ([]byte, uint32, error)
- func (b *Builder) HasSite(id string) bool
- func (b *Builder) HasStation(id string) bool
- type CatalogName
- type Cluster
- type ContainerChunk
- type Count
- type Datastream
- type FinishMode
- type Fixture
- type Hit
- type Interval
- type KeepEntry
- type Kind
- type PickerRow
- type Point
- type Query
- type Result
- type Shard
- type Site
- type SiteMarker
- type Spec
- type Station
- type VersionFile
Constants ¶
const ( GeometryShown = "shown" GeometryExact = "exact" )
Geometry names stored on every site. The caller picks one per query.
const ( DefaultMapSiteLimit uint32 = 100 DefaultMinSiteZoom uint32 = 6 )
Defaults when a query leaves the map limits at zero.
const ( PurposeReadyToUse = "ReadytoUse" PurposeRaw = "Raw" PurposeStatusInformation = "StatusInformation" )
Purpose values used by the fixtures. Query treats purpose as an ordinary string.
const FixtureSeed int64 = 1
FixtureSeed is the generator seed. The same seed always yields the same bytes.
Variables ¶
var ( // ErrOrder means a site, station, or datastream was added out of feed order. // Sites come first, then stations, then datastreams. ErrOrder = errors.New("search: sites, then stations, then datastreams") // ErrFinished means Add was called after Finish. Finish itself may be called again. ErrFinished = errors.New("search: builder is finished") // ErrDuplicate means a site, station, or datastream id was added twice. ErrDuplicate = errors.New("search: duplicate id") // ErrNotFound means a datastream names a site or station that was not added. ErrNotFound = errors.New("search: unknown site or station") // ErrInterval means a deployment interval is empty, overlapping, inverted, // or has more than one open end. Zero open ends is a deployment that has ended. ErrInterval = errors.New("search: invalid interval") // ErrDatastream means a datastream has no place, or both a station and its own intervals. ErrDatastream = errors.New("search: invalid datastream") // ErrBox means a site box or digest point is outside WGS84 or wraps the antimeridian. // Split a wrapping site before AddSite. ErrBox = errors.New("search: invalid box") // ErrGeometry means Query.Geometry is not "shown" or "exact". ErrGeometry = errors.New("search: geometry must be shown or exact") // ErrViewport means a viewport is outside WGS84 or has south above north. ErrViewport = errors.New("search: invalid viewport") // ErrWindow means only one time bound was set, or the end is not after the start. ErrWindow = errors.New("search: invalid time window") // ErrFormat means the bytes are not a shard this package can open. ErrFormat = errors.New("search: invalid shard") // ErrContainer means the bytes are not a DSPC frame this package can parse. ErrContainer = errors.New("search: invalid container") // ErrInvalid means a required id is empty, related records name different // organizations, or the receiver is nil. ErrInvalid = errors.New("search: invalid value") )
Functions ¶
func Measurement ¶
Measurement returns one of the twelve synthetic measurement names.
func WriteContainer ¶
func WriteContainer(chunks []ContainerChunk) ([]byte, error)
WriteContainer frames chunks in the order given. It does not sort organizations, inspect shard magic, or decide which etag changed.
Types ¶
type BenchCase ¶
BenchCase is one timed query in the benchmark matrix.
func BenchCases ¶
BenchCases returns the four design cases. The shown-versus-exact case is two queries.
type Box ¶
type Box struct {
West, South, East, North float64
}
Box is a longitude/latitude rectangle. West and South are the minimums, East and North the maximums. A point is a box whose corners are equal. A viewport may wrap the antimeridian (East < West). A site box may not.
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder accumulates one organization. The first added record sets OrganizationID. Later records must use that same id. Feed sites, then stations, then datastreams. Each accepted datastream is recorded into the index immediately. Finish serializes that index and returns the shard bytes and the doc count.
func NewBuilder ¶
func NewBuilder() *Builder
NewBuilder returns an empty builder for one organization.
func (*Builder) AddDatastream ¶
func (b *Builder) AddDatastream(datastream Datastream) error
AddDatastream records one datastream into the posting lists, interval table, and forward rows. The doc id is the accept order. The struct is not retained.
func (*Builder) AddDatastreams ¶
func (b *Builder) AddDatastreams(datastreams []Datastream) error
AddDatastreams adds each datastream in order.
func (*Builder) AddStation ¶
AddStation appends one station and copies its intervals.
func (*Builder) AddStations ¶
AddStations adds each station in order.
func (*Builder) Finish ¶
func (b *Builder) Finish(mode FinishMode) ([]byte, uint32, error)
Finish serializes the index recorded by AddDatastream. FinishPrivate writes every datastream. FinishPublic writes public_ok datastreams only, with exact geometry copied from shown. The index is left in place. Another Finish is allowed, in either order, and the same mode twice returns the same bytes. Add after the first Finish returns ErrFinished. An unknown mode returns ErrInvalid and does not seal.
func (*Builder) HasSite ¶
HasSite reports whether AddSite accepted id. The lookup uses the id map AddSite already keeps.
func (*Builder) HasStation ¶
HasStation reports whether AddStation accepted id. The lookup uses the id map AddStation already keeps.
type CatalogName ¶
CatalogName is one row from the host's organization or group list. The host supplies the name. This package does not look it up.
type ContainerChunk ¶
ContainerChunk is one organization's public shard inside an uncompressed DSPC frame. Bytes are stored and returned unchanged.
func ParseContainer ¶
func ParseContainer(frame []byte) ([]ContainerChunk, error)
ParseContainer reads an uncompressed DSPC frame. The chunk bytes are copies.
type Count ¶
type Count struct {
Value string
Count uint32
Name string
OrganizationID string
OrganizationName string
}
Count is one disjunctive facet row. Name and organization fields are set on site counts (from the Site record) so a host can label zero-count rows that never appear as map markers. Measurement counts leave them empty.
type Datastream ¶
type Datastream struct {
ID string
Name string
OrganizationID string
StationID string
UnitName string
Measurement string
Purpose string
PublicOK bool
MemberOK bool
// FieldNames are the datastream output field names, in display order.
// Empty means the datastream has none. The builder copies the slice.
FieldNames []string
// HasInfo is set by the host when the datastream has extra info to show.
// The library stores the bit and does not decide which fields count.
HasInfo bool
Intervals []Interval
}
Datastream is one searchable row. Set StationID, or set Intervals for a site-attached datastream, not both. OrganizationID is required and must match the builder. Doc ids are assigned in AddDatastream order.
type FinishMode ¶
type FinishMode int
FinishMode selects which shard Finish writes. The index stays in place, so Finish may be called again with the other mode.
const ( // FinishPrivate writes shown and exact boxes and every accepted datastream. FinishPrivate FinishMode = iota // FinishPublic writes exact boxes and points copied from shown, and // public_ok datastreams only. Sites with no public datastream are omitted. FinishPublic )
type Fixture ¶
type Fixture struct {
Name string
Seed int64
Orgs int
Sites int
Datastreams int
Blobs [][]byte
DocCounts []uint32
ShiftedSiteID string
ShiftedExact Point
ShiftedShown Point
Finish time.Duration
}
Fixture is a deterministic catalog of shard bytes.
func TodayCatalog ¶
TodayCatalog is the public catalog, rounded.
type Hit ¶
type Hit struct {
DocID uint32
DatastreamID string
Name string
OrganizationID string
OrganizationName string
StationID string
StationName string
SiteID string
SiteName string
UnitName string
Measurement string
Purpose string
FieldNames []string
// HasInfo is the forward-row bit the host set. It does not name a field.
HasInfo bool
// BeginsAt and EndsBefore are the outer deployment window, Unix
// milliseconds. EndsBefore is 0 when the last deployment is still open.
// They do not follow the query window or the site on this hit.
BeginsAt int64
EndsBefore int64
}
Hit is one matching datastream in doc id order.
type Interval ¶
Interval is a half-open deployment [BeginsAt, EndsBefore) in Unix milliseconds. EndsBefore == 0 means the interval is still open, the same as an unset ends_before on the wire. A non-zero EndsBefore means the deployment has ended. A datastream has at most one open interval. Every interval may be closed. GroupID is optional. Empty means the interval has no group. The builder stores the id and does not look up a name.
type PickerRow ¶
PickerRow is one visible picker row. Grey means the row is checked, the other side has at least one check, and this id is not relevant. The host keeps that check until the user clears it.
func ReducePicker ¶
func ReducePicker(orgs, groups []CatalogName, checkedOrgs, checkedGroups []string, groupsByOrg map[string][]string) (orgRows, groupRows []PickerRow)
ReducePicker builds the organization list and the group list.
orgs and groups are the catalogs after the host's text filter, in the order to display. checkedOrgs and checkedGroups are the full check sets, including ids the text filter hid. A hidden check still narrows the other side and is omitted from the returned rows. groupsByOrg maps each visible organization to the group ids GroupIDs returned for it.
A checked id that is not in the catalog argument is omitted here. This function does not change the check sets. The host drops a check that is outside the unfiltered catalog.
Neither side checked: both lists are the filtered catalogs, and nothing is grey. Checking organizations whittles groups to the union of groupsByOrg for those organizations. Checking groups whittles organizations to those whose set intersects the checked groups. The two reductions are independent.
type Point ¶
type Point struct {
Lon, Lat float64
}
Point is a WGS84 digest point. Clustering uses this, not a centroid substituted for an area box.
type Query ¶
type Query struct {
Purpose string
Measurements []string
SiteIDs []string
// GroupIDs filters intervals. Empty means every datastream, including
// intervals with no group. Several ids are a union: a datastream matches
// when one qualifying interval carries any listed id.
GroupIDs []string
BeginsAt int64
EndsBefore int64
Viewport *Box
Geometry string
Zoom uint32
IncludeMemberOnly bool
MapSiteLimit uint32
MinSiteZoom uint32
// AllHits returns every matching hit when the layer is sites, and no hit
// rows when the layer is clusters. TotalCount is still set. PageSize and
// PageAfter are ignored. HasMore is false.
AllHits bool
// PageSize is the maximum number of hits to return. Zero returns none.
// TotalCount is still set. Ignored when AllHits is set.
PageSize uint32
// PageAfter is the first doc id to return, inclusive. Zero starts at the
// beginning. Pass Result.NextPageAfter only when Result.HasMore is set.
// The cursor is valid only for the byte slice this shard was opened from.
PageAfter uint32
}
Query is one read of a shard. Empty slices and a nil viewport leave that predicate out. Both time bounds zero means the open deployment.
type Result ¶
type Result struct {
Kind Kind
Clusters []Cluster
Sites []SiteMarker
Candidates []SiteMarker
SiteTotal uint32
Bounds Box
SiteCounts []Count
MeasurementCounts []Count
Hits []Hit
TotalCount uint32
NextPageAfter uint32
HasMore bool
}
Result is the map layer for one shard, or for Combine. Candidates is the filtered site list before the cluster/site switch. Combine uses it. Measurement counts are always set. Site counts are set only for KindSites.
func Combine ¶
Combine merges per-organization results and chooses the map layer once. Measurement counts are summed on every result. Site counts are summed only when the merged layer is sites. Hits are concatenated in the order of parts; paging stays on each shard. Pass the same query that produced the parts, including zoom and the site limit.
type Shard ¶
type Shard struct {
// contains filtered or unexported fields
}
Shard is an immutable index. Query may run from many goroutines. Open inserts both R-trees. Query allocates temporary bitmaps only.
func (*Shard) GroupIDs ¶
GroupIDs returns the distinct group ids on in-play intervals of datastreams the caller may see. The result is sorted. Empty group ids are omitted. There is no count. Purpose, measurement, site, viewport, and Query.GroupIDs are not applied. includeMemberOnly false uses public_ok. True uses public_ok ∪ member_ok.
type Site ¶
type Site struct {
ID string
Name string
OrganizationID string
OrganizationName string
Shown Box
Exact Box
ShownPoint Point
ExactPoint Point
}
Site is one place in an organization shard. OrganizationID is required. Shown and Exact are both stored. Open inserts each box into its own R-tree.
type SiteMarker ¶
type SiteMarker struct {
SiteID string
Name string
OrganizationID string
OrganizationName string
Point Point
Box Box
DatastreamCount uint32
}
SiteMarker is one candidate site in the geometry the caller named.
type Station ¶
Station holds deployment intervals for station-attached datastreams. OrganizationID is required and must match the builder.
type VersionFile ¶
type VersionFile struct {
ObjectKey string `json:"object_key"`
ETag string `json:"etag"`
Size int64 `json:"size"`
BuiltAt time.Time `json:"built_at,omitempty"`
DocCount *uint32 `json:"doc_count,omitempty"`
IsEnabled *bool `json:"is_enabled,omitempty"`
IsHidden *bool `json:"is_hidden,omitempty"`
PublicOK *bool `json:"public_ok,omitempty"`
Encoding string `json:"encoding,omitempty"`
Keep []KeepEntry `json:"keep,omitempty"`
}
VersionFile is the current.json pointer for a shard or a container. An empty Encoding means the object is raw bytes. "gzip" is a label the caller sets; this struct does not compress.
func ParseVersionFile ¶
func ParseVersionFile(b []byte) (VersionFile, error)
ParseVersionFile decodes a current.json pointer. Unknown fields are rejected.
func (VersionFile) Marshal ¶
func (v VersionFile) Marshal() ([]byte, error)
Marshal encodes the pointer as JSON. An empty Encoding is omitted.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
bench
command
Command bench runs the fixture matrix and writes BENCHMARKS.md.
|
Command bench runs the fixture matrix and writes BENCHMARKS.md. |
|
demo
command
Command demo builds a handful of sites and prints one cluster query and one site query, then the north and south group picker.
|
Command demo builds a handful of sites and prints one cluster query and one site query, then the north and south group picker. |
|
map
command
Command map serves the static Explore demo.
|
Command map serves the static Explore demo. |
|
wasm
command
Browser wrappers for Generate, Open, Query, and Combine.
|
Browser wrappers for Generate, Open, Query, and Combine. |
|
Product browser host for Explore.
|
Product browser host for Explore. |