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.

88 lines
2.2 KiB

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