Moved multi-field query tests to lib.
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 1s
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 1s
This commit is contained in:
@@ -10,7 +10,7 @@ mod show;
|
|||||||
mod update;
|
mod update;
|
||||||
mod user;
|
mod user;
|
||||||
|
|
||||||
pub use crate::document::{DocDef, Field, FieldType, Record, Records};
|
pub use crate::document::{DocDef, Field, FieldType, IndexType, Record, Records};
|
||||||
pub use action_type::Action;
|
pub use action_type::Action;
|
||||||
pub use addition::Addition;
|
pub use addition::Addition;
|
||||||
pub use calculation::{CalcValue, Calculation, Operand};
|
pub use calculation::{CalcValue, Calculation, Operand};
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ mod session;
|
|||||||
use record::{InternalRecord, InternalRecords, Oid};
|
use record::{InternalRecord, InternalRecords, Oid};
|
||||||
|
|
||||||
pub use clock::Clock;
|
pub use clock::Clock;
|
||||||
pub use create::CreateDoc;
|
pub use create::{CreateDoc, IndexType};
|
||||||
pub use definition::DocDef;
|
pub use definition::DocDef;
|
||||||
pub use field::{Field, FieldType};
|
pub use field::{Field, FieldType};
|
||||||
pub use record::{Record, Records};
|
pub use record::{Record, Records};
|
||||||
|
|||||||
@@ -1312,7 +1312,6 @@ mod document_files {
|
|||||||
_ => unreachable!("got {:?}: should have been a reply", action),
|
_ => unreachable!("got {:?}: should have been a reply", action),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn query_should_work_with_multiple_fields() {
|
fn query_should_work_with_multiple_fields() {
|
||||||
@@ -1450,6 +1449,7 @@ mod document_files {
|
|||||||
_ => unreachable!("got {:?}: should have been a reply", action),
|
_ => unreachable!("got {:?}: should have been a reply", action),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn errors_on_bad_field_name() {
|
fn errors_on_bad_field_name() {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
mod support;
|
mod support;
|
||||||
|
|
||||||
use morethantext::{CalcValue, Calculation, Field, FieldType, MoreThanText, Operand, Query};
|
use morethantext::{CalcValue, Calculation, Field, FieldType, IndexType, MoreThanText, Operand, Query};
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use support::TestDocument;
|
use support::TestDocument;
|
||||||
|
|
||||||
@@ -149,3 +149,92 @@ fn does_query_work_with_greater_than_equal() {
|
|||||||
}
|
}
|
||||||
assert_eq!(holder.len(), 0, "got {:?}", holder);
|
assert_eq!(holder.len(), 0, "got {:?}", holder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn can_query_use_multiple_fields() {
|
||||||
|
let mut mtt = MoreThanText::new();
|
||||||
|
let test_doc = TestDocument::new(vec![FieldType::StaticString, FieldType::StaticString]);
|
||||||
|
mtt.create_document(test_doc.get_docdef()).unwrap();
|
||||||
|
let input = vec![
|
||||||
|
vec!["a", "a"],
|
||||||
|
vec!["a", "b"],
|
||||||
|
vec!["b", "a"],
|
||||||
|
vec!["b", "b"],
|
||||||
|
];
|
||||||
|
test_doc.populate_multiple(&mut mtt, input);
|
||||||
|
let mut calc1 = Calculation::new(Operand::Equal);
|
||||||
|
calc1.add_value("a").unwrap();
|
||||||
|
calc1.add_value(CalcValue::Existing(FieldType::StaticString)).unwrap();
|
||||||
|
let mut calc2 = Calculation::new(Operand::Equal);
|
||||||
|
calc2.add_value("b").unwrap();
|
||||||
|
calc2.add_value(CalcValue::Existing(FieldType::StaticString)).unwrap();
|
||||||
|
let mut query = Query::new(test_doc.get_doc_name());
|
||||||
|
query.add(test_doc.get_field_name(0), calc1);
|
||||||
|
query.add(test_doc.get_field_name(1), calc2);
|
||||||
|
let results = mtt.records(query).unwrap();
|
||||||
|
assert_eq!(results.len(), 1, "got {:?}", results);
|
||||||
|
let rec = results.iter().last().unwrap();
|
||||||
|
assert_eq!(rec.get(test_doc.get_field_name(0)).unwrap(), "a".into());
|
||||||
|
assert_eq!(rec.get(test_doc.get_field_name(1)).unwrap(), "b".into());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn can_query_use_multiple_indexed_fields() {
|
||||||
|
let mut mtt = MoreThanText::new();
|
||||||
|
let test_doc = TestDocument::new(vec![FieldType::StaticString, FieldType::StaticString]);
|
||||||
|
let mut docdef = test_doc.get_docdef();
|
||||||
|
docdef.add_index(&test_doc.get_field_name(0), IndexType::Index).unwrap();
|
||||||
|
docdef.add_index(&test_doc.get_field_name(1), IndexType::Index).unwrap();
|
||||||
|
mtt.create_document(docdef).unwrap();
|
||||||
|
let input = vec![
|
||||||
|
vec!["a", "a"],
|
||||||
|
vec!["a", "b"],
|
||||||
|
vec!["b", "a"],
|
||||||
|
vec!["b", "b"],
|
||||||
|
];
|
||||||
|
test_doc.populate_multiple(&mut mtt, input);
|
||||||
|
let mut calc1 = Calculation::new(Operand::Equal);
|
||||||
|
calc1.add_value("a").unwrap();
|
||||||
|
calc1.add_value(CalcValue::Existing(FieldType::StaticString)).unwrap();
|
||||||
|
let mut calc2 = Calculation::new(Operand::Equal);
|
||||||
|
calc2.add_value("b").unwrap();
|
||||||
|
calc2.add_value(CalcValue::Existing(FieldType::StaticString)).unwrap();
|
||||||
|
let mut query = Query::new(test_doc.get_doc_name());
|
||||||
|
query.add(test_doc.get_field_name(0), calc1);
|
||||||
|
query.add(test_doc.get_field_name(1), calc2);
|
||||||
|
let results = mtt.records(query).unwrap();
|
||||||
|
assert_eq!(results.len(), 1, "got {:?}", results);
|
||||||
|
let rec = results.iter().last().unwrap();
|
||||||
|
assert_eq!(rec.get(test_doc.get_field_name(0)).unwrap(), "a".into());
|
||||||
|
assert_eq!(rec.get(test_doc.get_field_name(1)).unwrap(), "b".into());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn can_query_use_multiple_mixed_index_fields() {
|
||||||
|
let mut mtt = MoreThanText::new();
|
||||||
|
let test_doc = TestDocument::new(vec![FieldType::StaticString, FieldType::StaticString]);
|
||||||
|
let mut docdef = test_doc.get_docdef();
|
||||||
|
docdef.add_index(&test_doc.get_field_name(0), IndexType::Index).unwrap();
|
||||||
|
mtt.create_document(docdef).unwrap();
|
||||||
|
let input = vec![
|
||||||
|
vec!["a", "a"],
|
||||||
|
vec!["a", "b"],
|
||||||
|
vec!["b", "a"],
|
||||||
|
vec!["b", "b"],
|
||||||
|
];
|
||||||
|
test_doc.populate_multiple(&mut mtt, input);
|
||||||
|
let mut calc1 = Calculation::new(Operand::Equal);
|
||||||
|
calc1.add_value("a").unwrap();
|
||||||
|
calc1.add_value(CalcValue::Existing(FieldType::StaticString)).unwrap();
|
||||||
|
let mut calc2 = Calculation::new(Operand::Equal);
|
||||||
|
calc2.add_value("b").unwrap();
|
||||||
|
calc2.add_value(CalcValue::Existing(FieldType::StaticString)).unwrap();
|
||||||
|
let mut query = Query::new(test_doc.get_doc_name());
|
||||||
|
query.add(test_doc.get_field_name(0), calc1);
|
||||||
|
query.add(test_doc.get_field_name(1), calc2);
|
||||||
|
let results = mtt.records(query).unwrap();
|
||||||
|
assert_eq!(results.len(), 1, "got {:?}", results);
|
||||||
|
let rec = results.iter().last().unwrap();
|
||||||
|
assert_eq!(rec.get(test_doc.get_field_name(0)).unwrap(), "a".into());
|
||||||
|
assert_eq!(rec.get(test_doc.get_field_name(1)).unwrap(), "b".into());
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user