search

package module
Version: v0.0.0-...-ee7e7c1 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2016 License: MIT Imports: 21 Imported by: 0

README

Middleware for Caddy.

search indexes your static and/or dynamic documents then serves a HTTP search endpoint.

Syntax
search [directory|regexp] [endpoint "search/"]
  • directory is the path, relative to site root, to a directory (static content)
  • regexp is the URL [regular expression] of documents that must be indexed (static and dynamic content)
  • endpoint is the path, relative to site's root url, of the search endpoint

For more options, use the following syntax:

search {
    engine      (default: bleve)
    datadir     (default: /tmp/caddyIndex)
    endpoint    (default: /search)
    template    (default: nil)
    expire      (default: 60)

    +path       regexp
    -path       regexp
}
  • engine is the engine for indexing and searching
  • datadir is the absolute path to where the indexer should store all data
  • template is the path to the search's HTML result's template
  • expire is the duration (in seconds) until a indexed document validation expires (should be updated)
  • +path include a path to be indexed (can be added multiple times)
  • -path exclude a path from being index (can be added multiple times)

Each property in the block is optional.

Supported Engines
Examples

Index every static content in root folder (single line configuration)

search /

Index every content (single line configuration)

search ^/

Indexing every dynamic content with a different endpoint (single line configuration)

search /(.*) /mySearch

Ignoring specific type of file

search {
    -path \.pdf$
}

Multiple static and dynamic paths

search ^/blog/ {
	+path /static/docs/
    -path ^/blog/admin/
    -path robots.txt
}

Different directory for storing the index

search {
	datadir /tmp/index
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertToRegExp

func ConvertToRegExp(rexp []string) (r []*regexp.Regexp)

ConvertToRegExp compile a string regular expression to multiple *regexp.Regexp instances

func NewIndexer

func NewIndexer(engine string, config indexer.Config) (index indexer.Handler, err error)

NewIndexer creates a new Indexer with the received config

func ScanToPipe

func ScanToPipe(fp string, pipeline *Pipeline, index indexer.Handler) indexer.Record

ScanToPipe ...

func Setup

func Setup(c *caddy.Controller) (err error)

Setup creates a new middleware with the given configuration

Types

type Config

type Config struct {
	HostName       string
	Engine         string
	Path           string
	IncludePaths   []*regexp.Regexp
	ExcludePaths   []*regexp.Regexp
	Endpoint       string
	IndexDirectory string
	Template       *template.Template
	Expire         time.Duration
	SiteRoot       string
}

Config represents this middleware configuration structure

func ParseSearchConfig

func ParseSearchConfig(c *caddy.Controller, cnf *httpserver.SiteConfig) (*Config, error)

ParseSearchConfig controller information to create a IndexSearch config

type Pipeline

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

Pipeline is the structure that holds search's pipeline infos and methods

func NewPipeline

func NewPipeline(config *Config, indxr indexer.Handler) (*Pipeline, error)

NewPipeline creates a new Pipeline instance

func (*Pipeline) Pipe

func (p *Pipeline) Pipe(record indexer.Record)

Pipe is the step of the pipeline that pipes valid documents to the indexer.

func (*Pipeline) Piper

func (p *Pipeline) Piper() piper.Handler

Piper is a func that returns the piper.Handler

func (*Pipeline) ValidatePath

func (p *Pipeline) ValidatePath(path string) bool

ValidatePath is the method that checks if the target page can be indexed

type QueryResults

type QueryResults struct {
	httpserver.Context
	Query   string
	Results []Result
}

type Result

type Result struct {
	Path     string
	Title    string
	Body     string
	Modified time.Time
	Indexed  time.Time
}

Result is the structure for the search result

type Search struct {
	Next httpserver.Handler
	*Config
	Indexer indexer.Handler
	*Pipeline
}

Search represents this middleware structure

func (*Search) SearchHTML

func (s *Search) SearchHTML(w http.ResponseWriter, r *http.Request) (int, error)

SearchHTML renders the search results in the HTML template

func (*Search) SearchJSON

func (s *Search) SearchJSON(w http.ResponseWriter, r *http.Request) (int, error)

SearchJSON renders the search results in JSON format

func (*Search) ServeHTTP

func (s *Search) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error)

ServerHTTP is the HTTP handler for this middleware

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL