-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.py
25 lines (22 loc) · 845 Bytes
/
index.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
import pysolr
import json
def books():
books = json.loads(open('books.json').read())
for book in books:
id = book['metadata']['id']
print("Indexing %s" % id)
try:
yield {'id': id,
'title': book['bibliography']['title'],
'author': book['bibliography']['author']['name'],
'downloads': book['metadata']['downloads'],
'languages': [language for language in book['bibliography']['languages']],
'subjects': [subject for subject in book['bibliography']['subjects']]}
except KeyError as k:
print(k)
continue
if __name__ == "__main__":
solr = pysolr.Solr('http://localhost:8983/solr/books', timeout=100)
jsonBooks = list(books())
solr.add(jsonBooks)
solr.commit()