Crate solrstice

Source
Expand description

Solrstice is a Solr 8+ client for Rust. Take a look at AsyncSolrCloudClient and SelectQuery for more documentation

§Examples

use serde::{Deserialize, Serialize};
use solrstice::AsyncSolrCloudClient;
use solrstice::SolrSingleServerHost;
use solrstice::SolrBasicAuth;
use solrstice::{SolrServerContextBuilder};
use solrstice::Error;
use solrstice::{DeleteQuery, UpdateQuery};
use solrstice::SelectQuery;
use std::path::Path;

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

#[tokio::test]
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(),
    }];
    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(())
}

Modules§

models
Model structs Models used by the Solr Client.
queries
Query types The different query types this library supports.

Structs§

AsyncSolrCloudClient
Async client for SolrCloud
DeleteQuery
A builder for deleting documents.
DismaxQuery
The dismax query parser
EdismaxQuery
The extended dismax query parser
FacetSetComponent
Get facet counts for different types of faceting.
FieldFacetComponent
Component for field facets
FieldFacetEntry
A field facet entry represents a single field facet.
GroupingComponent
Group documents by a field or query.
JsonFacetComponent
Get self defined facets.
JsonQueryFacet
A facet that does a query and returns the number of documents that match
JsonStatFacet
A facet that does a query and gets the number of results
JsonTermsFacet
A facet that counts the number of documents that match a query
LoggingWatcher
LuceneQuery
The default query parser
PivotFacetComponent
A facet component for pivot facets.
SelectQuery
Builder for a select query.
SolrBasicAuth
Basic Authentication
SolrMultipleServerHost
Connect to multiple solr hosts. Acts as a load balancer with random selection
SolrRequestBuilder
SolrServerContext
A SolrServerContext specifies how to connect to a solr server, and how to authenticate.
SolrServerContextBuilder
A SolrServerContext specifies how to connect to a solr server, and how to authenticate.
SolrSingleServerHost
Connect to a single solr host Good for if you have an external load balancer
UpdateQuery
A builder for the update handler.
ZookeeperEnsembleHost
Connect to zookeeper instances to get a list of solr nodes to connect to. Select randomly from the list of live nodes. The timeout is used to determine how long to wait for a response from a solr host before trying the next one
ZookeeperEnsembleHostConnector
Connect to zookeeper instances to get a list of solr nodes to connect to. Select randomly from the list of live nodes. The timeout is used to determine how long to wait for a response from a solr host before trying the next one

Enums§

CommitType
This struct encapsulates the commit types for Solr’s update and delete queries. By default, a Hard commit is performed, equating to commit=true. Conversely, a Soft commit corresponds to softCommit=true.
DefType
Error
Main error type for Solrstice
FieldFacetMethod
Set the method to do the facet calculation. Default is Fc.
FieldFacetSort
Set the sorting order of field facets
GroupFormatting
How to format groups. The default is GroupFormatting::Grouped.
JsonFacetType
The different types of facets supported by JsonFacet
LoggingPolicy
How detailed the logs of the requests should be For Fast and Pretty the number is the maximum length of the body that will be logged Logging will be with the debug level
QueryOperator

Traits§

SolrAuth
Modifies a reqwest::RequestBuilder to add authentication
SolrHost
SolrHost specifies how to connect to a solr server.