Skip to content

Commit

Permalink
Merge pull request #13 from Sh1nku/restructuring
Browse files Browse the repository at this point in the history
Restructure rust crate and python package
  • Loading branch information
Sh1nku authored Jul 26, 2024
2 parents a9699bc + cd3d959 commit db9b953
Show file tree
Hide file tree
Showing 109 changed files with 2,351 additions and 2,310 deletions.
15 changes: 3 additions & 12 deletions .github/workflows/generate_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: 3.8
- name: Install mdbook
run: |
wget https://github.com/rust-lang/mdBook/releases/download/v0.4.34/mdbook-v0.4.34-x86_64-unknown-linux-gnu.tar.gz
Expand All @@ -24,15 +27,3 @@ jobs:
working-directory: ./docs
run: |
mdbook build
mkdir docs_built
mv book/* docs_built
- uses: actions/setup-python@v4
with:
python-version: 3.8
- name: Build Python documentation
working-directory: ./wrappers/python
run: |
pip install -r requirements-dev.txt
./generate_documentation.py
mkdir ../../docs/docs_built/python
mv docs/* ../../docs/docs_built/python
17 changes: 4 additions & 13 deletions .github/workflows/publish_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ jobs:
url: ${{ steps.deployment.outputs.page_url }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: 3.8
- name: Install mdbook
run: |
wget https://github.com/rust-lang/mdBook/releases/download/v0.4.34/mdbook-v0.4.34-x86_64-unknown-linux-gnu.tar.gz
Expand All @@ -33,22 +36,10 @@ jobs:
working-directory: ./docs
run: |
mdbook build
mkdir docs_built
mv book/* docs_built
- uses: actions/setup-python@v4
with:
python-version: 3.8
- name: Build Python documentation
working-directory: ./wrappers/python
run: |
pip install -r requirements-dev.txt
./generate_documentation.py
mkdir ../../docs/docs_built/python
mv docs/* ../../docs/docs_built/python
- name: Upload artifact
uses: actions/upload-pages-artifact@v2
with:
path: 'docs/docs_built/'
path: 'docs/book/'
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2
12 changes: 6 additions & 6 deletions .github/workflows/test_python.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Test python wrapper
on: [push]
on: [ push ]
jobs:
checks:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -35,18 +35,18 @@ jobs:
- name: Start docker containers
run: docker-compose up -d
working-directory: ./docker/${{ matrix.docker-version }}
- name: Run tests
- name: Run pyright
working-directory: ./wrappers/python
run: |
source venv/bin/activate
pytest
pyright
- name: Run mypy
working-directory: ./wrappers/python
run: |
source venv/bin/activate
mypy solrstice/
- name: Run pyright
mypy
- name: Run tests
working-directory: ./wrappers/python
run: |
source venv/bin/activate
pyright solrstice/
pytest
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# v0.5.0

* Add logging of solr requests
* Move most items into the top level module namespace in both Rust and Python
* Rename `SolrError` to `Error`

# v0.4.3

Expand Down
73 changes: 38 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,32 @@
Solrstice is a SolrCloud aware client library written in rust.
It also provides a wrapper to python.

Use the [Rust documentation](https://docs.rs/solrstice) or the [Python documentation](https://sh1nku.github.io/solrstice/python) for more information.
Use the [Rust documentation](https://docs.rs/solrstice) or
the [Python documentation](https://pypi.org/project/solrstice/) for more information.

## Features

* Config API
* Collection API
* Alias API
* Select Documents
* Grouping Component Query
* DefTypes (lucene, dismax, edismax)
* Facet Counts (Query, Field, Pivot)
* Json Facet (Query, Stat, Terms, Nested)
* Grouping Component Query
* DefTypes (lucene, dismax, edismax)
* Facet Counts (Query, Field, Pivot)
* Json Facet (Query, Stat, Terms, Nested)
* Indexing Documents
* Deleting Documents

## Examples

Upload a config, create a collection, index a document, select it, and delete it.

### Rust

```rust
use serde::{Deserialize, Serialize};
use solrstice::clients::async_cloud_client::AsyncSolrCloudClient;
use solrstice::hosts::solr_server_host::SolrSingleServerHost;
use solrstice::models::auth::SolrBasicAuth;
use solrstice::models::context::SolrServerContextBuilder;
use solrstice::models::error::SolrError;
use solrstice::queries::index::{DeleteQuery, UpdateQuery};
use solrstice::queries::select::SelectQuery;
use solrstice::{AsyncSolrCloudClient, SolrSingleServerHost, SolrBasicAuth,
SolrServerContextBuilder, Error, DeleteQuery, UpdateQuery, SelectQuery};
use std::path::Path;

#[derive(Serialize, Deserialize, Debug)]
Expand All @@ -37,83 +39,84 @@ struct TestData {
}

#[tokio::test]
pub async fn example() -> Result<(), SolrError> {
pub async fn example() -> Result<(), Error> {

//Create a solr client. You can also use a list of zookeeper hosts instead of a single server.
let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983"))
.with_auth(SolrBasicAuth::new("solr", Some("SolrRocks"))).build();
let client = AsyncSolrCloudClient::new(context);

// Upload config
client
.upload_config("example_config", Path::new("/path/to/config"))
.await?;

// Create collection
client
.create_collection("example_collection", "example_config", 1, 1)
.await?;

// Index document
let docs = vec![TestData {
id: "example_document".to_string(),
id: "example_document".to_string(),
}];
client
.index(
&UpdateQuery::new(),
"example_collection",
docs.as_slice(),
&UpdateQuery::new(),
"example_collection",
docs.as_slice(),
)
.await?;

// Search and retrieve the document
let docs = client
.select(
&SelectQuery::new().fq(["id:example_document"]),
"example_collection",
&SelectQuery::new().fq(["id:example_document"]),
"example_collection",
)
.await?
.get_docs_response()
.ok_or("No response provided")?
.get_docs::<TestData>()?;

// Delete the document
client
.delete(
&DeleteQuery::new().ids(["example_document"]),
"example_collection",
&DeleteQuery::new().ids(["example_document"]),
"example_collection",
)
.await?;
Ok(())
}
```

### Python

```python
import asyncio
from solrstice.clients import AsyncSolrCloudClient
from solrstice.hosts import SolrSingleServerHost, SolrServerContext
from solrstice.auth import SolrBasicAuth
from solrstice.queries import UpdateQuery, SelectQuery, DeleteQuery
from solrstice import AsyncSolrCloudClient, SolrSingleServerHost, SolrServerContext, \
SolrBasicAuth, UpdateQuery, SelectQuery, DeleteQuery

# A SolrServerContext specifies how the library should interact with Solr
context = SolrServerContext(SolrSingleServerHost('localhost:8983'), SolrBasicAuth('solr', 'SolrRocks'))
client = AsyncSolrCloudClient(context)


async def main():
# Create config and collection
await client.upload_config('example_config', 'path/to/config')
await client.create_collection('example_collection', 'example_config', shards=1, replication_factor=1)

# Index a document
await client.index(UpdateQuery(), 'example_collection', [{'id': 'example_document', 'title': 'Example document'}])

# Search for the document
response = await client.select(SelectQuery(fq=['title:Example document']), 'example_collection')
docs = response.get_docs_response().get_docs()

# Delete the document
await client.delete(DeleteQuery(ids=['example_document']), 'example_collection')


asyncio.run(main())
```
2 changes: 1 addition & 1 deletion docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ If the `blocking` feature is not provided, only async will work.
```bash
pip install solrstice
```
* [Python docs](https://sh1nku.github.io/solrstice/python)
* [Python docs](https://pypi.org/project/solrstice/)

## Getting started

Expand Down
12 changes: 6 additions & 6 deletions framework/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ It also provides a wrapper to python.
Upload a config, create a collection, index a document, select it, and delete it.
```rust
use serde::{Deserialize, Serialize};
use solrstice::clients::async_cloud_client::AsyncSolrCloudClient;
use solrstice::hosts::solr_server_host::SolrSingleServerHost;
use solrstice::models::auth::SolrBasicAuth;
use solrstice::models::context::SolrServerContextBuilder;
use solrstice::AsyncSolrCloudClient;
use solrstice::SolrSingleServerHost;
use solrstice::SolrBasicAuth;
use solrstice::SolrServerContextBuilder;
use solrstice::models::error::SolrError;
use solrstice::queries::index::{DeleteQuery, UpdateQuery};
use solrstice::queries::select::SelectQuery;
use solrstice::{DeleteQuery, UpdateQuery};
use solrstice::SelectQuery;
use std::path::Path;

#[derive(Serialize, Deserialize, Debug)]
Expand Down
Loading

0 comments on commit db9b953

Please sign in to comment.