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.

segment.go 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. // Copyright (c) 2017 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 segment
  15. import (
  16. "fmt"
  17. "github.com/RoaringBitmap/roaring"
  18. "github.com/blevesearch/bleve/index"
  19. "github.com/couchbase/vellum"
  20. )
  21. var ErrClosed = fmt.Errorf("index closed")
  22. // DocumentFieldValueVisitor defines a callback to be visited for each
  23. // stored field value. The return value determines if the visitor
  24. // should keep going. Returning true continues visiting, false stops.
  25. type DocumentFieldValueVisitor func(field string, typ byte, value []byte, pos []uint64) bool
  26. type Segment interface {
  27. Dictionary(field string) (TermDictionary, error)
  28. VisitDocument(num uint64, visitor DocumentFieldValueVisitor) error
  29. DocID(num uint64) ([]byte, error)
  30. Count() uint64
  31. DocNumbers([]string) (*roaring.Bitmap, error)
  32. Fields() []string
  33. Close() error
  34. Size() int
  35. AddRef()
  36. DecRef() error
  37. }
  38. type UnpersistedSegment interface {
  39. Segment
  40. Persist(path string) error
  41. }
  42. type PersistedSegment interface {
  43. Segment
  44. Path() string
  45. }
  46. type TermDictionary interface {
  47. PostingsList(term []byte, except *roaring.Bitmap, prealloc PostingsList) (PostingsList, error)
  48. Iterator() DictionaryIterator
  49. PrefixIterator(prefix string) DictionaryIterator
  50. RangeIterator(start, end string) DictionaryIterator
  51. AutomatonIterator(a vellum.Automaton,
  52. startKeyInclusive, endKeyExclusive []byte) DictionaryIterator
  53. OnlyIterator(onlyTerms [][]byte, includeCount bool) DictionaryIterator
  54. Contains(key []byte) (bool, error)
  55. }
  56. type DictionaryIterator interface {
  57. Next() (*index.DictEntry, error)
  58. }
  59. type PostingsList interface {
  60. Iterator(includeFreq, includeNorm, includeLocations bool, prealloc PostingsIterator) PostingsIterator
  61. Size() int
  62. Count() uint64
  63. // NOTE deferred for future work
  64. // And(other PostingsList) PostingsList
  65. // Or(other PostingsList) PostingsList
  66. }
  67. type PostingsIterator interface {
  68. // The caller is responsible for copying whatever it needs from
  69. // the returned Posting instance before calling Next(), as some
  70. // implementations may return a shared instance to reduce memory
  71. // allocations.
  72. Next() (Posting, error)
  73. // Advance will return the posting with the specified doc number
  74. // or if there is no such posting, the next posting.
  75. // Callers MUST NOT attempt to pass a docNum that is less than or
  76. // equal to the currently visited posting doc Num.
  77. Advance(docNum uint64) (Posting, error)
  78. Size() int
  79. }
  80. type OptimizablePostingsIterator interface {
  81. ActualBitmap() *roaring.Bitmap
  82. DocNum1Hit() (uint64, bool)
  83. ReplaceActual(*roaring.Bitmap)
  84. }
  85. type Posting interface {
  86. Number() uint64
  87. Frequency() uint64
  88. Norm() float64
  89. Locations() []Location
  90. Size() int
  91. }
  92. type Location interface {
  93. Field() string
  94. Start() uint64
  95. End() uint64
  96. Pos() uint64
  97. ArrayPositions() []uint64
  98. Size() int
  99. }
  100. // DocumentFieldTermVisitable is implemented by various scorch segment
  101. // implementations with persistence for the un inverting of the
  102. // postings or other indexed values.
  103. type DocumentFieldTermVisitable interface {
  104. VisitDocumentFieldTerms(localDocNum uint64, fields []string,
  105. visitor index.DocumentFieldTermVisitor, optional DocVisitState) (DocVisitState, error)
  106. // VisitableDocValueFields implementation should return
  107. // the list of fields which are document value persisted and
  108. // therefore visitable by the above VisitDocumentFieldTerms method.
  109. VisitableDocValueFields() ([]string, error)
  110. }
  111. type DocVisitState interface {
  112. }
  113. type StatsReporter interface {
  114. ReportBytesWritten(bytesWritten uint64)
  115. }