result

package
v0.0.0-...-d7c7285 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitConfig

func InitConfig(c Config)

Types

type Condition

type Condition struct {
	Field    string   `mapstructure:"field"`    // result field name, like title, description,...
	Operator string   `mapstructure:"operator"` // operator, like in, containAny
	Expects  []string `mapstructure:"expects"`  // expect values
}

Condition is to determine whether the search results meet some requirements.

type Config

type Config struct {
	Score  Score                     `mapstructure:"score"`
	Limits map[string]map[string]int `mapstructure:"limits"`
}

type Data

type Data struct {
	Engine    string `json:"engine"`    // Engine is search engine name, means result source.
	Title     string `json:"title"`     // Title is the search result title.
	Url       string `json:"url"`       // Url link to the third party website.
	Content   string `json:"content"`   // Content is a short description.
	ImgSrc    string `json:"img_src"`   // ImgSrc is an image Url, used for poster.
	Thumbnail string `json:"thumbnail"` // Thumbnail Url for some video result.

	// Query is the query of search.
	Query string `json:"-"`
	// contains filtered or unexported fields
}

Data of search result

type InfoBox

type InfoBox struct {
	Title   string              `json:"title"`
	Content string              `json:"content"`
	ImgSrc  string              `json:"img_src"`
	Url     string              `json:"url"`
	UrlList []map[string]string `json:"url_list"`
}

InfoBox of search query from wikipedia(temporary)

type Result

type Result struct {
	MergedData  []*Data   `json:"merged_data"` // MergedData store result from different search engines.
	Suggestions *util.Set `json:"suggestions"` // Suggestions store suggestion from different search engines.
	InfoBox     *InfoBox  `json:"infoBox"`     // InfoBox store information from wikipedia of query

	From   string `json:"-"` // From means the engine name of the search results.
	PageNo int    `json:"-"` // PageNo means the page number of result. PageNo = 1 means first page.
}

Result of search

func CreateResult

func CreateResult(from string, page int) *Result

func (*Result) AppendData

func (r *Result) AppendData(d *Data)

func (*Result) GetDataSize

func (r *Result) GetDataSize() int

func (*Result) GetSortedData

func (r *Result) GetSortedData() []*Data

func (*Result) Merge

func (r *Result) Merge(result *Result)

Merge engine search result

type Rule

type Rule struct {
	Name       string      `mapstructure:"name"`
	Enable     bool        `mapstructure:"enable"`
	Score      int         `mapstructure:"score"`
	Conditions []Condition `mapstructure:"conditions"`
}

Rule is a way that scores search results depends on conditions.

type Score

type Score struct {
	Scorer         string   `mapstructure:"scorer"`
	MetadataFields []string `mapstructure:"metadata_fields"`
	Rules          []Rule   `mapstructure:"rules"`
}

type Scorer

type Scorer func(map[string]string) int

Jump to

Keyboard shortcuts

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