mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-23 18:45:06 +08:00
a30e02c18c
implements: https://github.com/meilisearch/specifications/blob/develop/text/0060-refashion-updates-apis.md linked PR: - #1889 - #1891 - #1892 - #1902 - #1906 - #1911 - #1914 - #1915 - #1916 - #1918 - #1924 - #1925 - #1926 - #1930 - #1936 - #1937 - #1942 - #1944 - #1945 - #1946 - #1947 - #1950 - #1951 - #1957 - #1959 - #1960 - #1961 - #1962 - #1964 - https://github.com/meilisearch/milli/pull/414 - https://github.com/meilisearch/milli/pull/409 - https://github.com/meilisearch/milli/pull/406 - https://github.com/meilisearch/milli/pull/418 - close #1687 - close #1786 - close #1940 - close #1948 - close #1949 - close #1932 - close #1956
120 lines
3.3 KiB
Rust
120 lines
3.3 KiB
Rust
use std::path::Path;
|
|
|
|
use actix_web::http::StatusCode;
|
|
use byte_unit::{Byte, ByteUnit};
|
|
use meilisearch_http::setup_meilisearch;
|
|
use meilisearch_lib::options::{IndexerOpts, MaxMemory};
|
|
use once_cell::sync::Lazy;
|
|
use serde_json::Value;
|
|
use tempfile::TempDir;
|
|
|
|
use meilisearch_http::option::Opt;
|
|
|
|
use super::index::Index;
|
|
use super::service::Service;
|
|
|
|
pub struct Server {
|
|
pub service: Service,
|
|
// hold ownership to the tempdir while we use the server instance.
|
|
_dir: Option<TempDir>,
|
|
}
|
|
|
|
static TEST_TEMP_DIR: Lazy<TempDir> = Lazy::new(|| TempDir::new().unwrap());
|
|
|
|
impl Server {
|
|
pub async fn new() -> Self {
|
|
let dir = TempDir::new().unwrap();
|
|
|
|
if cfg!(windows) {
|
|
std::env::set_var("TMP", TEST_TEMP_DIR.path());
|
|
} else {
|
|
std::env::set_var("TMPDIR", TEST_TEMP_DIR.path());
|
|
}
|
|
|
|
let options = default_settings(dir.path());
|
|
|
|
let meilisearch = setup_meilisearch(&options).unwrap();
|
|
let service = Service {
|
|
meilisearch,
|
|
options,
|
|
};
|
|
|
|
Server {
|
|
service,
|
|
_dir: Some(dir),
|
|
}
|
|
}
|
|
|
|
pub async fn new_with_options(options: Opt) -> Self {
|
|
let meilisearch = setup_meilisearch(&options).unwrap();
|
|
let service = Service {
|
|
meilisearch,
|
|
options,
|
|
};
|
|
|
|
Server {
|
|
service,
|
|
_dir: None,
|
|
}
|
|
}
|
|
|
|
/// Returns a view to an index. There is no guarantee that the index exists.
|
|
pub fn index(&self, uid: impl AsRef<str>) -> Index<'_> {
|
|
Index {
|
|
uid: uid.as_ref().to_string(),
|
|
service: &self.service,
|
|
}
|
|
}
|
|
|
|
pub async fn list_indexes(&self) -> (Value, StatusCode) {
|
|
self.service.get("/indexes").await
|
|
}
|
|
|
|
pub async fn version(&self) -> (Value, StatusCode) {
|
|
self.service.get("/version").await
|
|
}
|
|
|
|
pub async fn stats(&self) -> (Value, StatusCode) {
|
|
self.service.get("/stats").await
|
|
}
|
|
|
|
pub async fn tasks(&self) -> (Value, StatusCode) {
|
|
self.service.get("/tasks").await
|
|
}
|
|
}
|
|
|
|
pub fn default_settings(dir: impl AsRef<Path>) -> Opt {
|
|
Opt {
|
|
db_path: dir.as_ref().join("db"),
|
|
dumps_dir: dir.as_ref().join("dump"),
|
|
http_addr: "127.0.0.1:7700".to_owned(),
|
|
master_key: None,
|
|
env: "development".to_owned(),
|
|
#[cfg(all(not(debug_assertions), feature = "analytics"))]
|
|
no_analytics: true,
|
|
max_index_size: Byte::from_unit(4.0, ByteUnit::GiB).unwrap(),
|
|
max_task_db_size: Byte::from_unit(4.0, ByteUnit::GiB).unwrap(),
|
|
http_payload_size_limit: Byte::from_unit(10.0, ByteUnit::MiB).unwrap(),
|
|
ssl_cert_path: None,
|
|
ssl_key_path: None,
|
|
ssl_auth_path: None,
|
|
ssl_ocsp_path: None,
|
|
ssl_require_auth: false,
|
|
ssl_resumption: false,
|
|
ssl_tickets: false,
|
|
import_snapshot: None,
|
|
ignore_missing_snapshot: false,
|
|
ignore_snapshot_if_db_exists: false,
|
|
snapshot_dir: ".".into(),
|
|
schedule_snapshot: false,
|
|
snapshot_interval_sec: 0,
|
|
import_dump: None,
|
|
indexer_options: IndexerOpts {
|
|
// memory has to be unlimited because several meilisearch are running in test context.
|
|
max_memory: MaxMemory::unlimited(),
|
|
..Default::default()
|
|
},
|
|
log_level: "off".into(),
|
|
}
|
|
}
|