feat(solr): add Apache Solr connection support

This commit is contained in:
Terry Yao authored and GitHub committed 2026-09-21 18:07:44 +08:00
1 parent 7b407ccbfc
commit 3687a9cbfb
75 files changed
+5596 -82

No files matched your search

+42 -1
View File
@@ -1,7 +1,7 @@
use crate::connection::{AppState, PoolKind};
use crate::db::agent_driver::mongo_document_id_params;
use crate::db::document_result::DocumentQueryResult;
use crate::db::{dynamodb_driver, easysearch_driver, elasticsearch_driver, mongo_driver, vector_driver};
use crate::db::{dynamodb_driver, easysearch_driver, elasticsearch_driver, mongo_driver, solr_driver, vector_driver};
pub use crate::db::vector_driver::CollectionInfo;
@@ -61,6 +61,7 @@ pub async fn list_databases_core(state: &AppState, connection_id: &str) -> Resul
PoolKind::DynamoDb(client) => Ok(vec![client.region.clone()]),
PoolKind::Elasticsearch(_) => Ok(vec!["default".to_string()]),
PoolKind::Easysearch(_) => Ok(vec!["default".to_string()]),
PoolKind::Solr(_) => Ok(vec!["default".to_string()]),
PoolKind::Meilisearch(_) => Ok(vec!["default".to_string()]),
PoolKind::VectorDb(client) => vector_driver::list_databases(client).await,
PoolKind::Agent(client) => {
@@ -270,6 +271,18 @@ pub async fn list_collections_core(
PoolKind::Easysearch(client) => {
Ok(elasticsearch_collection_infos(easysearch_driver::list_indices_with_aliases(client).await?))
}
PoolKind::Solr(client) => {
let names = sort_names(solr_driver::list_cores(client).await?);
Ok(names
.into_iter()
.map(|n| CollectionInfo {
name: n.clone(),
id: n,
kind: Some("core".to_string()),
..Default::default()
})
.collect())
}
PoolKind::Meilisearch(client) => {
let names = sort_names(crate::db::meilisearch_driver::list_indexes(client).await?);
Ok(names.into_iter().map(|n| CollectionInfo { name: n.clone(), id: n, ..Default::default() }).collect())
@@ -459,6 +472,15 @@ pub async fn find_documents_core(
easysearch_driver::find_documents(&client, collection, skip, limit, filter, sort).await
}
}
PoolKind::Solr(client) => {
let client = client.clone();
let _ = projection;
if cursor_pagination {
solr_driver::find_documents_with_cursor(&client, collection, limit, filter, sort, cursor).await
} else {
solr_driver::find_documents(&client, collection, skip, limit, filter, sort).await
}
}
PoolKind::Meilisearch(client) => {
let client = client.clone();
crate::db::meilisearch_driver::find_documents(&client, collection, skip, limit, filter, sort).await
@@ -517,6 +539,10 @@ pub async fn count_document_store_documents_core(
let client = client.clone();
easysearch_driver::count_documents(&client, collection, filter).await
}
PoolKind::Solr(client) => {
let client = client.clone();
solr_driver::count_documents(&client, collection, filter).await
}
_ => Err("Document count is not supported for this connection".to_string()),
}
}
@@ -643,6 +669,11 @@ pub async fn insert_document_core(
let client = client.clone();
easysearch_driver::insert_document(&client, collection, doc_json, routing).await
}
PoolKind::Solr(client) => {
let client = client.clone();
let _ = routing;
solr_driver::insert_document(&client, collection, doc_json).await
}
PoolKind::Meilisearch(client) => {
let client = client.clone();
crate::db::meilisearch_driver::insert_document(&client, collection, doc_json).await
@@ -707,6 +738,11 @@ pub async fn update_document_core(
let client = client.clone();
easysearch_driver::update_document(&client, collection, id, doc_json, routing).await
}
PoolKind::Solr(client) => {
let client = client.clone();
let _ = routing;
solr_driver::update_document(&client, collection, id, doc_json).await
}
PoolKind::Meilisearch(client) => {
let client = client.clone();
crate::db::meilisearch_driver::update_document(&client, collection, id, doc_json).await
@@ -765,6 +801,11 @@ pub async fn delete_document_core_with_type(
let client = client.clone();
easysearch_driver::delete_document(&client, collection, id, document_type, routing).await
}
PoolKind::Solr(client) => {
let client = client.clone();
let _ = (document_type, routing);
solr_driver::delete_document(&client, collection, id).await
}
PoolKind::Meilisearch(client) => {
let client = client.clone();
crate::db::meilisearch_driver::delete_document(&client, collection, id).await
+21
View File
@@ -1963,6 +1963,20 @@ async fn do_execute_typed(
}
result
}
PoolKind::Solr(client) => {
let client = client.clone();
let sql = sql.to_string();
let max_rows = options.max_rows;
// cursorMark 分页只服务文档浏览器;REST 查询是一次性请求,不需要 session 游标。
let result =
wait_for_query_opt(cancel_token, query_timeout, db::solr_driver::execute_rest_query(&client, &sql))
.await
.map(|result| truncate_result_with_max_rows(result, max_rows));
if matches!(result.as_ref(), Err(err) if should_discard_pool_after_error(pool_db_type, err)) {
state.remove_pool_by_key(pool_key).await;
}
result
}
PoolKind::Meilisearch(client) => {
let client = client.clone();
let sql = sql.to_string();
@@ -2926,6 +2940,11 @@ pub async fn close_query_session(
db::easysearch_driver::close_cursor(&client, session_id).await?;
Ok(true)
}
PoolKind::Solr(client) => {
let client = client.clone();
db::solr_driver::close_cursor(&client, session_id).await?;
Ok(true)
}
_ => Ok(false),
}
}
@@ -4301,6 +4320,7 @@ fn pool_kind_has_transactional_path(pool: &PoolKind) -> bool {
| PoolKind::DynamoDb(_)
| PoolKind::Elasticsearch(_)
| PoolKind::Easysearch(_)
| PoolKind::Solr(_)
| PoolKind::Meilisearch(_)
| PoolKind::VectorDb(_)
| PoolKind::InfluxDb(_)
@@ -4704,6 +4724,7 @@ fn batch_transaction_path(pool: &PoolKind) -> BatchTransactionPath {
| PoolKind::CloudflareD1(_)
| PoolKind::Elasticsearch(_)
| PoolKind::Easysearch(_)
| PoolKind::Solr(_)
| PoolKind::Meilisearch(_)
| PoolKind::VectorDb(_)
| PoolKind::InfluxDb(_)