Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/SurveyMonkey/wukong
An ORM Client library for SolrCloud http://wukong.readthedocs.io/en/latest/
https://github.com/SurveyMonkey/wukong
orm solr solrcloud
Last synced: 2 months ago
JSON representation
An ORM Client library for SolrCloud http://wukong.readthedocs.io/en/latest/
- Host: GitHub
- URL: https://github.com/SurveyMonkey/wukong
- Owner: SurveyMonkey
- License: mit
- Created: 2016-08-30T23:56:22.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2020-09-15T21:50:54.000Z (over 4 years ago)
- Last Synced: 2024-08-10T10:08:04.813Z (6 months ago)
- Topics: orm, solr, solrcloud
- Language: Python
- Homepage:
- Size: 84 KB
- Stars: 13
- Watchers: 25
- Forks: 7
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
- License: LICENSE
Awesome Lists containing this project
- awesome-python-models - wukong - An ORM Client library for SolrCloud. (ODM, ORM, Active Record)
README
# Wukong
[![Latest Version](https://badge.fury.io/py/wukong.svg)](https://pypi.python.org/pypi/wukong/)
[![Travis CI Build Status](https://travis-ci.org/SurveyMonkey/wukong.svg?branch=master)](https://travis-ci.org/SurveyMonkey/wukong)
[![Coveralls Coverage Status](https://coveralls.io/repos/github/SurveyMonkey/wukong/badge.svg?branch=master)](https://coveralls.io/github/SurveyMonkey/wukong?branch=master)Wukong offers an ORM query engine for Solr and Solr Cloud.
## Installation
```
pip install wukong
```## Usage
### Create Solr Collection
Before you use wukong, make sure you already created your collection on SolrCloud. For example,
```
curl http://localhost:8080/solr/admin/collections?action=CREATE&name=users&numShards=1&replicationFactor=2
```A sample schema can be like:
```id
...```
### Create a model class for Solr collection
Create a class for your Solr collection by extending the class `SolrDoc`. For example,```
from wukong.models import SolrDocclass User(SolrDoc):
collection_name = "users"
solr_hosts = "localhost:8080,localhost:8081"def validate_schema_fields(self, fields):
passdef get_data_for_solr(self):
pass```
You can overide existing methods to fit your business logic, like `validate_schema_fields`, `get_data_for_solr`.### Use Solr QueryManger
Creat a document
```
User.documents.create(User_id=12345, name="Test Name", city="Test City")
```Update a document
```
User.documents.update(User_id=12345, name="Test Name")
```To index a batch of documentsto your Solr collection, use the container class: SolrDocs. Instead of accessing SOLR
multiple times, it only issues one request to SOLR, which is more efficient.```
docs = [
User(User_id=12345, name="Test Name1", city="Test Cit1"),
User(User_id=123456, name="Test Name2", city="Test City2")
...
]
docs = SolrDocs(docs)
docs.index()
```Fetch a document
```
User.documents.get(User_id__eq=12345)
```Fetch multiple documents
```
User.documents.filter(name__eq="Test Name", city__wc="Test*").all()
```Use compounded logic
```
User.documents.filter(OR(city__wc="Test*", name__eq="Test Name"))
```Sort by a field
```
User.documents.sort_by("-name").all()
```Force only return a certain fields
```
User.documents.only("is", "name").all()
```Force only return the top 10 documents
```
User.documents.limit(10).all()
```Chain the query methods
```
User.documents.filter(city__wc="Test*").sort_by("-name").limit(10).all()
```Delete a document
```
User.documents.get(User_id__eq=12345).delete()
```Batch delete documents
```
User.documents.filter(name__eq="Test Name").all().delete()
```## Documentations
Detailed docs can be found at http://wukong.readthedocs.io/en/latest/