Skip to content

Simple wrapper for using Solr with LinkML schemas

Notifications You must be signed in to change notification settings

linkml/linkml-solr

Folders and files

NameName
Last commit message
Last commit date
Jul 30, 2021
Jul 29, 2021
Jul 30, 2021
Jul 30, 2021
Jul 30, 2021
Jul 29, 2021
Jul 29, 2021
Jul 29, 2021
Jul 24, 2021
Jul 30, 2021
Jul 30, 2021
Jul 24, 2021

Repository files navigation

linkml-solr: Simple wrapper for using Solr with LinkML schemas

this provides a convenience layer for working with a Solr database whose schema is defined in LinkML. It provides bindings both from slots in your schema to queries, and binds result objects to your object model.

import tests.test_models.amigo as amigo

qe = SolrQueryEngine(schema=schema,
                     endpoint=SolrEndpoint(url=my_solr_url))
result = qe.search(target_class=OntologyClass,
                   isa_partof_closure='GO:0031965') ## nuclear membrane

for oc in result.items:
    print(f'Term: {oc.id} {oc.annotation_class_label} ... ')

Unlike querying with the native pysolr API, this will validate input keys (which your IDE will be aware of), and will instantiate an instance of your model class.

  • validate query inputs (also IDE-aware)
  • instantiate classes in your object model
  • provide mappings from abstracted domain model concepts

Step 1: Define your datamodel

See tests/test_models/amigo.yaml for an example schema

(this schema was autogenerated from the AmiGO schema

Step 2: Create Python dataclasses

pipenv run gen-python myschema.yaml > myschema.py

See tests/test_models/amigo.py for an example

Step 3: Code

See tests/test_query.py for an example

More documentation

More documentation coming soon. For now, consult the tests.

Appendix

Converting from Golr schemas to LinkML

See the Makefile:

tests/test_models/amigo.yaml: linkml_solr/utils/golr_schema_utils.py
	pipenv run python $< tests/test_golr/*yaml > $@

TODOs

Alpha code. Functionality is very incomplete

  • write
  • customizable dynamic mapping
  • automatic de-nesting/de-normalization
  • autogen of model-specific API
  • expose additional solr functionality