index

package
v0.0.0-...-7b67181 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound is returned by the indexer when attempting to look up
	// a document that does not exist.
	ErrNotFound = errors.New("not found")

	// ErrMissingLinkID is returned when attempting to index a document
	// that does not specify a valid link ID.
	ErrMissingLinkID = errors.New("document does not provide a valid linkID")
)

Functions

This section is empty.

Types

type Document

type Document struct {
	// The ID of the link graph entry that points to this document.
	LinkID uuid.UUID

	// The URL where the document was obtained from.
	URL string

	// The document title (if available).
	Title string

	// The document body
	Content string

	// The last time this document was indexed.
	IndexedAt time.Time

	// The PageRank score assigned to this document.
	PageRank float64
}

Document describes a webpage whose content has been indexed by Links 'R' Us.

type Indexer

type Indexer interface {
	// Index inserts a new document to the index or updates the index entry
	// for and existing document.
	Index(doc *Document) error

	// FindByID looks up a document by its link ID.
	FindByID(linkID uuid.UUID) (*Document, error)

	// Search the index for a particular query and return back a result
	// iterator.
	Search(query Query) (Iterator, error)

	// UpdateScore updates the PageRank score for a document with the
	// specified link ID. If no such document exists, a placeholder
	// document with the provided score will be created.
	UpdateScore(linkID uuid.UUID, score float64) error
}

Indexer is implemented by objects that can index and search documents discovered by the Links 'R' Us crawler.

type Iterator

type Iterator interface {
	// Close the iterator and release any allocated resources.
	Close() error

	// Next loads the next document matching the search query.
	// It returns false if no more documents are available.
	Next() bool

	// Error returns the last error encountered by the iterator.
	Error() error

	// Document returns the current document from the result set.
	Document() *Document

	// TotalCount returns the approximate number of search results.
	TotalCount() uint64
}

Iterator is implemented by objects that can paginate search results.

type Query

type Query struct {
	// The way that the indexer should interpret the search expression.
	Type QueryType

	// The search expression.
	Expression string

	// The number of search results to skip.
	Offset uint64
}

Query encapsulates a set of parameters to use when searching indexed documents.

type QueryType

type QueryType uint8

QueryType describes the types of queries supported by the indexer implementations.

const (
	// QueryTypeMatch requests the indexer to match each expression term.
	QueryTypeMatch QueryType = iota

	// QueryTypePhrase searches for an exact phrase match.
	QueryTypePhrase
)

Directories

Path Synopsis
mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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