hugo: github.com/gohugoio/hugo/related Index | Files

package related

import "github.com/gohugoio/hugo/related"

Package related holds code to help finding related content.

Index

Package Files

inverted_index.go

Variables

var (

    // DefaultConfig is the default related config.
    DefaultConfig = Config{
        Threshold: 80,
        Indices: IndexConfigs{
            IndexConfig{Name: "keywords", Weight: 100},
            IndexConfig{Name: "date", Weight: 10},
        },
    }
)

type Config Uses

type Config struct {
    // Only include matches >= threshold, a normalized rank between 0 and 100.
    Threshold int

    // To get stable "See also" sections we, by default, exclude newer related pages.
    IncludeNewer bool

    // Will lower case all string values and queries to the indices.
    // May get better results, but at a slight performance cost.
    ToLower bool

    Indices IndexConfigs
}

Config is the top level configuration element used to configure how to retrieve related content in Hugo.

An example site config.toml:

[related]
threshold = 1
[[related.indices]]
name = "keywords"
weight = 200
[[related.indices]]
name  = "tags"
weight = 100
[[related.indices]]
name  = "date"
weight = 1
pattern = "2006"

func DecodeConfig Uses

func DecodeConfig(in interface{}) (Config, error)

DecodeConfig decodes a slice of map into Config.

func (*Config) Add Uses

func (c *Config) Add(index IndexConfig)

Add adds a given index.

type Document Uses

type Document interface {
    // RelatedKeywords returns a list of keywords for the given index config.
    RelatedKeywords(cfg IndexConfig) ([]Keyword, error)

    // When this document was or will be published.
    PublishDate() time.Time

    // Name is used as an tiebreaker if both Weight and PublishDate are
    // the same.
    Name() string
}

Document is the interface an indexable document in Hugo must fulfill.

type IndexConfig Uses

type IndexConfig struct {
    // The index name. This directly maps to a field or Param name.
    Name string

    // Contextual pattern used to convert the Param value into a string.
    // Currently only used for dates. Can be used to, say, bump posts in the same
    // time frame when searching for related documents.
    // For dates it follows Go's time.Format patterns, i.e.
    // "2006" for YYYY and "200601" for YYYYMM.
    Pattern string

    // This field's weight when doing multi-index searches. Higher is "better".
    Weight int

    // Will lower case all string values in and queries tothis index.
    // May get better accurate results, but at a slight performance cost.
    ToLower bool
}

IndexConfig configures an index.

func (IndexConfig) ToKeywords Uses

func (cfg IndexConfig) ToKeywords(v interface{}) ([]Keyword, error)

ToKeywords returns a Keyword slice of the given input.

type IndexConfigs Uses

type IndexConfigs []IndexConfig

IndexConfigs holds a set of index configurations.

type InvertedIndex Uses

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

InvertedIndex holds an inverted index, also sometimes named posting list, which lists, for every possible search term, the documents that contain that term.

func NewInvertedIndex Uses

func NewInvertedIndex(cfg Config) *InvertedIndex

NewInvertedIndex creates a new InvertedIndex. Documents to index must be added in Add.

func (*InvertedIndex) Add Uses

func (idx *InvertedIndex) Add(docs ...Document) error

Add documents to the inverted index. The value must support == and !=.

func (*InvertedIndex) SearchDoc Uses

func (idx *InvertedIndex) SearchDoc(doc Document, indices ...string) ([]Document, error)

SearchDoc finds the documents matching any of the keywords in the given indices against the given document. The resulting document set will be sorted according to number of matches and the index weights, and any matches with a rank below the configured threshold (normalize to 0..100) will be removed. If an index name is provided, only that index will be queried.

func (*InvertedIndex) SearchKeyValues Uses

func (idx *InvertedIndex) SearchKeyValues(args ...types.KeyValues) ([]Document, error)

SearchKeyValues finds the documents matching any of the keywords in the given indices. The resulting document set will be sorted according to number of matches and the index weights, and any matches with a rank below the configured threshold (normalize to 0..100) will be removed.

type Keyword Uses

type Keyword interface {
    String() string
}

Keyword is the interface a keyword in the search index must implement.

func StringsToKeywords Uses

func StringsToKeywords(s ...string) []Keyword

StringsToKeywords converts the given slice of strings to a slice of Keyword.

type StringKeyword Uses

type StringKeyword string

StringKeyword is a string search keyword.

func (StringKeyword) String Uses

func (s StringKeyword) String() string

Package related imports 8 packages (graph) and is imported by 49 packages. Updated 2019-08-12. Refresh now. Tools for package owners.