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 3.7KB

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