data

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Page                    = "page"
	DayBefore               = "before-day"
	DayAfter                = "after-day"
	Before                  = "before"
	MonthBefore             = Before + "-month"
	After                   = "after"
	MonthAfter              = After + "-month"
	YearBefore              = "before-year"
	YearAfter               = "after-year"
	Query                   = "query"
	DateFrom                = "after-date"
	DateFromErr             = DateFrom + "-error"
	DateTo                  = "before-date"
	DateToErr               = DateTo + "-error"
	Type                    = "release-type"
	PaginationErr           = "pagination-error"
	ContentTypeFilterErr    = "filter-error"
	TopicFilterErr          = "topic-error"
	PopulationTypeFilterErr = "population-error"
	DimensionsFilterErr     = "dimensions-error"
	QueryStringErr          = "query-string-error"
)
View Source
const AllowedSpecialCharacters = "–‘’"

contains the special characters that are allowed in query validation

View Source
const DateFormat = "2006-01-02"

Variables

View Source
var (
	// Categories represent the list of all search categories
	Categories = []Category{Publication, Data, Other}

	// Publication - search information on publication category
	Publication = Category{
		LocaliseKeyName: "Publication",
		ContentTypes:    []ContentType{Bulletin, Article, Compendium},
	}

	// Data - search information on data category
	Data = Category{
		LocaliseKeyName: "Data",
		ContentTypes:    []ContentType{TimeSeries, Datasets, UserRequestedData},
	}

	// Other - search information on other categories
	Other = Category{
		LocaliseKeyName: "Other",
		ContentTypes:    []ContentType{Methodology, CorporateInformation, ProductPage},
	}

	// UnusedCategories - these categories are served from the Search API but we don't use them for filters.
	// If left in, they create noise in the logs about unexpected filters being returned.
	UnusedCategoryTypes = []string{
		"api_dataset_landing_page",
		"compendium_chapter",
		"compendium_data",
		"dataset",
		"home_page",
		"home_page_census",
		"reference_tables",
		"release",
		"taxonomy_landing_page",
		"visualisation",
	}

	// Bulletin - Search information specific for statistical bulletins
	Bulletin = ContentType{
		LocaliseKeyName: "StatisticalBulletin",
		Group:           "bulletin",
		Types:           []string{"bulletin"},
		ShowInWebUI:     true,
	}

	// Article - Search information specific for articles
	Article = ContentType{
		LocaliseKeyName: "Article",
		Group:           "article",
		Types:           []string{"article", "article_download"},
		ShowInWebUI:     true,
	}

	// Compendium - Search information specific for compendium
	Compendium = ContentType{
		LocaliseKeyName: "Compendium",
		Group:           "compendia",
		Types:           []string{"compendium_landing_page"},
		ShowInWebUI:     true,
	}

	// TimeSeries - Search information specific for time series
	TimeSeries = ContentType{
		LocaliseKeyName: "TimeSeries",
		Group:           "time_series",
		Types:           []string{"timeseries"},
		ShowInWebUI:     true,
	}

	// Datasets - Search information specific for datasets
	Datasets = ContentType{
		LocaliseKeyName: "Datasets",
		Group:           "datasets",
		Types:           []string{"dataset_landing_page", "timeseries_dataset"},
		ShowInWebUI:     true,
	}

	DatasetLandingPage = ContentType{
		LocaliseKeyName: "Datasets",
		Group:           "dataset_landing_page",
		Types:           []string{"dataset_landing_page"},
		ShowInWebUI:     true,
	}

	// UserRequestedData - Search information specific for user requested data
	UserRequestedData = ContentType{
		LocaliseKeyName: "UserRequestedData",
		Group:           "user_requested_data",
		Types:           []string{"static_adhoc"},
		ShowInWebUI:     true,
	}

	// Methodology - Search information specific for methodologies
	Methodology = ContentType{
		LocaliseKeyName: "Methodology",
		Group:           "methodology",
		Types:           []string{"static_methodology", "static_methodology_download", "static_qmi"},
		ShowInWebUI:     true,
	}

	// CorporateInformation - Search information specific for corporate information
	CorporateInformation = ContentType{
		LocaliseKeyName: "CorporateInformation",
		Group:           "corporate_information",
		Types:           []string{"static_foi", "static_page", "static_landing_page", "static_article"},
		ShowInWebUI:     true,
	}

	// ProductPage - Search information specific for product pages
	ProductPage = ContentType{
		LocaliseKeyName: "ProductPage",
		Group:           "product_page",
		Types:           []string{"product_page"},
		ShowInWebUI:     false,
	}
)
View Source
var (
	// SortOptions represent the list of all search sort options
	SortOptions        = []Sort{Relevance, ReleaseDate, Title}
	DatasetSortOptions = []Sort{ReleaseDate, Title}

	// Relevance - informing on sorting based on relevance
	Relevance = Sort{
		Query:           "relevance",
		LocaliseKeyName: "Relevance",
	}

	// ReleaseDate - informing on sorting based on release date
	ReleaseDate = Sort{
		Query:           "release_date",
		LocaliseKeyName: "ReleaseDate",
	}

	// Title - informing on sorting based on title
	Title = Sort{
		Query:           "title",
		LocaliseKeyName: "Title",
	}
)
View Source
var LimitOptions = []int{
	10,
	25,
	50,
}

LimitOptions contains all available limit parameter values

Functions

func CapitalizeFirstLetter added in v0.55.0

func CapitalizeFirstLetter(input string) string

CapitalizeFirstLetter is a helper function that transforms the first letter of a string to uppercase

func GetDataAggregationQuery added in v0.47.0

func GetDataAggregationQuery(validatedQueryParams SearchURLParams, template string) url.Values

GetDataAggregationQuery gets the query that needs to be passed to the search-api to get data aggregation results

func GetFirstAndLastPages added in v0.18.0

func GetFirstAndLastPages(req http.Request, validatedQueryParams SearchURLParams, totalPages int) []model.PageToDisplay

GetFirstAndLastPages gets the first and last pages

func GetGroupLocaliseKey added in v0.18.0

func GetGroupLocaliseKey(resultType string) string

GetGroupLocaliseKey gets the localise key of the group type of the search result to be displayed

func GetPagesToDisplay added in v0.5.0

func GetPagesToDisplay(cfg *config.Config, req http.Request, validatedQueryParams SearchURLParams, totalPages int) []model.PageToDisplay

GetPagesToDisplay gets all the pages available for the search results

func GetSearchAPIQuery added in v0.5.0

func GetSearchAPIQuery(validatedQueryParams SearchURLParams, censusTopicCache *cache.Topic) url.Values

GetSearchAPIQuery gets the query that needs to be passed to the search-api to get search results

func GetTotalPages added in v0.5.0

func GetTotalPages(cfg *config.Config, limit, count int) int

GetTotalPages gets the total pages of the search results

func IsCategoryUnused added in v0.58.0

func IsCategoryUnused(categoryName string) bool

IsCategoryUnused returns if a category is unused.

func SetParentTypeOnSearchAPIQuery added in v0.65.0

func SetParentTypeOnSearchAPIQuery(validatedQueryParams SearchURLParams, parentType string) url.Values

SetParentTypeOnSearchAPIQuery sets the parent type (e.g. if this is previous releases for a bulletin) on the search API query

Types

type Category

type Category struct {
	LocaliseKeyName string        `json:"localise_key"`
	Count           int           `json:"count"`
	ContentTypes    []ContentType `json:"content_types"`
}

Category represents all the search categories in search page

func GetCategories added in v0.5.0

func GetCategories() []Category

GetCategories returns all the categories and its content types where all the count is set to zero

type ContentType

type ContentType struct {
	LocaliseKeyName string   `json:"localise_key"`
	Count           int      `json:"count"`
	Group           string   `json:"group"`
	Types           []string `json:"types"`
	ShowInWebUI     bool     `json:"show_in_web_ui"`
}

ContentType represents the type of the search results and the number of results for each type

type Date added in v0.47.0

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

func DateFromTime added in v0.47.0

func DateFromTime(t time.Time) Date

DateFromTime extracts a date from a time object

func GetEndDate added in v0.55.0

func GetEndDate(params url.Values) (endDate Date, validationErrs []core.ErrorItem)

func GetStartDate added in v0.55.0

func GetStartDate(params url.Values) (startDate Date, validationErrs []core.ErrorItem)

GetStartDate returns the validated date from parameters

func MustParseDate added in v0.47.0

func MustParseDate(dateAsString string) Date

MustParseDate checks if the date format is correct and parsable

func MustSetFieldsetErrID added in v0.55.0

func MustSetFieldsetErrID(id string) (d Date)

func ParseDate added in v0.47.0

func ParseDate(dateAsString string) (Date, error)

ParseDate parses the date into the default DateFormat

func ValidateDateRange added in v0.55.0

func ValidateDateRange(from, to Date) (end Date, err error)

ValidateDateRange returns an error and 'to' date if the 'from' date is after than the 'to' date

func (Date) DayString added in v0.47.0

func (d Date) DayString() string

func (Date) GetFieldsetErrID added in v0.55.0

func (d Date) GetFieldsetErrID() string

func (Date) HasDayValidationErr added in v0.55.0

func (d Date) HasDayValidationErr() bool

func (Date) HasMonthValidationErr added in v0.55.0

func (d Date) HasMonthValidationErr() bool

func (Date) HasYearValidationErr added in v0.55.0

func (d Date) HasYearValidationErr() bool

func (Date) MonthString added in v0.47.0

func (d Date) MonthString() string

func (Date) String added in v0.47.0

func (d Date) String() string

func (Date) YearString added in v0.47.0

func (d Date) YearString() string

type Dimensions added in v0.41.0

type Dimensions struct {
	LocaliseKeyName string `json:"localise_key"`
	Count           int    `json:"count"`
	Type            string `json:"string"`
	Query           string `json:"query"`
	ShowInWebUI     bool   `json:"show_in_web_ui"`
}

func GetDimensions added in v0.41.0

func GetDimensions(countResp *searchModels.SearchResponse) (dimensions []Dimensions)

type Filter added in v0.5.0

type Filter struct {
	Query           []string `json:"query,omitempty"`
	LocaliseKeyName []string `json:"localise_key,omitempty"`
}

Filter represents information of filters selected by user

type PopulationTypes added in v0.41.0

type PopulationTypes struct {
	LocaliseKeyName string `json:"localise_key"`
	Count           int    `json:"count"`
	Type            string `json:"string"`
	Query           string `json:"query"`
	ShowInWebUI     bool   `json:"show_in_web_ui"`
}

func GetPopulationTypes added in v0.41.0

func GetPopulationTypes(countResp *searchModels.SearchResponse) (populationTypes []PopulationTypes)

type SearchURLParams added in v0.5.0

type SearchURLParams struct {
	Query                string
	PopulationTypeFilter string
	DimensionsFilter     string
	Filter               Filter
	AfterDate            Date
	BeforeDate           Date
	TopicFilter          string
	LatestRelease        bool
	Sort                 Sort
	Limit                int
	CurrentPage          int
	Offset               int
	NLPWeightingEnabled  bool
	URIPrefix            string
}

SearchURLParams is a struct which contains all information of search url parameters and values

func ReviewDataAggregationQueryWithParams added in v0.53.0

func ReviewDataAggregationQueryWithParams(ctx context.Context, cfg *config.Config, urlQuery url.Values) (sp SearchURLParams, validationErrs []core.ErrorItem)

ReviewDataAggregationQueryWithParams ensures that all search parameter values given by the user are reviewed

func ReviewDatasetQuery added in v0.41.0

func ReviewDatasetQuery(ctx context.Context, cfg *config.Config, urlQuery url.Values, censusTopicCache *cache.Topic) (SearchURLParams, []core.ErrorItem)

ReviewDatasetQuery ensures that all search parameter values given by the user are reviewed

func ReviewPreviousReleasesQueryWithParams added in v0.65.0

func ReviewPreviousReleasesQueryWithParams(ctx context.Context, cfg *config.Config, urlQuery url.Values, urlPath string) (sp SearchURLParams, validationErrs []core.ErrorItem)

ReviewPreviousReleasesQueryWithParams ensures that all search parameter values given by the user are reviewed

func ReviewQuery added in v0.5.0

func ReviewQuery(ctx context.Context, cfg *config.Config, urlQuery url.Values, censusTopicCache *cache.Topic) (sp SearchURLParams, validationErrs []core.ErrorItem)

ReviewQuery ensures that all search parameter values given by the user are reviewed

func ReviewRelatedDataQueryWithParams added in v1.1.0

func ReviewRelatedDataQueryWithParams(ctx context.Context, cfg *config.Config, urlQuery url.Values, urlPath string) (sp SearchURLParams, validationErrs []core.ErrorItem)

ReviewRelatedDataQueryWithParams ensures that all search parameter values given by the user are reviewed

type Sort added in v0.5.0

type Sort struct {
	Query           string `json:"query"`
	LocaliseKeyName string `json:"localise_key"`
}

Sort represents information of a particular sort option

type Subtopic added in v0.34.0

type Subtopic struct {
	Count           int    `json:"count"`
	LocaliseKeyName string `json:"localise_key"`
	Query           string `json:"query"`
	ShowInWebUI     bool   `json:"show_in_web_ui"`
}

Subtopic represents a subtopic filter on the search page

type Topic added in v0.24.0

type Topic struct {
	Count              int        `json:"count"`
	DistinctItemsCount int        `json:"distinct_items_count"`
	LocaliseKeyName    string     `json:"localise_key"`
	Query              string     `json:"query"`
	ShowInWebUI        bool       `json:"show_in_web_ui"`
	Subtopics          []Subtopic `json:"subtopics"`
}

Topic represents a topic filter on the search page

func GetTopics added in v0.34.0

func GetTopics(censusTopicCache *cache.Topic, countResp *searchModels.SearchResponse) []Topic

GetTopicCategories returns the topic filters to be displayed on the search page. Please note that only census topic filter is being returned

Jump to

Keyboard shortcuts

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