A Solr 8+ Client for Rust and Python

Overview

Solrstice: A Solr 8+ Client for Rust and Python

Lines of code

Solrstice is a SolrCloud aware client library written in rust. It also provides a wrapper to python.

Use the Rust documentation or the Python documentation 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)
  • Indexing Documents
  • Deleting Documents

Examples

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::models::error::SolrError;
use solrstice::queries::index::{DeleteQuery, UpdateQuery};
use solrstice::queries::select::SelectQuery;
use std::path::Path;

#[derive(Serialize, Deserialize, Debug)]
struct TestData {
    id: String,
}

#[tokio::test]
pub async fn example() -> Result<(), SolrError> {
  
    //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(),
    }];
    client
        .index(
          &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",
        )
        .await?
        .get_docs_response()
        .ok_or("No response provided")?
        .get_docs::<TestData>()?;
    
    // Delete the document
    client
        .delete(
          &DeleteQuery::new().ids(["example_document"]),
          "example_collection",
        )
        .await?;
    Ok(())
}

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

# 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())
You might also like...
Represent large sets and maps compactly with finite state transducers.

fst This crate provides a fast implementation of ordered sets and maps using finite state machines. In particular, it makes use of finite state transd

Lightning Fast, Ultra Relevant, and Typo-Tolerant Search Engine
Lightning Fast, Ultra Relevant, and Typo-Tolerant Search Engine

MeiliSearch Website | Roadmap | Blog | LinkedIn | Twitter | Documentation | FAQ โšก Lightning Fast, Ultra Relevant, and Typo-Tolerant Search Engine ๐Ÿ” M

Perlin: An Efficient and Ergonomic Document Search-Engine

Table of Contents 1. Perlin Perlin Perlin is a free and open-source document search engine library build on top of perlin-core. Since the first releas

 Rapidly Search and Hunt through Windows Event Logs
Rapidly Search and Hunt through Windows Event Logs

Rapidly Search and Hunt through Windows Event Logs Chainsaw provides a powerful โ€˜first-responseโ€™ capability to quickly identify threats within Windows

๐Ÿ”Ž A simple in-memory search for collections and key-value stores.
๐Ÿ”Ž A simple in-memory search for collections and key-value stores.

Indicium Search ๐Ÿ”Ž A simple in-memory search for collections (Vec, HashMap, BTreeMap, etc) and key-value stores. Features autocompletion. There are ma

Finding all pairs of similar documents time- and memory-efficiently

Finding all pairs of similar documents This software provides time- and memory-efficient all pairs similarity searches in documents. Problem definitio

Configurable quick search engine shortcuts for your terminal and browser.

Quicksearch Configurable quick search engine shortcuts for your terminal and browser. Installation Run cargo install quicksearch to install Configurat

๐Ÿ’ฐ Midas is a free and open source Moving Average Trading backtest simulator.
๐Ÿ’ฐ Midas is a free and open source Moving Average Trading backtest simulator.

Midas is a free and open source Moving Average Trading backtest simulator Bilibili Video: https://www.bilibili.com/video/BV11o4y1B7fL โš ๏ธ Warning Inves

AI-powered search engine for Rust

txtai: AI-powered search engine for Rust txtai executes machine-learning workflows to transform data and build AI-powered text indices to perform simi

Releases(v0.4.0)
  • v0.4.0(Sep 1, 2023)

    What's Changed

    • v0.4.0: Simplify how requests to Solr are done by @Sh1nku in https://github.com/Sh1nku/solrstice/pull/5

    Full Changelog: https://github.com/Sh1nku/solrstice/compare/v0.3.2...v0.4.0

    Source code(tar.gz)
    Source code(zip)
  • v0.3.2(Aug 22, 2023)

    What's Changed

    • v0.3.2: Fix error when using Solr 8.0-8.5 by @Sh1nku in https://github.com/Sh1nku/solrstice/pull/4

    Full Changelog: https://github.com/Sh1nku/solrstice/compare/v0.3.1...v0.3.2

    Source code(tar.gz)
    Source code(zip)
  • v0.3.1(Aug 21, 2023)

    What's Changed

    • v0.3.1: Fix error in python documentation by @Sh1nku in https://github.com/Sh1nku/solrstice/pull/3

    Full Changelog: https://github.com/Sh1nku/solrstice/compare/v0.3.0...v0.3.1

    Source code(tar.gz)
    Source code(zip)
  • v0.3.0(Aug 21, 2023)

    What's Changed

    • v0.3.0: Add Faceting with Json facets and facet counts by @Sh1nku in https://github.com/Sh1nku/solrstice/pull/2

    Full Changelog: https://github.com/Sh1nku/solrstice/compare/v0.2.0...v0.3.0

    Source code(tar.gz)
    Source code(zip)
  • v0.2.0(Aug 10, 2023)

    What's Changed

    • Add lucene, dismax and edismax query parsers by @Sh1nku in https://github.com/Sh1nku/solrstice/pull/1

    Full Changelog: https://github.com/Sh1nku/solrstice/compare/v0.1.1...v0.2.0

    Source code(tar.gz)
    Source code(zip)
  • v0.1.1(Aug 9, 2023)

    • Fix error in rust setup documentation example
    • Add mdbook, and pydoc documentation

    Full Changelog: https://github.com/Sh1nku/solrstice/compare/v0.1.0...v0.1.1

    Source code(tar.gz)
    Source code(zip)
Owner
Andreas H Johansen
Back-End web developer. In my free time I do game development.
Andreas H Johansen
Python bindings for Milli, the embeddable Rust-based search engine powering Meilisearch

milli-py Python bindings for Milli, the embeddable Rust-based search engine powering Meilisearch. Due to limitations around Rust lifecycles, methods a

Alexandro Sanchez 92 Feb 21, 2023
EasyAlgolia is a Rust crate designed for utilizing the Algolia admin client. It simplifies the process of updating and inserting documents into Algolia's search index.

crate link EasyAlgolia is a Rust crate designed for utilizing the Algolia admin client. It simplifies the process of updating and inserting documents

faizal khan 3 Mar 20, 2024
Official Elasticsearch Rust Client

elasticsearch โ€ƒ Official Rust Client for Elasticsearch. Full documentation is available at https://docs.rs/elasticsearch The project is still very muc

elastic 574 Jan 5, 2023
weggli is a fast and robust semantic search tool for C and C++ codebases. It is designed to help security researchers identify interesting functionality in large codebases.

weggli Introduction weggli is a fast and robust semantic search tool for C and C++ codebases. It is designed to help security researchers identify int

Google Project Zero 2k Jan 5, 2023
Tantivy is a full-text search engine library inspired by Apache Lucene and written in Rust

Tantivy is a full text search engine library written in Rust. It is closer to Apache Lucene than to Elasticsearch or Apache Solr in the sense it is no

tantivy 7.4k Dec 28, 2022
A full-text search and indexing server written in Rust.

Bayard Bayard is a full-text search and indexing server written in Rust built on top of Tantivy that implements Raft Consensus Algorithm and gRPC. Ach

Bayard Search 1.8k Dec 26, 2022
An example of web application by using Rust and Axum with Clean Architecture.

stock-metrics Stock price and stats viewer. Getting Started Middleware Launch the middleware by executing docker compose: cd local-middleware docker c

Yuki Toyoda 62 Dec 10, 2022
2 and 3-dimensional collision detection library in Rust.

2D Documentation | 3D Documentation | User Guide | Forum โš ๏ธ **This crate is now passively-maintained. It is being superseded by the Parry project.** โš 

dimforge 914 Dec 24, 2022
Tantivy is a full-text search engine library inspired by Apache Lucene and written in Rust

Tantivy is a full-text search engine library written in Rust. It is closer to Apache Lucene than to Elasticsearch or Apache Solr in the sense it is no

Quickwit OSS 7.5k Jan 9, 2023
A simple and lightweight fuzzy search engine that works in memory, searching for similar strings (a pun here).

simsearch A simple and lightweight fuzzy search engine that works in memory, searching for similar strings (a pun here). Documentation Usage Add the f

Andy Lok 116 Dec 10, 2022