def load(cls, serialized_index):
        """Load a serialized index"""
        from lunr import __TARGET_JS_VERSION__

        if isinstance(serialized_index, basestring):
            serialized_index = json.loads(serialized_index)

        if serialized_index["version"] != __TARGET_JS_VERSION__:
            logger.warning(
                "Version mismatch when loading serialized index. "
                "Current version of lunr {} does not match that of serialized "
                "index {}".format(__TARGET_JS_VERSION__, serialized_index["version"])
            )

        field_vectors = {
            ref: Vector(elements) for ref, elements in serialized_index["fieldVectors"]
        }

        tokenset_builder = TokenSetBuilder()
        inverted_index = {}
        for term, posting in serialized_index["invertedIndex"]:
            tokenset_builder.insert(term)
            inverted_index[term] = posting

        tokenset_builder.finish()

        return Index(
            fields=serialized_index["fields"],
            field_vectors=field_vectors,
            inverted_index=inverted_index,
            token_set=tokenset_builder.root,
            pipeline=Pipeline.load(serialized_index["pipeline"]),
        )
def load ( cls , serialized_index ) : from lunr import __TARGET_JS_VERSION__ if isinstance ( serialized_index , basestring ) : serialized_index = json . loads ( serialized_index ) if serialized_index [ "version" ] != __TARGET_JS_VERSION__ : logger . warning ( "Version mismatch when loading serialized index. " "Current version of lunr {} does not match that of serialized " "index {}" . format ( __TARGET_JS_VERSION__ , serialized_index [ "version" ] ) ) field_vectors = { ref : Vector ( elements ) for ref , elements in serialized_index [ "fieldVectors" ] } tokenset_builder = TokenSetBuilder ( ) inverted_index = { } for term , posting in serialized_index [ "invertedIndex" ] : tokenset_builder . insert ( term ) inverted_index [ term ] = posting tokenset_builder . finish ( ) return Index ( fields = serialized_index [ "fields" ] , field_vectors = field_vectors , inverted_index = inverted_index , token_set = tokenset_builder . root , pipeline = Pipeline . load ( serialized_index [ "pipeline" ] ) , )
Load a serialized index