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.

empty.go 3.2KB

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. "github.com/RoaringBitmap/roaring"
  17. "github.com/blevesearch/bleve/index"
  18. "github.com/couchbase/vellum"
  19. )
  20. type EmptySegment struct{}
  21. func (e *EmptySegment) Dictionary(field string) (TermDictionary, error) {
  22. return &EmptyDictionary{}, nil
  23. }
  24. func (e *EmptySegment) VisitDocument(num uint64, visitor DocumentFieldValueVisitor) error {
  25. return nil
  26. }
  27. func (e *EmptySegment) DocID(num uint64) ([]byte, error) {
  28. return nil, nil
  29. }
  30. func (e *EmptySegment) Count() uint64 {
  31. return 0
  32. }
  33. func (e *EmptySegment) DocNumbers([]string) (*roaring.Bitmap, error) {
  34. r := roaring.NewBitmap()
  35. return r, nil
  36. }
  37. func (e *EmptySegment) Fields() []string {
  38. return []string{}
  39. }
  40. func (e *EmptySegment) Close() error {
  41. return nil
  42. }
  43. func (e *EmptySegment) Size() uint64 {
  44. return 0
  45. }
  46. func (e *EmptySegment) AddRef() {
  47. }
  48. func (e *EmptySegment) DecRef() error {
  49. return nil
  50. }
  51. type EmptyDictionary struct{}
  52. func (e *EmptyDictionary) PostingsList(term []byte,
  53. except *roaring.Bitmap, prealloc PostingsList) (PostingsList, error) {
  54. return &EmptyPostingsList{}, nil
  55. }
  56. func (e *EmptyDictionary) Iterator() DictionaryIterator {
  57. return &EmptyDictionaryIterator{}
  58. }
  59. func (e *EmptyDictionary) PrefixIterator(prefix string) DictionaryIterator {
  60. return &EmptyDictionaryIterator{}
  61. }
  62. func (e *EmptyDictionary) RangeIterator(start, end string) DictionaryIterator {
  63. return &EmptyDictionaryIterator{}
  64. }
  65. func (e *EmptyDictionary) AutomatonIterator(a vellum.Automaton,
  66. startKeyInclusive, endKeyExclusive []byte) DictionaryIterator {
  67. return &EmptyDictionaryIterator{}
  68. }
  69. func (e *EmptyDictionary) OnlyIterator(onlyTerms [][]byte,
  70. includeCount bool) DictionaryIterator {
  71. return &EmptyDictionaryIterator{}
  72. }
  73. func (e *EmptyDictionary) Contains(key []byte) (bool, error) {
  74. return false, nil
  75. }
  76. type EmptyDictionaryIterator struct{}
  77. func (e *EmptyDictionaryIterator) Next() (*index.DictEntry, error) {
  78. return nil, nil
  79. }
  80. func (e *EmptyDictionaryIterator) Contains(key []byte) (bool, error) {
  81. return false, nil
  82. }
  83. type EmptyPostingsList struct{}
  84. func (e *EmptyPostingsList) Iterator(includeFreq, includeNorm, includeLocations bool,
  85. prealloc PostingsIterator) PostingsIterator {
  86. return &EmptyPostingsIterator{}
  87. }
  88. func (e *EmptyPostingsList) Size() int {
  89. return 0
  90. }
  91. func (e *EmptyPostingsList) Count() uint64 {
  92. return 0
  93. }
  94. type EmptyPostingsIterator struct{}
  95. func (e *EmptyPostingsIterator) Next() (Posting, error) {
  96. return nil, nil
  97. }
  98. func (e *EmptyPostingsIterator) Advance(uint64) (Posting, error) {
  99. return nil, nil
  100. }
  101. func (e *EmptyPostingsIterator) Size() int {
  102. return 0
  103. }
  104. var AnEmptyPostingsIterator = &EmptyPostingsIterator{}