models

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const DocumentEntityName = "Document"

DocumentEntityName is used to represent documents in storage.

Variables

This section is empty.

Functions

This section is empty.

Types

type Document

type Document struct {
	Key       string   `gorm:"primaryKey"`
	Name      string   // The name of the resource.
	Fragment  string   // The path to the fragment of the resource, possibly empty.
	Kind      string   // The type of the resource.
	Field     Field    // The field of the resource or type of the fragment, if appropriate.
	ProjectID string   // The project associated with the document and resource.
	Vector    TSVector // A Text Search Vector of the indexed text.
	Raw       string   // The raw indexed text for excerpting; has excerpt from search result.
	Escaped   bool     // If true, the raw text is escaped.
}

A document is an item stored in the search index that is a potential search result. A documents is typically a resource or part of a resource and when so, has a resource path and a possible path into the resource to the resource fragment corresponding to the document. Such a fragment might be an API operation or schema.

Documents have associated text that is used to index them. This text is derived from properties of the resource and is stored in two forms: a "vector" version that is created with the Postgres ts_vector function, and raw text that can be presented with the results of search queries. This raw text can be highlighted to show search terms.

The key of the document is derived from the resource name and the path to the resource fragment, when appropriate.

func (*Document) Escape

func (x *Document) Escape() *Document

Escape should be called after filling struct to HTML-escape the raw text in the Vector, and also then copies it to Raw.

func (*Document) IsEmpty

func (x *Document) IsEmpty() bool

IsEmpty determines whether an update should write or delete the Document.

type Field

type Field string
const (
	FieldDisplayName Field = "displayname"
	FieldDescription Field = "description"
	FieldParameters  Field = "parameters"
	FieldMethods     Field = "methods"
	FieldSchemas     Field = "schemas"
)

type TSVector

type TSVector struct {
	RawText string
	Weight  Weight
}

TSVector opaquely represents the write-only ts_vector, containing the should-be-escaped text to index and the search weight.

func (TSVector) GormDataType

func (t TSVector) GormDataType() string

GormDataType of TSVector is the Postgres column type "tsvector",

func (TSVector) GormValue

func (t TSVector) GormValue(ctx context.Context, db *gorm.DB) clause.Expr

GormValue of TSVector returns the Postgres expression to convert search text to a weighted vector.

func (*TSVector) Scan

func (t *TSVector) Scan(v interface{}) error

Scan implements the sql.Scanner interface

type Weight

type Weight string
const (
	WeightA Weight = "A"
	WeightB Weight = "B"
	WeightC Weight = "C"
	WeightD Weight = "D"
)

Jump to

Keyboard shortcuts

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