EncodeTSVector encodes a tsvector into a serialized representation for on-disk storage.
(appendTo []byte, vector TSVector)
| 17 | // EncodeTSVector encodes a tsvector into a serialized representation for |
| 18 | // on-disk storage. |
| 19 | func EncodeTSVector(appendTo []byte, vector TSVector) ([]byte, error) { |
| 20 | appendTo = encoding.EncodeUint32Ascending(appendTo, uint32(len(vector))) |
| 21 | for _, term := range vector { |
| 22 | l := term.lexeme |
| 23 | appendTo = encoding.EncodeUntaggedBytesValue(appendTo, encoding.UnsafeConvertStringToBytes(l)) |
| 24 | if len(term.positions) > maxTSVectorPositions { |
| 25 | return nil, pgerror.Newf(pgcode.ProgramLimitExceeded, |
| 26 | "tsvector position list of size %d too large (maximum is %d)", len(term.positions), |
| 27 | maxTSVectorPositions) |
| 28 | } |
| 29 | if len(l) > maxTSVectorLexemeLen { |
| 30 | return nil, pgerror.Newf(pgcode.ProgramLimitExceeded, |
| 31 | "tsvector lexeme of size %d too large (maximum is %d)", len(l), |
| 32 | maxTSVectorLexemeLen) |
| 33 | } |
| 34 | appendTo = encoding.EncodeUint16Ascending(appendTo, uint16(len(term.positions))) |
| 35 | for _, pos := range term.positions { |
| 36 | weight, err := pos.weight.TSVectorPGEncoding() |
| 37 | if err != nil { |
| 38 | return nil, err |
| 39 | } |
| 40 | // Clear the 2 most significant bits. These should never be set, |
| 41 | // as we always make sure that positions are at most 1 << 14, but |
| 42 | // better an extra check. |
| 43 | position := pos.position & (^(uint16(3) << 14)) |
| 44 | out := position | (uint16(weight) << 14) |
| 45 | appendTo = encoding.EncodeUint16Ascending(appendTo, out) |
| 46 | } |
| 47 | } |
| 48 | return appendTo, nil |
| 49 | } |
| 50 | |
| 51 | // DecodeTSVector decodes a tsvector in disk-storage representation from the |
| 52 | // input byte slice. |
nothing calls this directly
no test coverage detected
searching dependent graphs…