1//  Copyright (c) 2014 Couchbase, Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// 		http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package bleve
16
17import (
18	"expvar"
19	"io/ioutil"
20	"log"
21	"time"
22
23	"github.com/blevesearch/bleve/index"
24	"github.com/blevesearch/bleve/index/store/gtreap"
25	"github.com/blevesearch/bleve/index/upsidedown"
26	"github.com/blevesearch/bleve/registry"
27	"github.com/blevesearch/bleve/search/highlight/highlighter/html"
28
29	// force import of scorch so its accessible by default
30	_ "github.com/blevesearch/bleve/index/scorch"
31)
32
33var bleveExpVar = expvar.NewMap("bleve")
34
35type configuration struct {
36	Cache                  *registry.Cache
37	DefaultHighlighter     string
38	DefaultKVStore         string
39	DefaultMemKVStore      string
40	DefaultIndexType       string
41	SlowSearchLogThreshold time.Duration
42	analysisQueue          *index.AnalysisQueue
43}
44
45func (c *configuration) SetAnalysisQueueSize(n int) {
46	c.analysisQueue = index.NewAnalysisQueue(n)
47}
48
49func newConfiguration() *configuration {
50	return &configuration{
51		Cache:         registry.NewCache(),
52		analysisQueue: index.NewAnalysisQueue(4),
53	}
54}
55
56// Config contains library level configuration
57var Config *configuration
58
59func init() {
60	bootStart := time.Now()
61
62	// build the default configuration
63	Config = newConfiguration()
64
65	// set the default highlighter
66	Config.DefaultHighlighter = html.Name
67
68	// default kv store
69	Config.DefaultKVStore = ""
70
71	// default mem only kv store
72	Config.DefaultMemKVStore = gtreap.Name
73
74	// default index
75	Config.DefaultIndexType = upsidedown.Name
76
77	bootDuration := time.Since(bootStart)
78	bleveExpVar.Add("bootDuration", int64(bootDuration))
79	indexStats = NewIndexStats()
80	bleveExpVar.Set("indexes", indexStats)
81
82	initDisk()
83}
84
85var logger = log.New(ioutil.Discard, "bleve", log.LstdFlags)
86
87// SetLog sets the logger used for logging
88// by default log messages are sent to ioutil.Discard
89func SetLog(l *log.Logger) {
90	logger = l
91}
92