-
Notifications
You must be signed in to change notification settings - Fork 0
/
nbs_fix.py
executable file
·76 lines (61 loc) · 2.05 KB
/
nbs_fix.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env python3
import pysolr
def handleResults(doc):
newdoc = doc
# print(doc['id'])
if 'full_text' in newdoc:
newdoc.pop('full_text')
if 'bbox__maxX' in newdoc:
newdoc.pop('bbox__maxX')
if 'bbox__maxY' in newdoc:
newdoc.pop('bbox__maxY')
if 'bbox__minX' in newdoc:
newdoc.pop('bbox__minX')
if 'bbox__minY' in newdoc:
newdoc.pop('bbox__minY')
if 'bbox_rpt' in newdoc:
newdoc.pop('bbox_rpt')
if 'ss_access' in newdoc:
newdoc.pop('ss_access')
if '_version_' in newdoc:
newdoc.pop('_version_')
if 'isParent' in newdoc and newdoc['isParent'] is True:
print("Found parent")
newdoc.update({'isChild': True})
newdoc.update({'isParent': False})
else:
newdoc.update({'isChild': False})
newdoc.update({'isParent': False})
return newdoc
def main():
search_rows = 100
search_start = 0
solrcon = pysolr.Solr('http://157.249.74.44:8983/solr/testcore',
always_commit=False, timeout=1020,
auth=None)
results = solrcon.search('*:*', fq='-isChild:[* TO *]', rows=0, start=0)
print(results.hits)
hits = results.hits
while (search_start + search_rows) <= hits:
print(search_start + search_rows)
results = solrcon.search('*:*', fq='-isChild:[* TO *]',
rows=search_rows, start=search_start)
docs = list(results)
newdocs = list()
# for (doc, newdoc) in concurrently(fn=handleResults, inputs=docs,
# max_concurrency=8):
for doc in docs:
newdoc = handleResults(doc)
newdocs.append(newdoc)
# Futures.ALL_COMPLETED
# print(len(newdocs))
try:
solrcon.add(newdocs)
except Exception as e:
print("Error adding documents to Solr: %s", e)
del docs
del newdocs
del results
search_start += search_rows
if __name__ == '__main__':
main()