@@ -1040,6 +1040,7 @@ Y_UNIT_TEST_SUITE(Viewer) {
1040
1040
UNIT_ASSERT_VALUES_EQUAL (LevenshteinDistance (" abc" , " " ), 3 );
1041
1041
UNIT_ASSERT_VALUES_EQUAL (LevenshteinDistance (" apple" , " apple" ), 0 );
1042
1042
UNIT_ASSERT_VALUES_EQUAL (LevenshteinDistance (" apple" , " aple" ), 1 );
1043
+ UNIT_ASSERT_VALUES_EQUAL (LevenshteinDistance (" UPPER" , " upper" ), 0 );
1043
1044
UNIT_ASSERT_VALUES_EQUAL (LevenshteinDistance (" horse" , " ros" ), 3 );
1044
1045
UNIT_ASSERT_VALUES_EQUAL (LevenshteinDistance (" intention" , " execution" ), 5 );
1045
1046
UNIT_ASSERT_VALUES_EQUAL (LevenshteinDistance (" /slice/db" , " /slice" ), 3 );
@@ -1048,64 +1049,48 @@ Y_UNIT_TEST_SUITE(Viewer) {
1048
1049
UNIT_ASSERT_VALUES_EQUAL (LevenshteinDistance (" /slice/db" , " /slice/db26000" ), 5 );
1049
1050
}
1050
1051
1051
- Y_UNIT_TEST (FuzzySearcher)
1052
- {
1053
- TVector<TString> dictionary = { " /slice" , " /slice/db" , " /slice/db26000" };
1052
+ TVector<TString> SimilarWordsDictionary = { " /slice" , " /slice/db" , " /slice/db26000" };
1053
+ TVector<TString> DifferentWordsDictionary = { " /orders" , " /peoples" , " /OrdinaryScheduleTables" };
1054
1054
1055
- {
1056
- TVector<TString> expectations = { " /slice/db" };
1057
- auto fuzzy = FuzzySearcher<TString>(dictionary);
1058
- auto result = fuzzy.Search (" /slice/db" , 1 );
1055
+ void FuzzySearcherTest (TVector<TString>& dictionary, TString search, ui32 limit, TVector<TString> expectations) {
1056
+ auto fuzzy = FuzzySearcher<TString>(dictionary);
1057
+ auto result = fuzzy.Search (search, limit);
1059
1058
1060
- UNIT_ASSERT_VALUES_EQUAL (expectations.size (), result.size ());
1061
- for (ui32 i = 0 ; i < expectations.size (); i++) {
1062
- UNIT_ASSERT_VALUES_EQUAL (expectations[i], result[i]);
1063
- }
1064
- }
1065
-
1066
- {
1067
- TVector<TString> expectations = { " /slice/db" , " /slice" };
1068
- auto fuzzy = FuzzySearcher<TString>(dictionary);
1069
- auto result = fuzzy.Search (" /slice/db" , 2 );
1070
-
1071
- UNIT_ASSERT_VALUES_EQUAL (expectations.size (), result.size ());
1072
- for (ui32 i = 0 ; i < expectations.size (); i++) {
1073
- UNIT_ASSERT_VALUES_EQUAL (expectations[i], result[i]);
1074
- }
1059
+ UNIT_ASSERT_VALUES_EQUAL (expectations.size (), result.size ());
1060
+ for (ui32 i = 0 ; i < expectations.size (); i++) {
1061
+ UNIT_ASSERT_VALUES_EQUAL (expectations[i], result[i]);
1075
1062
}
1063
+ }
1076
1064
1077
- {
1078
- TVector<TString> expectations = { " /slice/db " , " /slice " , " /slice/db26000 " };
1079
- auto fuzzy = FuzzySearcher<TString>(dictionary );
1080
- auto result = fuzzy. Search ( " /slice/db " , 3 );
1065
+ Y_UNIT_TEST (FuzzySearcherLimit1OutOf4)
1066
+ {
1067
+ FuzzySearcherTest (SimilarWordsDictionary, " /slice/db " , 1 , { " /slice/db " } );
1068
+ }
1081
1069
1082
- UNIT_ASSERT_VALUES_EQUAL (expectations.size (), result.size ());
1083
- for (ui32 i = 0 ; i < expectations.size (); i++) {
1084
- UNIT_ASSERT_VALUES_EQUAL (expectations[i], result[i]);
1085
- }
1086
- }
1070
+ Y_UNIT_TEST (FuzzySearcherLimit2OutOf4)
1071
+ {
1072
+ FuzzySearcherTest (SimilarWordsDictionary, " /slice/db" , 2 , { " /slice/db" , " /slice/db26000" });
1073
+ }
1087
1074
1088
- {
1089
- TVector<TString> expectations = { " /slice/db " , " /slice " , " /slice/db26000 " };
1090
- auto fuzzy = FuzzySearcher<TString>(dictionary );
1091
- auto result = fuzzy. Search ( " /slice/db " , 4 );
1075
+ Y_UNIT_TEST (FuzzySearcherLimit3OutOf4)
1076
+ {
1077
+ FuzzySearcherTest (SimilarWordsDictionary, " /slice/db " , 3 , { " /slice/db " , " /slice/db26000 " , " /slice " } );
1078
+ }
1092
1079
1093
- UNIT_ASSERT_VALUES_EQUAL (expectations.size (), result.size ());
1094
- for (ui32 i = 0 ; i < expectations.size (); i++) {
1095
- UNIT_ASSERT_VALUES_EQUAL (expectations[i], result[i]);
1096
- }
1097
- }
1080
+ Y_UNIT_TEST (FuzzySearcherLimit4OutOf4)
1081
+ {
1082
+ FuzzySearcherTest (SimilarWordsDictionary, " /slice/db" , 4 , { " /slice/db" , " /slice/db26000" , " /slice" });
1083
+ }
1098
1084
1099
- {
1100
- TVector<TString> expectations = { " /slice/db26000 " , " /slice/db " , " /slice " };
1101
- auto fuzzy = FuzzySearcher<TString>(dictionary );
1102
- auto result = fuzzy. Search ( " /slice/db26001 " );
1085
+ Y_UNIT_TEST (FuzzySearcherLongWord)
1086
+ {
1087
+ FuzzySearcherTest (SimilarWordsDictionary, " /slice/db26001 " , 10 , { " /slice/db26000 " , " /slice/db " , " /slice " } );
1088
+ }
1103
1089
1104
- UNIT_ASSERT_VALUES_EQUAL (expectations.size (), result.size ());
1105
- for (ui32 i = 0 ; i < expectations.size (); i++) {
1106
- UNIT_ASSERT_VALUES_EQUAL (expectations[i], result[i]);
1107
- }
1108
- }
1090
+ Y_UNIT_TEST (FuzzySearcherPriority)
1091
+ {
1092
+ FuzzySearcherTest (DifferentWordsDictionary, " /ord" , 10 , { " /orders" , " /OrdinaryScheduleTables" , " /peoples" });
1093
+ FuzzySearcherTest (DifferentWordsDictionary, " Tables" , 10 , { " /OrdinaryScheduleTables" , " /orders" , " /peoples" });
1109
1094
}
1110
1095
1111
1096
void JsonAutocompleteTest (HTTP_METHOD method, NJson::TJsonValue& value, TString prefix = " " , TString database = " " , TVector<TString> tables = {}, ui32 limit = 10 , bool lowerCaseContentType = false ) {
@@ -1136,6 +1121,7 @@ Y_UNIT_TEST_SUITE(Viewer) {
1136
1121
if (prefix) {
1137
1122
httpReq.CgiParameters .emplace (" prefix" , prefix);
1138
1123
}
1124
+ httpReq.CgiParameters .emplace (" limit" , ToString (limit));
1139
1125
} else if (method == HTTP_METHOD_POST) {
1140
1126
NJson::TJsonArray tableArray;
1141
1127
for (const TString& table : tables) {
@@ -1145,13 +1131,13 @@ Y_UNIT_TEST_SUITE(Viewer) {
1145
1131
NJson::TJsonValue root = NJson::TJsonMap{
1146
1132
{" database" , database},
1147
1133
{" table" , tableArray},
1148
- {" prefix" , prefix}
1134
+ {" prefix" , prefix},
1135
+ {" limit" , limit}
1149
1136
};
1150
1137
httpReq.PostContent = NJson::WriteJson (root);
1151
- auto contType = lowerCaseContentType ? " content-type" : " Content-Type" ;
1152
- httpReq.HttpHeaders .AddHeader (contType , " application/json" );
1138
+ auto contentType = lowerCaseContentType ? " content-type" : " Content-Type" ;
1139
+ httpReq.HttpHeaders .AddHeader (contentType , " application/json" );
1153
1140
}
1154
- httpReq.CgiParameters .emplace (" limit" , ToString (limit));
1155
1141
httpReq.CgiParameters .emplace (" direct" , " 1" );
1156
1142
auto page = MakeHolder<TMonPage>(" viewer" , " title" );
1157
1143
TMonService2HttpRequest monReq (nullptr , &httpReq, nullptr , page.Get (), " /json/autocomplete" , nullptr );
@@ -1236,7 +1222,7 @@ Y_UNIT_TEST_SUITE(Viewer) {
1236
1222
});
1237
1223
}
1238
1224
1239
- Y_UNIT_TEST (JsonAutocompleteDatabase ) {
1225
+ Y_UNIT_TEST (JsonAutocompleteStartOfDatabaseName ) {
1240
1226
NJson::TJsonValue value;
1241
1227
JsonAutocompleteTest (HTTP_METHOD_GET, value, " /Root" );
1242
1228
VerifyJsonAutocompleteSuccess (value, {
@@ -1246,16 +1232,22 @@ Y_UNIT_TEST_SUITE(Viewer) {
1246
1232
" /Root/MyDatabase" ,
1247
1233
" /Root/TestDatabase"
1248
1234
});
1235
+ }
1249
1236
1237
+ Y_UNIT_TEST (JsonAutocompleteEndOfDatabaseName) {
1238
+ NJson::TJsonValue value;
1250
1239
JsonAutocompleteTest (HTTP_METHOD_GET, value, " Database" );
1251
1240
VerifyJsonAutocompleteSuccess (value, {
1252
- " /Root/test" ,
1253
1241
" /Root/MyDatabase" ,
1254
- " /Root/slice" ,
1255
1242
" /Root/TestDatabase" ,
1243
+ " /Root/test" ,
1244
+ " /Root/slice" ,
1256
1245
" /Root/qwerty"
1257
1246
});
1247
+ }
1258
1248
1249
+ Y_UNIT_TEST (JsonAutocompleteSimilarDatabaseName) {
1250
+ NJson::TJsonValue value;
1259
1251
JsonAutocompleteTest (HTTP_METHOD_GET, value, " /Root/Database" );
1260
1252
VerifyJsonAutocompleteSuccess (value, {
1261
1253
" /Root/MyDatabase" ,
@@ -1264,19 +1256,28 @@ Y_UNIT_TEST_SUITE(Viewer) {
1264
1256
" /Root/slice" ,
1265
1257
" /Root/qwerty"
1266
1258
});
1259
+ }
1267
1260
1261
+ Y_UNIT_TEST (JsonAutocompleteSimilarDatabaseNameWithLimit) {
1262
+ NJson::TJsonValue value;
1268
1263
JsonAutocompleteTest (HTTP_METHOD_GET, value, " /Root/Database" , " " , {}, 2 );
1269
1264
VerifyJsonAutocompleteSuccess (value, {
1270
1265
" /Root/MyDatabase" ,
1271
1266
" /Root/TestDatabase"
1272
1267
});
1268
+ }
1273
1269
1270
+ Y_UNIT_TEST (JsonAutocompleteSimilarDatabaseNamePOST) {
1271
+ NJson::TJsonValue value;
1274
1272
JsonAutocompleteTest (HTTP_METHOD_POST, value, " /Root/Database" , " " , {}, 2 );
1275
1273
VerifyJsonAutocompleteSuccess (value, {
1276
1274
" /Root/MyDatabase" ,
1277
1275
" /Root/TestDatabase"
1278
1276
});
1277
+ }
1279
1278
1279
+ Y_UNIT_TEST (JsonAutocompleteSimilarDatabaseNameLowerCase) {
1280
+ NJson::TJsonValue value;
1280
1281
JsonAutocompleteTest (HTTP_METHOD_POST, value, " /Root/Database" , " " , {}, 2 , true );
1281
1282
VerifyJsonAutocompleteSuccess (value, {
1282
1283
" /Root/MyDatabase" ,
@@ -1293,7 +1294,10 @@ Y_UNIT_TEST_SUITE(Viewer) {
1293
1294
" orders" ,
1294
1295
" products"
1295
1296
});
1297
+ }
1296
1298
1299
+ Y_UNIT_TEST (JsonAutocompleteSchemePOST) {
1300
+ NJson::TJsonValue value;
1297
1301
JsonAutocompleteTest (HTTP_METHOD_POST, value, " clien" , " /Root/Database" );
1298
1302
VerifyJsonAutocompleteSuccess (value, {
1299
1303
" clients" ,
@@ -1302,22 +1306,28 @@ Y_UNIT_TEST_SUITE(Viewer) {
1302
1306
});
1303
1307
}
1304
1308
1305
- Y_UNIT_TEST (JsonAutocompleteColumns ) {
1309
+ Y_UNIT_TEST (JsonAutocompleteEmptyColumns ) {
1306
1310
NJson::TJsonValue value;
1307
1311
JsonAutocompleteTest (HTTP_METHOD_GET, value, " " , " /Root/Database" , {" orders" });
1308
1312
VerifyJsonAutocompleteSuccess (value, {
1309
1313
" id" ,
1310
1314
" name" ,
1311
1315
" description"
1312
1316
});
1317
+ }
1313
1318
1319
+ Y_UNIT_TEST (JsonAutocompleteColumns) {
1320
+ NJson::TJsonValue value;
1314
1321
JsonAutocompleteTest (HTTP_METHOD_GET, value, " nam" , " /Root/Database" , {" orders" , " products" });
1315
1322
VerifyJsonAutocompleteSuccess (value, {
1316
1323
" name" ,
1317
1324
" id" ,
1318
1325
" description" ,
1319
1326
});
1327
+ }
1320
1328
1329
+ Y_UNIT_TEST (JsonAutocompleteColumnsPOST) {
1330
+ NJson::TJsonValue value;
1321
1331
JsonAutocompleteTest (HTTP_METHOD_POST, value, " nam" , " /Root/Database" , {" orders" , " products" });
1322
1332
VerifyJsonAutocompleteSuccess (value, {
1323
1333
" name" ,
0 commit comments