2014-07-30 18:30:38 +02:00
|
|
|
// Copyright (c) 2014 Couchbase, Inc.
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
// except in compliance with the License. You may obtain a copy of the License at
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
// Unless required by applicable law or agreed to in writing, software distributed under the
|
|
|
|
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
|
|
|
// either express or implied. See the License for the specific language governing permissions
|
|
|
|
// and limitations under the License.
|
2014-08-29 20:18:36 +02:00
|
|
|
|
2014-07-30 18:30:38 +02:00
|
|
|
package bleve
|
|
|
|
|
|
|
|
import (
|
2014-08-14 03:14:47 +02:00
|
|
|
"expvar"
|
2014-12-28 21:14:48 +01:00
|
|
|
"io/ioutil"
|
|
|
|
"log"
|
2014-08-03 23:19:04 +02:00
|
|
|
"time"
|
2014-07-30 18:30:38 +02:00
|
|
|
|
2015-09-02 19:12:08 +02:00
|
|
|
"github.com/blevesearch/bleve/index"
|
2015-09-16 23:10:59 +02:00
|
|
|
"github.com/blevesearch/bleve/index/store/boltdb"
|
|
|
|
"github.com/blevesearch/bleve/index/upside_down"
|
2014-09-24 14:13:14 +02:00
|
|
|
"github.com/blevesearch/bleve/registry"
|
2015-09-16 23:10:59 +02:00
|
|
|
"github.com/blevesearch/bleve/search/highlight/highlighters/html"
|
2014-07-30 18:30:38 +02:00
|
|
|
)
|
|
|
|
|
2014-08-14 03:14:47 +02:00
|
|
|
var bleveExpVar = expvar.NewMap("bleve")
|
2014-07-30 18:30:38 +02:00
|
|
|
|
2014-08-29 21:32:36 +02:00
|
|
|
type configuration struct {
|
2014-12-29 04:34:16 +01:00
|
|
|
Cache *registry.Cache
|
|
|
|
DefaultHighlighter string
|
|
|
|
DefaultKVStore string
|
2015-09-02 19:12:08 +02:00
|
|
|
DefaultIndexType string
|
2014-12-29 04:34:16 +01:00
|
|
|
SlowSearchLogThreshold time.Duration
|
2015-09-02 19:12:08 +02:00
|
|
|
analysisQueue *index.AnalysisQueue
|
2014-07-30 18:30:38 +02:00
|
|
|
}
|
|
|
|
|
2015-09-02 17:55:30 +02:00
|
|
|
func (c *configuration) SetAnalysisQueueSize(n int) {
|
2015-09-02 19:12:08 +02:00
|
|
|
c.analysisQueue = index.NewAnalysisQueue(n)
|
2015-09-02 17:55:30 +02:00
|
|
|
}
|
|
|
|
|
2014-08-29 21:32:36 +02:00
|
|
|
func newConfiguration() *configuration {
|
|
|
|
return &configuration{
|
2014-09-24 14:13:14 +02:00
|
|
|
Cache: registry.NewCache(),
|
2015-09-02 19:12:08 +02:00
|
|
|
analysisQueue: index.NewAnalysisQueue(4),
|
2014-07-30 18:30:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-31 16:55:22 +02:00
|
|
|
// Config contains library level configuration
|
2014-08-29 21:32:36 +02:00
|
|
|
var Config *configuration
|
2014-07-30 18:30:38 +02:00
|
|
|
|
|
|
|
func init() {
|
2014-08-14 03:14:47 +02:00
|
|
|
bootStart := time.Now()
|
2014-07-30 18:30:38 +02:00
|
|
|
|
|
|
|
// build the default configuration
|
2014-08-29 21:32:36 +02:00
|
|
|
Config = newConfiguration()
|
2014-07-30 18:30:38 +02:00
|
|
|
|
|
|
|
// set the default highlighter
|
2015-09-16 23:10:59 +02:00
|
|
|
Config.DefaultHighlighter = html.Name
|
2014-07-30 18:30:38 +02:00
|
|
|
|
2014-08-20 22:58:20 +02:00
|
|
|
// default kv store
|
2015-09-16 23:10:59 +02:00
|
|
|
Config.DefaultKVStore = boltdb.Name
|
2014-08-03 23:19:04 +02:00
|
|
|
|
2015-09-02 19:12:08 +02:00
|
|
|
// default index
|
2015-09-16 23:10:59 +02:00
|
|
|
Config.DefaultIndexType = upside_down.Name
|
2015-09-02 19:12:08 +02:00
|
|
|
|
2014-08-14 03:14:47 +02:00
|
|
|
bootDuration := time.Since(bootStart)
|
|
|
|
bleveExpVar.Add("bootDuration", int64(bootDuration))
|
2014-07-30 18:30:38 +02:00
|
|
|
}
|
2014-12-28 21:14:48 +01:00
|
|
|
|
|
|
|
var logger = log.New(ioutil.Discard, "bleve", log.LstdFlags)
|
|
|
|
|
|
|
|
// SetLog sets the logger used for logging
|
|
|
|
// by default log messages are sent to ioutil.Discard
|
2014-12-29 04:34:16 +01:00
|
|
|
func SetLog(l *log.Logger) {
|
|
|
|
logger = l
|
2014-12-28 21:14:48 +01:00
|
|
|
}
|