method of static class JsNgram
Description
Picks up perfect match from sorted result of N-gram partial matches.
Returns the perfect match.
Counts the number of hits and puts it in the property work as an array of [hits, documents].
Example
var found = JsNgram.sortResultsByLocation(results);
JsNgram.findPerfection(found, 3);
Usage
findPerfection(x, n);
Argument x is a sorted result of match (by document).
The data should be the output of the method sortResultsByLocation.
Argument n is the required count for perfect match.
This should be the number of generated N-gram keys.
For example, 2 for "cat" and 4 for "alice".
The output is compatible format with the method sortFoundByDocumentPosition.
This very method does match the N-gram results comparing the N-gram key numbers with positons.
The input found format is:
{
document id: {
N-gram key number: [position, position, position, ... ],
N-gram key number: [position, position, position, ... ],
N-gram key number: [position, position, position, ... ]
},
document id: {
N-gram key number: [position, position, position, ... ],
N-gram key number: [position, position, position, ... ]
}
}
In above notation, N-gram key number is a sequence number of each N-gram key. For example, for searching "alice", following four N-gram keys are generated: "al", "li", "ic" and "ce" with the N-gram key number is 0, 1, 2 and 3, respectively.
The output format is:
{
document id: [ # list is sorted
[position, matched N-gram key text],
[position, matched N-gram key text],
[position, matched N-gram key text]
],
document id: [ # list is sorted
[position, matched N-gram key text],
[position, matched N-gram key text]
]
}