setSearchField method
Generates a field divided by a bi-gram for searching.
The key
is the key to save the data for search.
The original data to be split into bigrams is specified by bigramKeys
,
and the data to be saved for tags is specified by tagKeys
.
Implementation
DynamicDocumentModel setSearchField({
String key = MetaConst.search,
List<String> bigramKeys = const [Const.name, Const.text],
List<String> tagKeys = const [Const.tag, Const.category],
}) {
var tmp = "";
for (final bigramKey in bigramKeys) {
if (this[bigramKey] is! String) {
continue;
}
tmp += this[bigramKey];
}
for (final tagKey in tagKeys) {
final tags = this[tagKey];
if (tags is! List) {
continue;
}
for (final tag in tags) {
tmp += tag.toString();
}
}
final res = <String, bool>{};
tmp = tmp.toLowerCase();
final bigramList = tmp.splitByBigram();
for (final bigram in bigramList) {
res[bigram] = true;
}
final characterList = tmp.splitByCharacter();
for (final character in characterList) {
res[character] = true;
}
this[key] = res;
return this;
}