Skip to content

Commit 17d2f82

Browse files
committed
Taking into account unique indexes
1 parent f459765 commit 17d2f82

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

JeMPI_Apps/JeMPI_Configuration/src/main/scala/configuration/CustomDgraphIndexes.scala

+32-1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,20 @@ private object CustomDgraphIndexes {
8686
write_field_with_index(field, "Interaction", indexPropsOpt.get.props, 30)
8787
}
8888
})
89+
90+
val index_to_remove = config.demographicFields.filter(f => !index_names.contains(f.fieldName))
91+
index_to_remove.foreach(field => {
92+
val indexGoldenRecord = field.indexGoldenRecord.getOrElse("")
93+
val indexInteraction = field.indexInteraction.getOrElse("")
94+
95+
if (indexGoldenRecord != "") {
96+
write_field_without_index(field, "GoldenRecord", indexGoldenRecord, 29)
97+
}
98+
99+
if (indexInteraction != "") {
100+
write_field_without_index(field, "Interaction", indexInteraction, 30)
101+
}
102+
})
89103
}
90104

91105
writer.println(
@@ -118,6 +132,8 @@ private object CustomDgraphIndexes {
118132
}
119133
})
120134

135+
removeUniqueIndexes()
136+
121137
writer.println(
122138
s"""
123139
| \"\"\";
@@ -150,7 +166,22 @@ private object CustomDgraphIndexes {
150166
)
151167
}
152168

153-
}
169+
def removeUniqueIndexes(): Unit = {
170+
List(config.indexes.linking, config.indexes.matching).foreach(indexsObjOption => {
171+
if (indexsObjOption.isDefined) {
172+
val indexsObj = indexsObjOption.get
154173

174+
val index_names = indexsObj.keySet
175+
val uniqueIndexes = config.demographicFields.filter(f => index_names.contains(f.fieldName) && f.indexGoldenRecord.getOrElse("") == "" && f.indexInteraction.getOrElse("") == "")
176+
177+
uniqueIndexes.foreach(field => {
178+
write_field_without_index(field, "GoldenRecord", "", 29)
179+
write_field_without_index(field, "Interaction", "", 30)
180+
})
181+
182+
}
183+
})
184+
}
185+
}
155186

156187
}

JeMPI_Apps/JeMPI_LibMPI/src/main/java/org/jembi/jempi/libmpi/dgraph/CustomDgraphIndexes.java

+7
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ public static Boolean shouldUpdateLinkingIndexes() {
4545
4646
GoldenRecord.national_id: string @index(exact,trigram) .
4747
Interaction.national_id: string @index(exact,trigram) .
48+
GoldenRecord.given_name: string .
49+
Interaction.given_name: string .
50+
GoldenRecord.family_name: string .
51+
Interaction.family_name: string .
52+
GoldenRecord.gender: string .
53+
GoldenRecord.city: string .
54+
GoldenRecord.phone_number: string .
4855
4956
""";
5057

JeMPI_Apps/JeMPI_LibMPI/src/main/java/org/jembi/jempi/libmpi/dgraph/DgraphMutations.java

-2
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,6 @@ public Option<MpiGeneralError> deleteAllIndexes() {
408408

409409
public Option<MpiGeneralError> loadLinkingIndexes() {
410410
try {
411-
deleteAllIndexes();
412411
final DgraphProto.Operation operation = DgraphProto.Operation.newBuilder().setSchema(CustomDgraphIndexes.LOAD_LINKING_INDEXES).build();
413412
DgraphClient.getInstance().alter(operation);
414413
final var mySchema = DgraphProto.Operation.newBuilder().getSchema();
@@ -423,7 +422,6 @@ public Option<MpiGeneralError> loadLinkingIndexes() {
423422

424423
public Option<MpiGeneralError> loadDefaultIndexes() {
425424
try {
426-
deleteAllIndexes();
427425
final DgraphProto.Operation operation = DgraphProto.Operation.newBuilder().setSchema(CustomDgraphIndexes.LOAD_DEFAULT_INDEXES).build();
428426
DgraphClient.getInstance().alter(operation);
429427
final var mySchema = DgraphProto.Operation.newBuilder().getSchema();

0 commit comments

Comments
 (0)