github.com/balzaczyy/golucene@v0.0.0-20151210033525-d0be9ee89713/core/codec/spi/blockTermState.go (about) 1 package spi 2 3 import ( 4 "fmt" 5 . "github.com/balzaczyy/golucene/core/index/model" 6 "reflect" 7 ) 8 9 // index/OrdTermState.java 10 11 // An ordinal based TermState 12 type OrdTermState struct { 13 // Term ordinal, i.e. it's position in the full list of 14 // sorted terms 15 ord int64 16 } 17 18 func (ts *OrdTermState) CopyFrom(other TermState) { 19 if ots, ok := other.(*OrdTermState); ok { 20 ts.ord = ots.ord 21 } else { 22 panic(fmt.Sprintf("Can not copy from %v", reflect.TypeOf(other).Name())) 23 } 24 } 25 26 func (ts *OrdTermState) Clone() TermState { 27 return &OrdTermState{ord: ts.ord} 28 } 29 30 func (ts *OrdTermState) String() string { 31 return fmt.Sprintf("TermState ord=%v", ts.ord) 32 } 33 34 // BlockTermState.java 35 /* Holds all state required for PostingsReaderBase 36 to produce a DocsEnum without re-seeking the 37 terms dict. */ 38 type BlockTermState struct { 39 *OrdTermState 40 // Allow sub-class to be converted 41 Self TermState 42 43 // how many docs have this term 44 DocFreq int 45 // total number of occurrences of this term 46 TotalTermFreq int64 47 48 // the term's ord in the current block 49 TermBlockOrd int 50 // fp into the terms dict primary file (_X.tim) that holds this term 51 blockFilePointer int64 52 } 53 54 func NewBlockTermState() *BlockTermState { 55 return &BlockTermState{OrdTermState: &OrdTermState{}} 56 } 57 58 func (ts *BlockTermState) CopyFrom(other TermState) { 59 if ts.Self != nil { 60 ts.Self.CopyFrom(other) 61 return 62 } 63 ts.CopyFrom_(other) 64 } 65 66 func (ts *BlockTermState) CopyFrom_(other TermState) { 67 if ots, ok := other.(*BlockTermState); ok { 68 ts.OrdTermState.CopyFrom(ots.OrdTermState) 69 ts.DocFreq = ots.DocFreq 70 ts.TotalTermFreq = ots.TotalTermFreq 71 ts.TermBlockOrd = ots.TermBlockOrd 72 ts.blockFilePointer = ots.blockFilePointer 73 } else { 74 panic(fmt.Sprintf("Can not copy from %v", reflect.TypeOf(other).Name())) 75 } 76 } 77 78 func (ts *BlockTermState) Clone() TermState { 79 if ts.Self != nil { 80 return ts.Self.Clone() 81 } 82 clone := NewBlockTermState() 83 clone.CopyFrom(ts) 84 return clone 85 } 86 87 func (ts *BlockTermState) String() string { 88 return fmt.Sprintf("docFreq=%v totalTermFreq=%v termBlockOrd=%v blockFP=%v", 89 ts.DocFreq, ts.TotalTermFreq, ts.TermBlockOrd, ts.blockFilePointer) 90 }