github.com/balzaczyy/golucene@v0.0.0-20151210033525-d0be9ee89713/core/codec/spi/docValues.go (about) 1 package spi 2 3 import ( 4 . "github.com/balzaczyy/golucene/core/index/model" 5 "io" 6 ) 7 8 // codecs/DocValuesFormat.java 9 10 /* 11 Encodes/decodes per-document values. 12 13 Note, when extending this class, the name Name() may be written into 14 the index in certain configurations. In order for the segment to be 15 read, the name must resolve to your implemetation via LoadXYZ(). 16 Since Go doesn't have Java's SPI locate mechanism, this method use 17 manual mappings to resolve format names. 18 19 If you implement your own format, make sure that it is manually 20 included. 21 */ 22 type DocValuesFormat interface { 23 Name() string 24 // Returns a DocValuesConsumer to write docvalues to the index. 25 FieldsConsumer(state *SegmentWriteState) (w DocValuesConsumer, err error) 26 // Returns a DocValuesProducer to read docvalues from the index. 27 // 28 // NOTE: by the time this call returns, it must 29 // hold open any files it will need to use; else, those files may 30 // be deleted. Additionally, required fiels may be deleted during 31 // the execution of this call before there is a chance to open them. 32 // Under these circumstances an IO error should be returned by the 33 // implementation. IO errors are expected and will automatically 34 // cause a retry of the segment opening logic with the newly 35 // revised segments. 36 FieldsProducer(state SegmentReadState) (r DocValuesProducer, err error) 37 } 38 39 var allDocValuesFormats = map[string]DocValuesFormat{} 40 41 // workaround Lucene Java's SPI mechanism 42 func RegisterDocValuesFormat(formats ...DocValuesFormat) { 43 for _, format := range formats { 44 allDocValuesFormats[format.Name()] = format 45 } 46 } 47 48 func LoadDocValuesProducer(name string, state SegmentReadState) (fp DocValuesProducer, err error) { 49 panic("not implemented yet") 50 // switch name { 51 // case "Lucene42": 52 // return newLucene42DocValuesProducer(state, LUCENE42_DV_DATA_CODEC, LUCENE42_DV_DATA_EXTENSION, 53 // LUCENE42_DV_METADATA_CODEC, LUCENE42_DV_METADATA_EXTENSION) 54 // case "Lucene45": 55 // return newLucene45DocValuesProducer(state, LUCENE45_DV_DATA_CODEC, LUCENE45_DV_DATA_EXTENSION, 56 // LUCENE45_DV_META_CODEC, LUCENE45_DV_META_EXTENSION) 57 // } 58 // panic(fmt.Sprintf("Service '%v' not found.", name)) 59 } 60 61 // codecs/DocValuesConsumer.java 62 /* 63 Abstract API that consumes numeric, binary and sorted docvalues. 64 Concret implementations of this actually do "something" with the 65 docvalues (write it into the index in a specific format). 66 67 The lifecycle is: 68 69 1. DocValuesConsumer is created by DocValuesFormat.FieldsConsumer() 70 or NormsFormat.NormsConsumer(). 71 2. AddNumericField, AddBinaryField, or addSortedField are called for 72 each Numeric, Binary, or Sorted docvalues field. The API is a "pull" 73 rather than "push", and the implementation is free to iterate over 74 the values multiple times. 75 3. After all fields are added, the consumer is closed. 76 */ 77 type DocValuesConsumer interface { 78 io.Closer 79 // Writes numeric docvalues for a field. 80 AddNumericField(*FieldInfo, func() func() (interface{}, bool)) error 81 } 82 83 // codecs/DocvaluesProducer.java 84 85 // Abstract API that produces numeric, binary and sorted docvalues. 86 type DocValuesProducer interface { 87 io.Closer 88 Numeric(field *FieldInfo) (v NumericDocValues, err error) 89 Binary(field *FieldInfo) (v BinaryDocValues, err error) 90 Sorted(field *FieldInfo) (v SortedDocValues, err error) 91 SortedSet(field *FieldInfo) (v SortedSetDocValues, err error) 92 } 93 94 // type NumericDocValues interface { 95 // Value(docID int) int64 96 // } 97 type NumericDocValues func(docID int) int64 98 99 /* A per-document []byte */ 100 type BinaryDocValues interface { 101 // Lookup the value for document. The returned BytesRef may be 102 // re-used across calls to get() so make sure to copy it if you 103 // want to keep it around. 104 Get(docId int) []byte 105 } 106 107 type SortedDocValues interface { 108 BinaryDocValues 109 Ord(docID int) int 110 LookupOrd(int) []byte 111 ValueCount() int 112 } 113 114 type SortedSetDocValues interface { 115 NextOrd() int64 116 SetDocument(docID int) 117 LookupOrd(int64) []byte 118 ValueCount() int64 119 }