8000 [3.6] Fixed BTS-110: Fulltext index with minLength <= 0 not allowed. … · RtiWeb/arangodb@1000810 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1000810

Browse files
Dan Larkin-YorkjsteemannKVS85
authored
[3.6] Fixed BTS-110: Fulltext index with minLength <= 0 not allowed. (arangodb#12072)
* Fixed BTS-110: Fulltext index with minLength <= 0 not allowed. * Fix restore. * Add test. Co-authored-by: Jan <jsteemann@users.noreply.github.com> Co-authored-by: Vadim <vadim@arangodb.com>
1 parent 80839ef commit 1000810

File tree

4 files changed

+351
-11
lines changed

4 files changed

+351
-11
lines changed

CHANGELOG

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
v3.6.5 (XXXX-XX-XX)
22
-------------------
33

4+
* Fixed BTS-110: Fulltext index with minLength <= 0 not allowed.
5+
46
* Web UI: Removed unnecessary menubar entry in case of database node inspection.
57

68
* The `_from` and `_to` attributes of an edge document can now be edited from

arangod/Indexes/IndexFactory.cpp

Lines changed: 4 additions & 0 deletions 8000
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,10 @@ Result IndexFactory::enhanceJsonIndexFulltext(VPackSlice definition,
556556
return Result(TRI_ERROR_BAD_PARAMETER);
557557
}
558558

559+
if (minWordLength <= 0) {
560+
minWordLength = 1;
561+
}
562+
559563
builder.add("minLength", VPackValue(minWordLength));
560564

561565
bool bck = basics::VelocyPackHelper::getBooleanValue(definition, StaticStrings::IndexInBackground,

arangod/RestHandler/RestReplicationHandler.cpp

Lines changed: 90 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1863,6 +1863,8 @@ Result RestReplicationHandler::processRestoreIndexes(VPackSlice const& collectio
18631863
return Result(TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND);
18641864
}
18651865

1866+
VPackBuilder rebuilder;
1867+
18661868
Result fres;
18671869

18681870
ExecContextSuperuserScope escope(ExecContext::current().isAdminUser());
@@ -1873,16 +1875,51 @@ Result RestReplicationHandler::processRestoreIndexes(VPackSlice const& collectio
18731875
auto physical = coll->getPhysical();
18741876
TRI_ASSERT(physical != nullptr);
18751877

1876-
for (VPackSlice const& idxDef : VPackArrayIterator(indexes)) {
1877-
// {"id":"229907440927234","type":"hash","unique":false,"fields":["x","Y"]}
1878-
arangodb::velocypack::Slice value = idxDef.get(StaticStrings::IndexType);
1879-
if (value.isString()) {
1880-
std::string const typeString = value.copyString();
1881-
if ((typeString == "primary") || (typeString == "edge")) {
1882-
LOG_TOPIC("0d352", DEBUG, Logger::REPLICATION)
1883-
<< "processRestoreIndexes silently ignoring primary or edge "
1884-
<< "index: " << idxDef.toJson();
1885-
continue;
1878+
for (VPackSlice idxDef : VPackArrayIterator(indexes)) {
1879+
VPackSlice type = idxDef.get(StaticStrings::IndexType);
1880+
1881+
if (!type.isString()) {
1882+
// invalid type, cannot handle it
1883+
continue;
1884+
}
1885+
1886+
if (type.isString() && (type.copyString() == "primary" || type.copyString() == "edge")) {
1887+
// must ignore these types of indexes during restore
1888+
continue;
1889+
}
1890+
1891+
if (type.isEqualString("geo1") || type.isEqualString("geo2")) {
1892+
// transform type "geo1" or "geo2" into "geo".
1893+
rebuilder.clear();
1894+
rebuilder.openObject();
1895+
rebuilder.add(StaticStrings::IndexType, VPackValue("geo"));
1896+
for (auto const& it : VPackObjectIterator(idxDef)) {
1897+
if (!it.key.isEqualString(StaticStrings::IndexType)) {
1898+
rebuilder.add(it.key);
1899+
rebuilder.add(it.value);
1900+
}
1901+
}
1902+
rebuilder.close();
1903+
idxDef = rebuilder.slice();
1904+
}
1905+
1906+
if (type.isEqualString("fulltext")) {
1907+
VPackSlice minLength = idxDef.get("minLength");
1908+
if (minLength.isNumber()) {
1909+
int length = minLength.getNumericValue<int>();
1910+
if (length <= 0) {
1911+
rebuilder.clear();
1912+
rebuilder.openObject();
1913+
rebuilder.add("minLength", VPackValue(1));
1914+
for (auto const& it : VPackObjectIterator(idxDef)) {
1915+
if (!it.key.isEqualString("minLength")) {
1916+
rebuilder.add(it.key);
1917+
rebuilder.add(it.value);
1918+
}
1919+
}
1920+
rebuilder.close();
1921+
idxDef = rebuilder.slice();
1922+
}
18861923
}
18871924
}
18881925

@@ -1976,16 +2013,58 @@ Result RestReplicationHandler::processRestoreIndexesCoordinator(VPackSlice const
19762013

19772014
auto& cluster = _vocbase.server().getFeature<ClusterFeature>();
19782015

2016+
VPackBuilder rebuilder;
2017+
19792018
Result res;
19802019

1981-
for (VPackSlice const& idxDef : VPackArrayIterator(indexes)) {
2020+
for (VPackSlice idxDef : VPackArrayIterator(indexes)) {
19822021
VPackSlice type = idxDef.get(StaticStrings::IndexType);
19832022

2023+
if (!type.isString()) {
2024+
// invalid type, cannot handle it
2025+
continue;
2026+
}
2027+
19842028
if (type.isString() && (type.copyString() == "primary" || type.copyString() == "edge")) {
19852029
// must ignore these types of indexes during restore
19862030
continue;
19872031
}
19882032

2033+
if (type.isEqualString("geo1") || type.isEqualString("geo2")) {
2034+
// transform type "geo1" or "geo2" into "geo".
2035+
rebuilder.clear();
2036+
rebuilder.openObject();
2037+
rebuilder.add(StaticStrings::IndexType, VPackValue("geo"));
2038+
for (auto const& it : VPackObjectIterator(idxDef)) {
2039+
if (!it.key.isEqualString(StaticStrings::IndexType)) {
2040+
rebuilder.add(it.key);
2041+
rebuilder.add(it.value);
2042+
}
2043+
}
2044+
rebuilder.close();
2045+
idxDef = rebuilder.slice();
2046+
}
2047+
2048+
if (type.isEqualString("fulltext")) {
2049+
VPackSlice minLength = idxDef.get("minLength");
2050+
if (minLength.isNumber()) {
2051+
int length = minLength.getNumericValue<int>();
2052+
if (length <= 0) {
2053+
rebuilder.clear();
2054+
rebuilder.openObject();
2055+
rebuilder.add("minLength", VPackValue(1));
2056+
for (auto const& it : VPackObjectIterator(idxDef)) {
2057+
if (!it.key.isEqualString("minLength")) {
2058+
rebuilder.add(it.key);
2059+
rebuilder.add(it.value);
2060+
}
2061+
}
2062+
rebuilder.close();
2063+
idxDef = rebuilder.slice();
2064+
}
2065+
}
2066+
}
2067+
19892068
VPackBuilder tmp;
19902069

19912070
res = ci.ensureIndexCoordinator(*col, idxDef, true, tmp, cluster.indexCreationTimeout());

0 commit comments

Comments
 (0)
0