-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathsection.go
78 lines (64 loc) · 2.8 KB
/
section.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright (c) 2023 Couchbase, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package zap
import (
"sync"
"github.com/RoaringBitmap/roaring"
index "github.com/blevesearch/bleve_index_api"
)
type section interface {
// process is essentially parsing of a specific field's content in a specific
// document. any tracking of processed data *specific to this section* should
// be done in opaque which will be passed to the Persist() API.
Process(opaque map[int]resetable, docNum uint32, f index.Field, fieldID uint16)
// flush the processed data in the opaque to the writer.
Persist(opaque map[int]resetable, w *CountHashWriter) (n int64, err error)
// this API is used to fetch the file offset of the field for this section.
// this is used during search time to parse the section, and fetch results
// for the specific "index" thats part of the section.
AddrForField(opaque map[int]resetable, fieldID int) int
// for every field in the fieldsInv (relevant to this section) merge the section
// contents from all the segments into a single section data for the field.
// as part of the merge API, write the merged data to the writer and also track
// the starting offset of this newly merged section data.
Merge(opaque map[int]resetable, segments []*SegmentBase, drops []*roaring.Bitmap, fieldsInv []string,
newDocNumsIn [][]uint64, w *CountHashWriter, closeCh chan struct{}) error
// opaque is used to track the data specific to this section. its not visible
// to the other sections and is only visible and freely modifiable by this specifc
// section.
InitOpaque(args map[string]interface{}) resetable
}
type resetable interface {
Reset() error
Set(key string, value interface{})
}
// -----------------------------------------------------------------------------
const (
SectionInvertedTextIndex = iota
SectionFaissVectorIndex
SectionSynonymIndex
)
// -----------------------------------------------------------------------------
var (
segmentSectionsMutex sync.Mutex
// writes to segmentSections within init()s ONLY within lock,
// reads will not require lock access
segmentSections = make(map[uint16]section)
)
// Method to be invoked within init()s ONLY.
func registerSegmentSection(key uint16, val section) {
segmentSectionsMutex.Lock()
segmentSections[key] = val
segmentSectionsMutex.Unlock()
}