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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 TermDictionary interface {
  39. PostingsList(term []byte, except *roaring.Bitmap, prealloc PostingsList) (PostingsList, error)
  40. Iterator() DictionaryIterator
  41. PrefixIterator(prefix string) DictionaryIterator
  42. RangeIterator(start, end string) DictionaryIterator
  43. AutomatonIterator(a vellum.Automaton,
  44. startKeyInclusive, endKeyExclusive []byte) DictionaryIterator
  45. OnlyIterator(onlyTerms [][]byte, includeCount bool) DictionaryIterator
  46. Contains(key []byte) (bool, error)
  47. }
  48. type DictionaryIterator interface {
  49. Next() (*index.DictEntry, error)
  50. }
  51. type PostingsList interface {
  52. Iterator(includeFreq, includeNorm, includeLocations bool, prealloc PostingsIterator) PostingsIterator
  53. Size() int
  54. Count() uint64
  55. // NOTE deferred for future work
  56. // And(other PostingsList) PostingsList
  57. // Or(other PostingsList) PostingsList
  58. }
  59. type PostingsIterator interface {
  60. // The caller is responsible for copying whatever it needs from
  61. // the returned Posting instance before calling Next(), as some
  62. // implementations may return a shared instance to reduce memory
  63. // allocations.
  64. Next() (Posting, error)
  65. // Advance will return the posting with the specified doc number
  66. // or if there is no such posting, the next posting.
  67. // Callers MUST NOT attempt to pass a docNum that is less than or
  68. // equal to the currently visited posting doc Num.
  69. Advance(docNum uint64) (Posting, error)
  70. Size() int
  71. }
  72. type Posting interface {
  73. Number() uint64
  74. Frequency() uint64
  75. Norm() float64
  76. Locations() []Location
  77. Size() int
  78. }
  79. type Location interface {
  80. Field() string
  81. Start() uint64
  82. End() uint64
  83. Pos() uint64
  84. ArrayPositions() []uint64
  85. Size() int
  86. }
  87. // DocumentFieldTermVisitable is implemented by various scorch segment
  88. // implementations with persistence for the un inverting of the
  89. // postings or other indexed values.
  90. type DocumentFieldTermVisitable interface {
  91. VisitDocumentFieldTerms(localDocNum uint64, fields []string,
  92. visitor index.DocumentFieldTermVisitor, optional DocVisitState) (DocVisitState, error)
  93. // VisitableDocValueFields implementation should return
  94. // the list of fields which are document value persisted and
  95. // therefore visitable by the above VisitDocumentFieldTerms method.
  96. VisitableDocValueFields() ([]string, error)
  97. }
  98. type DocVisitState interface {
  99. }
  100. type StatsReporter interface {
  101. ReportBytesWritten(bytesWritten uint64)
  102. }