wikipedia

package module
v0.0.0-...-eb17f3f Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2021 License: BSD-3-Clause Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const EntryTemplate = `` /* 747-byte string literal not displayed */

EntryTemplate is a entry page

View Source
const IndexPage = `` /* 255-byte string literal not displayed */

IndexPage is the index page

View Source
const ResultsTemplate = `` /* 227-byte string literal not displayed */

ResultsTemplate is the template for search results

Variables

View Source
var (
	// WikiRegex is a regex for wiki syntax
	WikiRegex = regexp.MustCompile("[^A-Za-z]+")
	// NumCPU is the number of CPUs
	NumCPU = runtime.NumCPU()
)
View Source
var File_wikipedia_proto protoreflect.FileDescriptor

Functions

func Build

func Build()

Build builds the db

func Compress

func Compress(input []byte, output io.Writer)

Compress compresses some data

func Decompress

func Decompress(input io.Reader, output []byte)

Decompress decompresses some data

func Interface

func Interface(w http.ResponseWriter, r *http.Request, ps httprouter.Params)

Interface outputs the search interface

func Pretty

func Pretty(pretty bool) func(*Wikipedia) error

func Rank

func Rank()

Rank ranks the pages

func Server

func Server(encyclopedia *Encyclopedia, router *httprouter.Router)

Server start server mode

func Size

func Size(size int) func(*Wikipedia) error

func WikiTextToHTML

func WikiTextToHTML(input string) string

WikiTextToHTML converts wikitext to html

Types

type Article

type Article struct {
	Title string `protobuf:"bytes,1,opt,name=Title,proto3" json:"Title,omitempty"`
	ID    uint64 `protobuf:"varint,2,opt,name=ID,proto3" json:"ID,omitempty"`
	Text  string `protobuf:"bytes,3,opt,name=Text,proto3" json:"Text,omitempty"`
	// contains filtered or unexported fields
}

func (*Article) Descriptor deprecated

func (*Article) Descriptor() ([]byte, []int)

Deprecated: Use Article.ProtoReflect.Descriptor instead.

func (*Article) GetID

func (x *Article) GetID() uint64

func (*Article) GetText

func (x *Article) GetText() string

func (*Article) GetTitle

func (x *Article) GetTitle() string

func (*Article) HTML

func (a *Article) HTML() string

HTML returns the HTML version of the article

func (*Article) ProtoMessage

func (*Article) ProtoMessage()

func (*Article) ProtoReflect

func (x *Article) ProtoReflect() protoreflect.Message

func (*Article) Reset

func (x *Article) Reset()

func (*Article) String

func (x *Article) String() string

type Compressed

type Compressed struct {
	Size uint64 `protobuf:"varint,1,opt,name=size,proto3" json:"size,omitempty"`
	Data []byte `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"`
	// contains filtered or unexported fields
}

func (*Compressed) Descriptor deprecated

func (*Compressed) Descriptor() ([]byte, []int)

Deprecated: Use Compressed.ProtoReflect.Descriptor instead.

func (*Compressed) GetData

func (x *Compressed) GetData() []byte

func (*Compressed) GetSize

func (x *Compressed) GetSize() uint64

func (*Compressed) ProtoMessage

func (*Compressed) ProtoMessage()

func (*Compressed) ProtoReflect

func (x *Compressed) ProtoReflect() protoreflect.Message

func (*Compressed) Reset

func (x *Compressed) Reset()

func (*Compressed) String

func (x *Compressed) String() string

type Encyclopedia

type Encyclopedia struct {
	DB *bolt.DB
	// contains filtered or unexported fields
}

Encyclopedia is an encyclopedia

func Open

func Open(readonly bool) (*Encyclopedia, error)

Open opens an encyclopedia

func (*Encyclopedia) Article

Article is the endpoint for view an article

func (*Encyclopedia) Lookup

func (e *Encyclopedia) Lookup(title string) (article *Article)

Lookup looks up an article

func (*Encyclopedia) Search

func (e *Encyclopedia) Search(query string) []Result

Search search for a page

func (*Encyclopedia) WikiSearch

func (e *Encyclopedia) WikiSearch(w http.ResponseWriter, r *http.Request, ps httprouter.Params)

WikiSearch searches for articles

type Index

type Index struct {
	Indexes []uint32 `protobuf:"varint,1,rep,packed,name=indexes,proto3" json:"indexes,omitempty"`
	// contains filtered or unexported fields
}

func (*Index) Descriptor deprecated

func (*Index) Descriptor() ([]byte, []int)

Deprecated: Use Index.ProtoReflect.Descriptor instead.

func (*Index) GetIndexes

func (x *Index) GetIndexes() []uint32

func (*Index) ProtoMessage

func (*Index) ProtoMessage()

func (*Index) ProtoReflect

func (x *Index) ProtoReflect() protoreflect.Message

func (*Index) Reset

func (x *Index) Reset()

func (*Index) String

func (x *Index) String() string

type LRU

type LRU struct {
	Size       int
	Head, Tail *Node
	Nodes      map[string]*Node
}

LRU is a least recently used cache

func NewLRU

func NewLRU(size uint) LRU

NewLRU creates a new LRU cache

func (*LRU) Flush

func (l *LRU) Flush() *Node

Flush flush the oldest entries in the cache

func (*LRU) Get

func (l *LRU) Get(key string) (*Node, bool)

Get gets an entry and sets it as the most recent

type Node

type Node struct {
	F, B  *Node
	Index []uint32
	Key   string
	Seen  bool
}

Node is an entry in the LRU cache

type Page

type Page struct {
	Title string `xml:"title"`
	ID    uint64 `xml:"id"`
	Text  string `xml:"revision>text"`
}

Page is a wikitext page

type Result

type Result struct {
	Index   uint32
	Count   int
	Rank    float32
	Article *Article
	Matches int
}

Result is a search result

type Wikipedia

type Wikipedia struct {
	Buffer string

	Pretty bool
	// contains filtered or unexported fields
}

func (*Wikipedia) AST

func (t *Wikipedia) AST() *node32

func (*Wikipedia) Add

func (t *Wikipedia) Add(rule pegRule, begin, end, index uint32)

func (*Wikipedia) Init

func (p *Wikipedia) Init(options ...func(*Wikipedia) error) error

func (*Wikipedia) Parse

func (p *Wikipedia) Parse(rule ...int) error

func (*Wikipedia) PrettyPrintSyntaxTree

func (t *Wikipedia) PrettyPrintSyntaxTree(buffer string)

func (*Wikipedia) Print

func (t *Wikipedia) Print()

func (*Wikipedia) PrintSyntaxTree

func (p *Wikipedia) PrintSyntaxTree()

func (*Wikipedia) Reset

func (p *Wikipedia) Reset()

func (*Wikipedia) SprintSyntaxTree

func (p *Wikipedia) SprintSyntaxTree() string

func (*Wikipedia) Tokens

func (t *Wikipedia) Tokens() []token32

func (*Wikipedia) Trim

func (t *Wikipedia) Trim(length uint32)

func (*Wikipedia) WriteSyntaxTree

func (p *Wikipedia) WriteSyntaxTree(w io.Writer)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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