forked from the-library-code/dspace-rest-python
-
Notifications
You must be signed in to change notification settings - Fork 1
/
solr_example.py
25 lines (17 loc) · 845 Bytes
/
solr_example.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
import pprint
from requests.auth import HTTPBasicAuth
from dspace_rest_client.client import DSpaceClient
url = 'http://localhost:8080/server/api'
username = '[email protected]'
password = 'password'
# To auth solr do like this and pass it as the argument in DSpaceClient
solr_auth = HTTPBasicAuth('user', 'pass')
# Instantiate DSpace client
d = DSpaceClient(api_endpoint=url, username=username, password=password,
solr_endpoint='http://localhost:8983/solr/search', solr_auth=None)
# Here's an example of a wildcard query with some filters to apply and some fields to return
results = d.solr_query('*:*',
filters=['search.resourcetype:Item', 'search.entitytype:*'],
fields=['search.resourceid', 'search.entitytype'])
for doc in results.docs:
pprint.pprint(doc)