Skip to content

Commit 00ac2ce

Browse files
authored
Merge pull request #3 from alldroll/issue2
Inverted index version validation
2 parents 0285fc4 + dd36c36 commit 00ac2ce

File tree

4 files changed

+9
-0
lines changed

4 files changed

+9
-0
lines changed

pkg/index/index_reader.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ func (ir *Reader) readHeader() (*header, error) {
7171
return nil, fmt.Errorf("Failed to retrieve header: %v", err)
7272
}
7373

74+
if header.Version != IndexVersion {
75+
return nil, fmt.Errorf("Index version mismatch, expected %s version", IndexVersion)
76+
}
77+
7478
if err = closeIfRequired(headerReader); err != nil {
7579
return nil, fmt.Errorf("Failed to close header file: %v", err)
7680
}

pkg/index/indexer_writer.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import (
1010
"github.com/alldroll/suggest/pkg/compression"
1111
)
1212

13+
// IndexVersion tells that the inverted index structure has the provided below version
14+
const IndexVersion = "v1"
15+
1316
// Writer creates and maintains an inverted index
1417
type Writer struct {
1518
directory Directory
@@ -46,6 +49,7 @@ var (
4649

4750
// header struct that store terms descriptions and indices count
4851
type header struct {
52+
Version string
4953
Indices uint32
5054
Terms []termDescription
5155
}
@@ -102,6 +106,7 @@ func (iw *Writer) Commit() error {
102106

103107
// header struct that should be loaded on Load
104108
header := header{
109+
Version: IndexVersion,
105110
Terms: []termDescription{},
106111
Indices: uint32(len(iw.indices)),
107112
}

pkg/suggest/testdata/db/cars.dl

28 Bytes
Binary file not shown.

pkg/suggest/testdata/db/cars.hd

-70 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)