mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-03 00:47:53 +00:00
ElasticSearch test
This commit is contained in:
1 parent
c91f548878
commit
c15360ddb3
3 files changed
+68
-3
No files matched your search
Generated
+1
@@ -2149,6 +2149,7 @@ dependencies = [
|
||||
"errors",
|
||||
"log",
|
||||
"my-workspace-hack",
|
||||
"regex",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tokens",
|
||||
|
||||
@@ -27,6 +27,7 @@ chrono = { version = "0.4.22", features = ["serde"] }
|
||||
serde = { version = "1.0.152", features = ["derive"] }
|
||||
serde_json = "1.0.108"
|
||||
my-workspace-hack = { version = "0.1", path = "../../my-workspace-hack" }
|
||||
regex = "1.10.2"
|
||||
|
||||
[dev-dependencies]
|
||||
# None yet
|
||||
# None yet
|
||||
@@ -1,8 +1,7 @@
|
||||
use elasticsearch::{Elasticsearch, SearchParts};
|
||||
use log::error;
|
||||
use serde_json::{json, Value};
|
||||
use enums::by_table::model_weights::weights_types::WeightsType;
|
||||
|
||||
use enums::by_table::model_weights::weights_types::WeightsType;
|
||||
use errors::AnyhowResult;
|
||||
|
||||
use crate::documents::model_weight_document::{MODEL_WEIGHT_INDEX, ModelWeightDocument};
|
||||
@@ -202,3 +201,67 @@ fn query_model_weights_with_model_weights_type(search_term: &str, weight_type: W
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use regex::Regex;
|
||||
use crate::searches::search_model_weights::query_model_weights;
|
||||
|
||||
#[test]
|
||||
fn default_search_only_keyword() {
|
||||
let json = query_model_weights("FOO_BAR_BAZ");
|
||||
let json = serde_json::to_string(&json).unwrap();
|
||||
|
||||
// NB: Keys in emitted JSON are sorted.
|
||||
let expected_json = r#"
|
||||
{
|
||||
"query": {
|
||||
"bool": {
|
||||
"must": [
|
||||
{
|
||||
"bool": {
|
||||
"should": [
|
||||
{
|
||||
"fuzzy": {
|
||||
"title": {
|
||||
"fuzziness": 2,
|
||||
"value": "FOO_BAR_BAZ"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"match": {
|
||||
"title": {
|
||||
"boost": 1,
|
||||
"query": "FOO_BAR_BAZ"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"multi_match": {
|
||||
"boost": 50,
|
||||
"fields": [
|
||||
"title",
|
||||
"title._2gram",
|
||||
"title._3gram"
|
||||
],
|
||||
"query": "FOO_BAR_BAZ",
|
||||
"type": "bool_prefix"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
"#;
|
||||
|
||||
let regex = Regex::new("\\s+").expect("regex should parse");
|
||||
|
||||
let expected_json = regex.replace_all(&expected_json, "");
|
||||
|
||||
assert_eq!(&json, &expected_json);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user