Index.fromJson constructor
Implementation
factory Index.fromJson(Map<String, dynamic> map) {
Map<FieldRef, Vector> fieldVectors = {};
List serializedVectors = map['fieldVectors'];
InvertedIndex invertedIndex = InvertedIndex();
List serializedInvertedIndex = map['invertedIndex'];
TokenSetBuilder tokenSetBuilder = TokenSetBuilder();
Pipeline pipeline = Pipeline.load(map['pipeline'].cast<String>());
if (map['version'] != Lunr.version) {
Utils.warn("Version mismatch when loading serialised index. Current"
"version of lunr '${Lunr.version}' does not match serialized "
"index '${map['version']}'");
}
for (List tuple in serializedVectors) {
String ref = tuple[0] as String;
List<num> elements = tuple[1].cast<num>();
fieldVectors[FieldRef.fromString(ref)] = Vector(elements);
}
for (List tuple in serializedInvertedIndex) {
String term = tuple[0];
Posting posting = Posting.fromJson(tuple[1]);
tokenSetBuilder.insert(term);
invertedIndex[Token(term)] = posting;
}
tokenSetBuilder.finish();
return Index(
fields: map['fields'].cast<String>(),
fieldVectors: fieldVectors,
invertedIndex: invertedIndex,
tokenSet: tokenSetBuilder.root,
pipeline: pipeline,
);
}