They will offer to solve this problem, create a map (hash), enter each word as a key and add the location of the word as a value to the list, which is the value on the map.
For the text, Fast brown fox jumps over a lazy dog, this will lead to a model as shown below (in json format).
Note: Here all words are added to the index as if they were written in lower case.
{
"document": [
{
"key": "the",
"value": [
{
"location": 1
},
{
"location": 7
}
]
},
{
"key": "quick",
"value": [
{
"location": 2
}
]
},
{
"key": "brown",
"value": [
{
"location": 3
}
]
},
{
"key": "fox",
"value": [
{
"location": 4
}
]
},
{
"key": "jumps",
"value": [
{
"location": 5
}
]
},
{
"key": "over",
"value": [
{
"location": 6
}
]
},
{
"key": "lazy",
"value": [
{
"location": 8
}
]
},
{
"key": "dog",
"value": [
{
"location": 9
}
]
}
]
}
Once this index is made, it is easy to see how far different words are from each other. As can be seen in the word a, which is located in places 1 and 7.
Also, the number of times a word is displayed in the text can be easily obtained by the number of places that give the word.
: , , // ..