-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Support for transactions, analyzers and views (#38)
- Loading branch information
Showing
25 changed files
with
1,941 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#![allow(unused_imports)] | ||
#![allow(unused_parens)] | ||
|
||
use anyhow::Error; | ||
|
||
use arangors::analyzer::{AnalyzerCase, AnalyzerFeature, AnalyzerInfo, NormAnalyzerProperties}; | ||
use arangors::Connection; | ||
use std::collections::HashMap; | ||
|
||
const URL: &str = "http://localhost:8529"; | ||
|
||
#[cfg_attr(feature = "reqwest_async", tokio::main)] | ||
#[cfg_attr(feature = "surf_async", async_std::main)] | ||
#[cfg_attr(feature = "reqwest_blocking", maybe_async::must_be_sync)] | ||
async fn main() -> Result<(), Error> { | ||
let analyzer_name = "test_analyzer".to_string(); | ||
|
||
let conn = Connection::establish_jwt(URL, "username", "password").await?; | ||
let database = conn.db("test_db").await?; | ||
|
||
let info = AnalyzerInfo::Norm { | ||
name: analyzer_name.clone(), | ||
features: Some(vec![AnalyzerFeature::Frequency, AnalyzerFeature::Norm]), | ||
properties: Some( | ||
NormAnalyzerProperties::builder() | ||
.locale("en.utf-8".to_string()) | ||
.case(AnalyzerCase::Lower) | ||
.build(), | ||
), | ||
}; | ||
|
||
database.create_analyzer(info).await?; | ||
|
||
database.drop_analyzer(&analyzer_name).await?; | ||
|
||
Ok(()) | ||
} | ||
#[cfg(not(any( | ||
feature = "reqwest_blocking", | ||
feature = "reqwest_async", | ||
feature = "surf_async" | ||
)))] | ||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#![allow(unused_imports)] | ||
#![allow(unused_parens)] | ||
|
||
use anyhow::Error; | ||
use arangors::Document; | ||
use arangors::{ | ||
transaction::{TransactionCollections, TransactionSettings}, | ||
Connection, | ||
}; | ||
use log::info; | ||
use serde_json::{json, Value}; | ||
|
||
const URL: &str = "http://localhost:8529"; | ||
|
||
#[cfg_attr(feature = "reqwest_async", tokio::main)] | ||
#[cfg_attr(feature = "surf_async", async_std::main)] | ||
#[cfg_attr(feature = "reqwest_blocking", maybe_async::must_be_sync)] | ||
async fn main() -> Result<(), Error> { | ||
let conn = Connection::establish_jwt(URL, "username", "password").await?; | ||
let database = conn.db("test_db").await?; | ||
|
||
let tx = database | ||
.begin_transaction( | ||
TransactionSettings::builder() | ||
.lock_timeout(60000) | ||
.wait_for_sync(true) | ||
.collections( | ||
TransactionCollections::builder() | ||
.write(vec!["test_collection".to_owned()]) | ||
.build(), | ||
) | ||
.build(), | ||
) | ||
.await?; | ||
|
||
let transactions = database.list_transactions().await?; | ||
info!("Transactions: {:?}", transactions); | ||
|
||
let test_doc: Document<Value> = Document::new(json!({ | ||
"user_name":"test21", | ||
"user_name":"test21_pwd", | ||
})); | ||
|
||
let collection = tx.collection("test_collection").await?; | ||
let document = collection | ||
.create_document(test_doc, Default::default()) | ||
.await?; | ||
let header = document.header().unwrap(); | ||
let _key = &header._key; | ||
|
||
info!("Key: {}", _key); | ||
tx.abort().await?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#![allow(unused_imports)] | ||
#![allow(unused_parens)] | ||
|
||
use anyhow::Error; | ||
|
||
use arangors::view::{ArangoSearchViewLink, ArangoSearchViewPropertiesOptions, ViewOptions}; | ||
use arangors::Connection; | ||
use std::collections::HashMap; | ||
|
||
const URL: &str = "http://localhost:8529"; | ||
|
||
#[cfg_attr(feature = "reqwest_async", tokio::main)] | ||
#[cfg_attr(feature = "surf_async", async_std::main)] | ||
#[cfg_attr(feature = "reqwest_blocking", maybe_async::must_be_sync)] | ||
async fn main() -> Result<(), Error> { | ||
let collection_name = "test_collection".to_string(); | ||
|
||
let conn = Connection::establish_jwt(URL, "username", "password").await?; | ||
let database = conn.db("test_db").await?; | ||
|
||
let mut links: HashMap<String, ArangoSearchViewLink> = HashMap::new(); | ||
|
||
links.insert( | ||
collection_name.clone(), | ||
ArangoSearchViewLink::builder() | ||
.include_all_fields(true) | ||
.build(), | ||
); | ||
|
||
let view = database | ||
.create_view( | ||
ViewOptions::builder() | ||
.name(format!("{}_view", collection_name)) | ||
.properties( | ||
ArangoSearchViewPropertiesOptions::builder() | ||
.links(links) | ||
.build(), | ||
) | ||
.build(), | ||
) | ||
.await?; | ||
|
||
println!("{:?}", view); | ||
|
||
database | ||
.drop_view(&format!("{}_view", collection_name)) | ||
.await?; | ||
|
||
Ok(()) | ||
} | ||
#[cfg(not(any( | ||
feature = "reqwest_blocking", | ||
feature = "reqwest_async", | ||
feature = "surf_async" | ||
)))] | ||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
use serde::{Deserialize, Serialize}; | ||
use typed_builder::TypedBuilder; | ||
|
||
#[derive(Debug, Serialize, Deserialize, PartialEq)] | ||
#[serde(rename_all = "lowercase")] | ||
pub enum AnalyzerFeature { | ||
Frequency, | ||
Norm, | ||
Position, | ||
} | ||
|
||
#[derive(Debug, Serialize, Deserialize, PartialEq)] | ||
#[serde(rename_all = "lowercase")] | ||
pub enum AnalyzerCase { | ||
Lower, | ||
None, | ||
Upper, | ||
} | ||
|
||
#[derive(Debug, Serialize, Deserialize, TypedBuilder, PartialEq)] | ||
#[builder(doc)] | ||
pub struct DelimiterAnalyzerProperties { | ||
/// The value will be used as delimiter to split text into tokens as specified | ||
/// in RFC 4180, without starting new records on newlines. | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
#[builder(default, setter(strip_option))] | ||
pub delimiter: Option<String>, | ||
} | ||
|
||
#[derive(Debug, Serialize, Deserialize, TypedBuilder, PartialEq)] | ||
#[builder(doc)] | ||
pub struct StemAnalyzerProperties { | ||
/// Format: `language[_COUNTRY][.encoding][@variant]` | ||
pub locale: String, | ||
} | ||
|
||
#[derive(Debug, Serialize, Deserialize, TypedBuilder, PartialEq)] | ||
#[builder(doc)] | ||
pub struct NormAnalyzerProperties { | ||
/// Format: `language[_COUNTRY][.encoding][@variant]` | ||
pub locale: String, | ||
|
||
/// Case conversion. Default: `"lower"` | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
#[builder(default, setter(strip_option))] | ||
pub case: Option<AnalyzerCase>, | ||
|
||
/// Preserve accents in returned words. Default: `false` | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
#[builder(default, setter(strip_option))] | ||
pub accent: Option<bool>, | ||
} | ||
|
||
#[derive(Debug, Serialize, Deserialize, TypedBuilder, PartialEq)] | ||
#[builder(doc)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct NgramAnalyzerProperties { | ||
/// Minimum n-gram length. | ||
pub min: u16, | ||
|
||
/// Maximum n-gram length. | ||
pub max: u16, | ||
|
||
/// Output the original value as well. | ||
pub preserve_riginal: bool, | ||
} | ||
|
||
#[derive(Debug, Serialize, Deserialize, TypedBuilder, PartialEq)] | ||
#[builder(doc)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct TextAnalyzerProperties { | ||
/// Format: `language[_COUNTRY][.encoding][@variant]` | ||
pub locale: String, | ||
|
||
#[serde(skip_serializing_if = "Option::is_none")] | ||
#[builder(default, setter(strip_option))] | ||
pub case: Option<AnalyzerCase>, | ||
|
||
#[serde(skip_serializing_if = "Option::is_none")] | ||
#[builder(default, setter(strip_option))] | ||
pub accent: Option<bool>, | ||
|
||
/// Words to omit from result. | ||
/// Defaults to the words loaded from the file at `stopwordsPath`. | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
#[builder(default, setter(strip_option))] | ||
pub stopwords: Option<Vec<String>>, | ||
|
||
/// Path with a `language` sub-directory containing files with words to omit. | ||
/// | ||
/// Defaults to the path specified in the server-side environment variable | ||
/// IRESEARCH_TEXT_STOPWORD_PATH` or the current working directory of the | ||
/// ArangoDB process. | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
#[builder(default, setter(strip_option))] | ||
pub stopwords_path: Option<Vec<String>>, | ||
|
||
/// Apply stemming on returned words. | ||
/// Default: `true` | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
#[builder(default, setter(strip_option))] | ||
pub stemming: Option<bool>, | ||
} | ||
|
||
#[derive(Debug, Serialize, Deserialize, PartialEq)] | ||
#[serde(rename_all = "camelCase", tag = "type")] | ||
pub enum AnalyzerInfo { | ||
/// The `identity` Analyzer does not take additional properties. | ||
Identity { | ||
name: String, | ||
|
||
#[serde(skip_serializing_if = "Option::is_none")] | ||
features: Option<Vec<AnalyzerFeature>>, | ||
}, | ||
Delimiter { | ||
name: String, | ||
|
||
#[serde(skip_serializing_if = "Option::is_none")] | ||
features: Option<Vec<AnalyzerFeature>>, | ||
|
||
#[serde(skip_serializing_if = "Option::is_none")] | ||
properties: Option<DelimiterAnalyzerProperties>, | ||
}, | ||
|
||
Stem { | ||
name: String, | ||
|
||
#[serde(skip_serializing_if = "Option::is_none")] | ||
features: Option<Vec<AnalyzerFeature>>, | ||
|
||
#[serde(skip_serializing_if = "Option::is_none")] | ||
properties: Option<StemAnalyzerProperties>, | ||
}, | ||
|
||
Norm { | ||
name: String, | ||
|
||
#[serde(skip_serializing_if = "Option::is_none")] | ||
features: Option<Vec<AnalyzerFeature>>, | ||
|
||
#[serde(skip_serializing_if = "Option::is_none")] | ||
properties: Option<NormAnalyzerProperties>, | ||
}, | ||
|
||
Ngram { | ||
name: String, | ||
|
||
#[serde(skip_serializing_if = "Option::is_none")] | ||
features: Option<Vec<AnalyzerFeature>>, | ||
|
||
#[serde(skip_serializing_if = "Option::is_none")] | ||
properties: Option<NgramAnalyzerProperties>, | ||
}, | ||
|
||
Text { | ||
name: String, | ||
|
||
#[serde(skip_serializing_if = "Option::is_none")] | ||
features: Option<Vec<AnalyzerFeature>>, | ||
|
||
#[serde(skip_serializing_if = "Option::is_none")] | ||
properties: Option<TextAnalyzerProperties>, | ||
}, | ||
} | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
pub struct AnalyzerDescription { | ||
pub name: String, | ||
} |
Oops, something went wrong.