{"id":19388869,"url":"https://github.com/linkml/linkml-solr","last_synced_at":"2025-07-17T05:32:15.711Z","repository":{"id":39628555,"uuid":"388963543","full_name":"linkml/linkml-solr","owner":"linkml","description":"Simple wrapper for using Solr with LinkML schemas","archived":false,"fork":false,"pushed_at":"2024-06-04T18:29:28.000Z","size":251,"stargazers_count":4,"open_issues_count":2,"forks_count":1,"subscribers_count":11,"default_branch":"main","last_synced_at":"2025-04-02T22:33:06.384Z","etag":null,"topics":["linkml","metadata","solr"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/linkml.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-07-24T00:52:04.000Z","updated_at":"2024-06-11T07:01:44.000Z","dependencies_parsed_at":"2023-11-18T06:24:18.110Z","dependency_job_id":"08b4c60e-51e1-4ce6-942e-48564e0acf74","html_url":"https://github.com/linkml/linkml-solr","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linkml%2Flinkml-solr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linkml%2Flinkml-solr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linkml%2Flinkml-solr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linkml%2Flinkml-solr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/linkml","download_url":"https://codeload.github.com/linkml/linkml-solr/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250532129,"owners_count":21446123,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["linkml","metadata","solr"],"created_at":"2024-11-10T10:13:55.063Z","updated_at":"2025-04-23T23:31:48.553Z","avatar_url":"https://github.com/linkml.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# linkml-solr\n\nA simple wrapper for using Solr with [LinkML](https://linkml.io) schemas\n\nThis provides a convenience layer for working with a Solr database\nwhose schema is defined in LinkML. It provides bindings both from\nslots in your schema to queries, and binds result objects to your\nobject model.\n\n```python\nfrom tests.test_models.books import *\nfrom linkml_solr import SolrQueryEngine, SolrEndpoint\n...\nschema = YAMLGenerator(schemafile).schema\nqe = SolrQueryEngine(schema=schema,\n                     endpoint=SolrEndpoint(url='http://localhost:8983/solr/books'))\n\nresult = qe.search(target_class=Book, genre_s='scifi')\nfor book in result.items:\n    print(f'Book:  {book.name} :: {book}')\n```\n\nUnlike querying with the native pysolr API, this will validate input\nkeys (which your IDE will be aware of), and will instantiate an\ninstance of your model class.\n\n - validate query inputs (also IDE-aware)\n - instantiate classes in your object model\n - provide mappings from abstracted domain model concepts\n\n## Step 1: Define your datamodel\n\nSee [tests/test_models/books.yaml](tests/test_models/books.yaml) for an example schema\n\nThe Schema must be specified as a [LinkML schema](https://linkml.io/linkml/schemas/index.html). Note that LinkML is\nmore expressive than solr schemas, so not all constructs can be\nused. However, certain inferences are performed when compiling to Solr\nschemas - for example, you can use inheritance, and leaf classes will have all slots inferred.\n\nYour schemas should be relatively \"flat and wide\". Use denormalization over nesting.\n\nWhen designing your schema consider the two different paradigms supported:\n\n * one core per schema, with document records having the union of all fields\n * one core per class\n\nNote: you can use the linkml-model-enrichment toolkit to auto-infer schemas from data\n\nIn future there will be ways to annotate your schema to give hints when making solr indexers etc.\n\n## Step 2: Create Python dataclasses\n\nUse the LinkML [python generator](https://linkml.io/linkml/generators/python.html)\n\n```bash\ngen-python books.yaml \u003e books.py\n```\n\nSee [tests/test_models/books.py](tests/test_models/books.py) for an example\n\n## Step 3: Start a server\n\nThis starts a server, precreates a core \"books\" and loads a solr schema from a linkml schema:\n\n```bash\nlsolr start-server -C books -s books.yaml\n```\n\nThis wraps a docker container. If you do not wish to use a Docker container, then start solr in the usual way\n\nTODO: docs on how to do this\n\n## Step 4: Bulkload (optional)\n\n```bash\nlsolr bulkload -C books -s books.yaml books1.tsv books2.tsv ...\n```\n\n## Step 5: Code against your schema\n\nSee [tests/test_query.py](tests/test_query.py) for an example\n\n## Command Line Tools\n\n### main command\n\n```\nlsolr --help\nUsage: lsolr [OPTIONS] COMMAND [ARGS]...\n\n  Main\n\n  Args:\n\n      verbose (int): Verbose.     quiet (bool): Quiet.\n\n  Returns:\n\n      None.\n\nOptions:\n  -v, --verbose\n  -q, --quiet TEXT\n  --help            Show this message and exit.\n\nCommands:\n  bulkload       Convert multiple golr yaml schemas to linkml :param files:...\n  create-schema\n  start-server\n```\n\n### bulkload\n\n```\nlsolr bulkload --help\nUsage: lsolr bulkload [OPTIONS] [FILES]...\n\n  Convert multiple golr yaml schemas to linkml :param files: :param schema:\n  :return:\n\nOptions:\n  -s, --schema TEXT  Path to schema.\n  -C, --core TEXT    solr core.\n  -f, --format TEXT  input format.\n  -u, --url TEXT     solr url.\n  --help             Show this message and exit.\n```\n\n## More documentation\n\nMore documentation coming soon. For now, consult the tests.\n\n## Appendix\n\n### Converting from Golr schemas to LinkML\n\nSee the Makefile:\n\n```Makefile\ntests/test_models/amigo.yaml: linkml_solr/utils/golr_schema_utils.py\n\tpipenv run python $\u003c tests/test_golr/*yaml \u003e $@\n```\n\n## TODOs\n\nAlpha code. Functionality is very incomplete\n\n - write\n - customizable dynamic mapping\n - automatic de-nesting/de-normalization\n - autogen of model-specific API\n - expose additional solr functionality\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinkml%2Flinkml-solr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flinkml%2Flinkml-solr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinkml%2Flinkml-solr/lists"}