示例#1
0
// Setup creates a new middleware with the given configuration
func Setup(c *caddy.Controller) (err error) {
	cfg := httpserver.GetConfig(c)
	var config *Config

	config, err = ParseSearchConfig(c, cfg)
	if err != nil {
		return err
	}

	index, err := NewIndexer(config.Engine, indexer.Config{
		HostName:       config.HostName,
		IndexDirectory: config.IndexDirectory,
	})

	if err != nil {
		return err
	}

	ppl, err := NewPipeline(config, index)

	if err != nil {
		return err
	}

	expire := time.NewTicker(config.Expire)
	go func() {
		var lastScanned indexer.Record
		lastScanned = ScanToPipe(config.SiteRoot, ppl, index)

		for {
			select {
			case <-expire.C:
				if lastScanned != nil && (!lastScanned.Indexed().IsZero() || lastScanned.Ignored()) {
					lastScanned = ScanToPipe(config.SiteRoot, ppl, index)
				}
			}
		}
	}()

	search := &Search{
		Config:   config,
		Indexer:  index,
		Pipeline: ppl,
	}

	cfg.AddMiddleware(func(next httpserver.Handler) httpserver.Handler {
		search.Next = next
		return search
	})

	return
}
示例#2
0
func (i *bleveIndexer) Kill(r indexer.Record) {
	bufPool.Put(r.Body())
	recordPool.Put(r)
}