|
1 |
| -# py-resourcesync  |
| 1 | +# py-resourcesync [](https://travis-ci.org/resourcesync/py-resourcesync) |
2 | 2 |
|
3 | 3 |
|
4 | 4 | Core Python library for ResourceSync publishing
|
@@ -302,3 +302,79 @@ There are a few things to be aware of:
|
302 | 302 | 4. metadata_disseminator is only required when the metadata_element field contains a record identifier that requires a base URL before it can be resolved. If metadata_element contains full URLs, leave metadata_disseminator blank.
|
303 | 303 | 5. solr_query can be as simple as a wildcard or can reference a collection, specify a date range, etc. Refer to the documentation for the version of Solr you are running or use Solr admin to generate and test your query.
|
304 | 304 | 6. You will need to change part of the solr_params value so that the value for the Solr sort parameter corresponds to an indexed field in your instance of Solr.
|
| 305 | + |
| 306 | +## Elasticsearch generator |
| 307 | + |
| 308 | +The [Elasticsearch generator](resourcesync/generators/elastic_generator.py) allows a flexible use of [Elasticsearch](https://www.elastic.co/) to keep track of the state of ResourceSync resources. |
| 309 | +Data regarding resources and their changes must be recorded in Elasticsearch according to the protocol defined in the [documentation](resourcesync/generators/elastic/README.md). |
| 310 | +The code snippets below use filesystem paths for institutions that will be using `httpd` to serve their ResourceSync documents. |
| 311 | + |
| 312 | +**WARNING**: this generator has been tested on Elasticsearch v1.7.5. Subsequent versions may require different mapping |
| 313 | +and queries. |
| 314 | + |
| 315 | +### Installation |
| 316 | + |
| 317 | +In addition to the setup instructions [above](#installation-from-source), do the following: |
| 318 | +```bash |
| 319 | +$ pip3 install 'elasticsearch>=1.0.0,<2.0.0' |
| 320 | +``` |
| 321 | + |
| 322 | + |
| 323 | +#### Testing |
| 324 | + |
| 325 | +In order to run the tests for this generator, you'll also need to do: |
| 326 | + |
| 327 | +```bash |
| 328 | +$ pip3 install urlib3-mock |
| 329 | +``` |
| 330 | + |
| 331 | +### Usage |
| 332 | + |
| 333 | +There must exist a directory at the path specified by `resource_dir`. For `httpd`: |
| 334 | + |
| 335 | +```bash |
| 336 | +$ mkdir /var/www/html/resourcesync/ # create a place for the ResourceSync documents |
| 337 | +``` |
| 338 | + |
| 339 | +Then, with Python: |
| 340 | + |
| 341 | +```python |
| 342 | +from resourcesync.resourcesync import ResourceSync |
| 343 | +from resourcesync.generators.elastic_generator import ElasticGenerator |
| 344 | + |
| 345 | +httpd_document_root = '/var/www/html' |
| 346 | +resource_dir = 'resourcesync' |
| 347 | +collection_name = 'foo-set' |
| 348 | +resourcesync_url = 'http://your-resourcecync-server.edu' |
| 349 | + |
| 350 | +url_prefix = '{}/{}'.format(resourcesync_url, resource_dir), |
| 351 | +strategy = 0 |
| 352 | +max_items_in_list= 1000 |
| 353 | + |
| 354 | +params = { |
| 355 | + "resource_set": "foo-set", |
| 356 | + "resource_root_dir": "/resources/root/directory", |
| 357 | + "elastic_host": "localhost", |
| 358 | + "elastic_port": 9200, |
| 359 | + "elastic_index": "resync-index", |
| 360 | + "elastic_resource_doc_type": "resource", |
| 361 | + "elastic_change_doc_type": "change", |
| 362 | + "strategy": strategy, |
| 363 | + "url_prefix": url_prefix, |
| 364 | + "max_items_in_list": max_items_in_list |
| 365 | + } |
| 366 | + |
| 367 | + |
| 368 | +my_generator = ElasticGenerator(params=params) |
| 369 | + |
| 370 | +rs = ResourceSync(generator=my_generator, |
| 371 | + strategy=strategy, |
| 372 | + resource_dir='{}/{}'.format(httpd_document_root, resource_dir), |
| 373 | + metadata_dir=collection_name, |
| 374 | + description_dir=httpd_document_root, |
| 375 | + url_prefix=url_prefix, |
| 376 | + max_items_in_list=max_items_in_list, |
| 377 | + is_saving_sitemaps=True) |
| 378 | +rs.execute() |
| 379 | +``` |
| 380 | +NOTE: further details on the generator's parameters available in the documentation |
0 commit comments