github.com/balzaczyy/golucene@v0.0.0-20151210033525-d0be9ee89713/core/index/invert.go (about) 1 package index 2 3 import ( 4 . "github.com/balzaczyy/golucene/core/analysis/tokenattributes" 5 "github.com/balzaczyy/golucene/core/util" 6 ) 7 8 // index/DocInvertState.java 9 10 /* 11 Tracks the number and position / offset parameters of terms being 12 added to the index. The information collected in this class is also 13 used to calculate the normalization factor for a field 14 */ 15 type FieldInvertState struct { 16 name string 17 position int 18 length int 19 numOverlap int 20 offset int 21 maxTermFrequency int 22 uniqueTermCount int 23 boost float32 24 lastStartOffset int 25 lastPosition int 26 attributeSource *util.AttributeSource 27 28 offsetAttribute OffsetAttribute 29 posIncrAttribute PositionIncrementAttribute 30 payloadAttribute PayloadAttribute 31 termAttribute TermToBytesRefAttribute 32 } 33 34 /* Creates FieldInvertState for the specified field name. */ 35 func newFieldInvertState(name string) *FieldInvertState { 36 return &FieldInvertState{name: name} 37 } 38 39 /* Re-initialize the state */ 40 func (st *FieldInvertState) reset() { 41 st.position = -1 42 st.length = 0 43 st.numOverlap = 0 44 st.offset = 0 45 st.maxTermFrequency = 0 46 st.uniqueTermCount = 0 47 st.boost = 1.0 48 st.lastStartOffset = 0 49 st.lastPosition = 0 50 } 51 52 /* Sets attributeSource to a new instance. */ 53 func (st *FieldInvertState) setAttributeSource(attributeSource *util.AttributeSource) { 54 if st.attributeSource != attributeSource { 55 st.attributeSource = attributeSource 56 st.termAttribute = attributeSource.Get("TermToBytesRefAttribute").(TermToBytesRefAttribute) 57 st.posIncrAttribute = attributeSource.Add("PositionIncrementAttribute").(PositionIncrementAttribute) 58 st.offsetAttribute = attributeSource.Add("OffsetAttribute").(OffsetAttribute) 59 // st.payloadAttribute = attributeSource.Get("PayloadAttribute").(PayloadAttribute) 60 st.payloadAttribute = nil 61 } 62 } 63 64 /* Get total number of terms in this field. */ 65 func (st *FieldInvertState) Length() int { 66 return st.length 67 } 68 69 /* Get the number of terms with positionIncrement == 0. */ 70 func (st *FieldInvertState) NumOverlap() int { 71 return st.numOverlap 72 } 73 74 /* 75 Get boost value. This is the cumulative product of document boost and 76 field boost for all field instances sharing the same field name. 77 */ 78 func (st *FieldInvertState) Boost() float32 { 79 return st.boost 80 } 81 82 /* Return the field's name */ 83 func (st *FieldInvertState) Name() string { 84 return st.name 85 }