Add new document to the index with body that has the same word twice like: { "body", "test test" }
Serialize the index to file or string using ToJson() method
Create new index, and try to load the serialized data with the LoadFromJson() method
Result'Unexpected token Number.' exception is being thrown.
Expected behavior
The index deserializes properly.
Additional data
Here is a minimal example:
var index = await Lunr.Index.Build(async builder =>
{
builder.AllowMetadata("position");
builder.AddField("body");
await builder.Add(new Document
{
{ "body", "test test" },
{ "id", "1" },
});
});
var json = index.ToJson();
var index2 = Lunr.Index.LoadFromJson(json);
If we change { "body", "test test" } to, for example, { "body", "test test2" } it deserializes fine. From what I can tell, it fails because the metadata deserializer doesn't expect more than one position. So when it encounters something like this:
To Reproduce
Result 'Unexpected token Number.' exception is being thrown.
Expected behavior The index deserializes properly.
Additional data Here is a minimal example:
If we change { "body", "test test" } to, for example, { "body", "test test2" } it deserializes fine. From what I can tell, it fails because the metadata deserializer doesn't expect more than one position. So when it encounters something like this:
It loads the first position pair but is unable to deserialize the second one.