You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
2.3KB

  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. package bleve
  15. import (
  16. "expvar"
  17. "io/ioutil"
  18. "log"
  19. "time"
  20. "github.com/blevesearch/bleve/index"
  21. "github.com/blevesearch/bleve/index/store/gtreap"
  22. "github.com/blevesearch/bleve/index/upsidedown"
  23. "github.com/blevesearch/bleve/registry"
  24. "github.com/blevesearch/bleve/search/highlight/highlighter/html"
  25. // force import of scorch so its accessible by default
  26. _ "github.com/blevesearch/bleve/index/scorch"
  27. )
  28. var bleveExpVar = expvar.NewMap("bleve")
  29. type configuration struct {
  30. Cache *registry.Cache
  31. DefaultHighlighter string
  32. DefaultKVStore string
  33. DefaultMemKVStore string
  34. DefaultIndexType string
  35. SlowSearchLogThreshold time.Duration
  36. analysisQueue *index.AnalysisQueue
  37. }
  38. func (c *configuration) SetAnalysisQueueSize(n int) {
  39. c.analysisQueue = index.NewAnalysisQueue(n)
  40. }
  41. func newConfiguration() *configuration {
  42. return &configuration{
  43. Cache: registry.NewCache(),
  44. analysisQueue: index.NewAnalysisQueue(4),
  45. }
  46. }
  47. // Config contains library level configuration
  48. var Config *configuration
  49. func init() {
  50. bootStart := time.Now()
  51. // build the default configuration
  52. Config = newConfiguration()
  53. // set the default highlighter
  54. Config.DefaultHighlighter = html.Name
  55. // default kv store
  56. Config.DefaultKVStore = ""
  57. // default mem only kv store
  58. Config.DefaultMemKVStore = gtreap.Name
  59. // default index
  60. Config.DefaultIndexType = upsidedown.Name
  61. bootDuration := time.Since(bootStart)
  62. bleveExpVar.Add("bootDuration", int64(bootDuration))
  63. indexStats = NewIndexStats()
  64. bleveExpVar.Set("indexes", indexStats)
  65. initDisk()
  66. }
  67. var logger = log.New(ioutil.Discard, "bleve", log.LstdFlags)
  68. // SetLog sets the logger used for logging
  69. // by default log messages are sent to ioutil.Discard
  70. func SetLog(l *log.Logger) {
  71. logger = l
  72. }