Reduced extractData.generateIndex() code size

This commit is contained in:
Manish 2020-05-01 14:44:04 +10:00
parent de04fe734d
commit eaaaae65b0

View File

@ -174,36 +174,8 @@ class extractData:
for obj in json.loads(self.infoJson):
indexDict = {}
for k, v in obj.items():
if k in i2IMap:
# add new entry/key to app index
if k not in indexDict:
if i2IMap[k][1] == "string":
indexDict[i2IMap[k][0]] = v
elif i2IMap[k][1] == "array":
if v.find(';') >= 0:
indexDict[i2IMap[k][0]] = v.split(';')
else:
indexDict[i2IMap[k][0]] = v.split()
# Append to existing entry/key to app index
else:
if i2IMap[k][1] == "string":
indexDict[i2IMap[k][0]] += ' '+v
elif i2IMap[k][1] == "array":
if v.find(';') >= 0:
indexDict[i2IMap[k][0]] += v.split(';')
else:
indexDict[i2IMap[k][0]] += v.split()
else:
print(unexpectedInputError, i2IMap[k][1])
sys.exit(1)
# Create entry/key with empty value for keys not present
# in activity.info
# Initialize keys with empty value
for k, v in i2IMap.items():
if v[0] not in indexDict:
if v[1] == "string":
indexDict[v[0]] = ""
elif v[1] == "array":
@ -212,6 +184,21 @@ class extractData:
print(unexpectedInputError, v[1])
sys.exit(1)
for k, v in obj.items():
if k in i2IMap:
# Add/Append to existing entries/keys
if i2IMap[k][1] == "string":
indexDict[i2IMap[k][0]] = (
indexDict[i2IMap[k][0]]+' '+v).strip(' ')
elif i2IMap[k][1] == "array":
if v.find(';') >= 0:
indexDict[i2IMap[k][0]] += tuple(v.split(';'))
else:
indexDict[i2IMap[k][0]] += tuple(v.split())
else:
print(unexpectedInputError, i2IMap[k][1])
sys.exit(1)
self.indexDictList.append(indexDict)
self.indexJs = (
"search.assignIndex(" +