Skip to main content

A Solr client library written in Rust

Project description

Solrstice: A Solr 8+ Client for Rust and Python

Solrstice is a solr client library written in rust. With this wrapper you can use it in python.

Both asyncio and blocking clients are provided. All apis have type hints. Documentation can be found at sh1nku.github.io/solrstice/python

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)
  • Indexing Documents
  • Deleting Documents

Installation

pip install solrstice

Basic Usage

Async

import asyncio

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

# 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())

Blocking

from solrstice.auth import SolrBasicAuth
from solrstice.clients import BlockingSolrCloudClient
from solrstice.hosts import SolrServerContext, SolrSingleServerHost
from solrstice.queries import DeleteQuery, SelectQuery, UpdateQuery

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

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

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

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

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

Grouping component

Field grouping

group_builder = GroupingComponent(fields=["age"], limit=10)
select_builder = SelectQuery(fq=["age:[* TO *]"], grouping=group_builder)
groups = await client.select(select_builder, "example_collection").get_groups()
age_group = groups["age"]
docs = age_group.get_field_result()

Query grouping

group_builder = GroupingComponent(queries=["age:[0 TO 59]", "age:[60 TO *]"], limit=10)
select_builder = SelectQuery(fq=["age:[* TO *]"], grouping=group_builder)
groups = await client.select(select_builder, "example_collection").get_groups()
age_group = groups["age:[0 TO 59]"]
group = age_group.get_query_result()
docs = group.get_docs()

Query parsers

Lucene

query_parser = LuceneQuery(df="population")
select_builder = SelectQuery(q="outdoors", def_type=query_parser)
await client.select(select_builder, "example_collection")
docs = response.get_docs_response().get_docs()

Dismax

query_parser = DismaxQuery(qf="interests^20", bq=["interests:cars^20"])
select_builder = SelectQuery(q="outdoors", def_type=query_parser)
await client.select(select_builder, "example_collection")
docs = response.get_docs_response().get_docs()

Edismax

query_parser = EdismaxQuery(qf="interests^20", bq=["interests:cars^20"])
select_builder = SelectQuery(q="outdoors", def_type=query_parser)
await client.select(select_builder, "example_collection")
docs = response.get_docs_response().get_docs()

FacetSet Component

Pivot facet

select_builder = SelectQuery(facet_set=FacetSetComponent(pivots=PivotFacetComponent(["interests,age"])))
await client.select(select_builder, "example_collection")
facets = response.get_facet_set()
pivots = facets.get_pivots()
interests_age = pivot.get("interests,age")

Field facet

facet_set = FacetSetComponent(fields=FieldFacetComponent(fields=[FieldFacetEntry("age")]))
select_builder = SelectQuery(facet_set=facet_set)
response = await client.select(select_builder, "example_collection")
facets = response.get_facet_set()
fields = facets.get_fields()
age = fields.get("age")

Query facet

select_builder = SelectQuery(facet_set=FacetSetComponent(queries=["age:[0 TO 59]"]))
response = await client.select(select_builder, name)
facets = response.get_facet_set()
queries = facets.get_queries()
query = queries.get("age:[0 TO 59]")

Json Facet Component

Query

select_builder = SelectQuery(
  json_facet=JsonFacetComponent(
    facets={"below_60": JsonQueryFacet("age:[0 TO 59]")}
  )
)
response = await client.select(select_builder, "example_collection"")
facets = response.get_json_facets()
below_60 = facets.get_nested_facets().get("below_60")
assert below_60.get_count() == 4

Stat

select_builder = SelectQuery(
    json_facet=JsonFacetComponent(
        facets={"total_people": JsonStatFacet("sum(count)")}
    )
)
response = await client.select(select_builder, "example_collection")
facets = response.get_json_facets()
total_people = facets.get_flat_facets().get("total_people")
assert total_people == 1000

Terms

select_builder = SelectQuery(
    json_facet=JsonFacetComponent(facets={"age": JsonTermsFacet("age")})
)
response = await config.async_client.select(select_builder, name)
facets = response.get_json_facets()
age_buckets = facets.get_nested_facets().get("age").get_buckets()
assert len(age_buckets) == 3

Nested

select_builder = SelectQuery(
    json_facet=JsonFacetComponent(
        facets={
            "below_60": JsonQueryFacet(
                "age:[0 TO 59]",
                facets={"total_people": JsonStatFacet("sum(count)")},
            )
        }
    )
)
response = await client.select(select_builder, "example_collection")
facets = response.get_json_facets()
total_people = (
    facets.get_nested_facets()
    .get("below_60")
    .get_flat_facets()
    .get("total_people")
)
assert total_people == 750.0

Hosts

Single Server

context = SolrServerContext(SolrSingleServerHost('localhost:8983'), SolrBasicAuth('solr', 'SolrRocks'))
client = AsyncSolrCloudClient(context)

Multiple servers

# The client will randomly select a server to send requests to. It will wait 5 seconds for a response, before trying another server.
context = SolrServerContext(
  SolrMultipleServerHost(["localhost:8983", "localhost:8984"], 5),
  SolrBasicAuth('solr', 'SolrRocks'),
)
client = AsyncSolrCloudClient(context)

Zookeeper

context = SolrServerContext(
    await ZookeeperEnsembleHostConnector(["localhost:2181"], 30).connect(),
    SolrBasicAuth('solr', 'SolrRocks'),
)
client = AsyncSolrCloudClient(context)

Notes

  • Multiprocessing does not work, and will block forever. Normal multithreading works fine.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

solrstice-0.4.0.tar.gz (80.5 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

solrstice-0.4.0-cp38-abi3-win_amd64.whl (2.8 MB view details)

Uploaded CPython 3.8+Windows x86-64

solrstice-0.4.0-cp38-abi3-win32.whl (2.6 MB view details)

Uploaded CPython 3.8+Windows x86

solrstice-0.4.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.9 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ x86-64

solrstice-0.4.0-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl (6.5 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ s390x

solrstice-0.4.0-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (6.4 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ppc64le

solrstice-0.4.0-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl (6.1 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ i686

solrstice-0.4.0-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (5.6 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARMv7l

solrstice-0.4.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (5.8 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARM64

solrstice-0.4.0-cp38-abi3-macosx_11_0_arm64.whl (3.2 MB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

solrstice-0.4.0-cp38-abi3-macosx_10_7_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.8+macOS 10.7+ x86-64

File details

Details for the file solrstice-0.4.0.tar.gz.

File metadata

  • Download URL: solrstice-0.4.0.tar.gz
  • Upload date:
  • Size: 80.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.2.3

File hashes

Hashes for solrstice-0.4.0.tar.gz
Algorithm Hash digest
SHA256 5a19ab718cebe812c79ac63668003ecbd947155b8edb8786b96b86d186529bf6
MD5 2f1728fa52bad55ca8781d26378fbdb3
BLAKE2b-256 f3b6ed9dd031057b533694731d89a2b83812dcf205c79752447e8405219762b8

See more details on using hashes here.

File details

Details for the file solrstice-0.4.0-cp38-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for solrstice-0.4.0-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 be8eb6b52f619e3abfe19659648fc0139aeb184556e6f503e7d665a2b9112e3d
MD5 5017ffe4214f8f58d5c338879841a883
BLAKE2b-256 a282b9781f64e7c2705ca110301df1b05cb70f2f50277ae0822b7eff418a704f

See more details on using hashes here.

File details

Details for the file solrstice-0.4.0-cp38-abi3-win32.whl.

File metadata

  • Download URL: solrstice-0.4.0-cp38-abi3-win32.whl
  • Upload date:
  • Size: 2.6 MB
  • Tags: CPython 3.8+, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.2.3

File hashes

Hashes for solrstice-0.4.0-cp38-abi3-win32.whl
Algorithm Hash digest
SHA256 b6761a7944be7e210322b4270457071f8261bd98475451224173a966d668cab3
MD5 6ece6a8ab0a56f2811b2e6cd270cdf97
BLAKE2b-256 520592ab94de00f6d14ded07d5a68710110dfe146b1242962ce7d4366ae5e389

See more details on using hashes here.

File details

Details for the file solrstice-0.4.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for solrstice-0.4.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 84e012d1d98457cbb0b135054212d6996003f7ef1b94742713ac1171b3db861f
MD5 10417902b84bfc36054c67ec2268d032
BLAKE2b-256 b06b3fc01f22909d54c5a5429b67e85b781acdd0b07b541cc5d331085ef51a63

See more details on using hashes here.

File details

Details for the file solrstice-0.4.0-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl.

File metadata

File hashes

Hashes for solrstice-0.4.0-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 493a0d7f0e5e02c7cf5be3b8c273483d238384bdedc607a745b60d2bf9d07df7
MD5 df9599ed153ce780878242708fcc69e5
BLAKE2b-256 eb8dcce0f0866c4d04465b6840176ffe88e62b123e574a3a311bf5ec03a71667

See more details on using hashes here.

File details

Details for the file solrstice-0.4.0-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl.

File metadata

File hashes

Hashes for solrstice-0.4.0-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 9570807b3ef24edaa9f1bfa661dba16a91f0e9531af872bf069fdf2f6158c06a
MD5 b0c59b9d36003cce457bf45703c87561
BLAKE2b-256 937286750b5820acb801fb301a958482c2be65dfad4cd332807099e7d2fcf896

See more details on using hashes here.

File details

Details for the file solrstice-0.4.0-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for solrstice-0.4.0-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 697ee29b06cf58e26adf4127c2de4958f7a95c6f3caf34a334ee689556909fbc
MD5 5c88bd8ad2c1a59c406a1861ba682a02
BLAKE2b-256 cc69605d04ad42d8e9a3b0f9e1d81c75487c6a17bc543810d6c72a030c9248e8

See more details on using hashes here.

File details

Details for the file solrstice-0.4.0-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.

File metadata

File hashes

Hashes for solrstice-0.4.0-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 bc787581f752d0213917909401d58c02bfd2096477178976c4b2b0245cc98575
MD5 10f937a3e7134bd9905927b2671084f9
BLAKE2b-256 9a8fd16e09f695df14e8393318bdf7fa6dcf05af8737412bcce19b0751b19b84

See more details on using hashes here.

File details

Details for the file solrstice-0.4.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for solrstice-0.4.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 fc13df7d5793ff46a01b6d4820432719c4f68eecc43e98026717554f36aa8a38
MD5 7480127f95b0e316370b74624a6cc32d
BLAKE2b-256 815c0a44d16590efb754b3c2599d19c401817eca383e8bbcdb099a82a887f4dd

See more details on using hashes here.

File details

Details for the file solrstice-0.4.0-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for solrstice-0.4.0-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d70f8dd0a675779caa023475625deae38bcb0d983e9046a8736ae26c1135ff73
MD5 256263af0f61480c6f1ec184014b9362
BLAKE2b-256 b432ad4428a81fcc9552d80d2905f7529ce5c2b144a7a8ab80b24dd2fdd8ab31

See more details on using hashes here.

File details

Details for the file solrstice-0.4.0-cp38-abi3-macosx_10_7_x86_64.whl.

File metadata

File hashes

Hashes for solrstice-0.4.0-cp38-abi3-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 7312e3ef3b7e8ee21eb9dbed627142d3df98fa0f2b3cc60758b356222d093862
MD5 576ca23f1342b100762ac3cc08435b27
BLAKE2b-256 de2408485c63991644eba2578e971b31309e463a55cbdc9b4deabe88397a65eb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page