use tantivy::schema::{STORED, TEXT};
use super::{
DEFAULT_ANALYZER, LaneAnalyzers, RESERVED_LANE_KEYS, SEARCHABLE_FIELD, lane_field, lane_options,
open_unfanned,
};
use crate::LaneIdent;
#[test]
fn the_default_lane_is_tantivys_own_text() {
assert_eq!(
lane_options(DEFAULT_ANALYZER, false),
TEXT,
"an unfanned corpus's field is `TEXT`",
);
assert_eq!(
lane_options(DEFAULT_ANALYZER, true),
TEXT | STORED,
"and `TEXT | STORED` where the declaration asked",
);
}
#[test]
fn a_named_analyzer_changes_the_tokenizer_and_nothing_else() {
let stemmed = lane_options("en_stem", false);
assert_ne!(stemmed, TEXT, "the tokenizer name is part of the options");
let indexing = stemmed
.get_indexing_options()
.expect("a lane field is indexed");
assert_eq!(indexing.tokenizer(), "en_stem");
assert!(indexing.fieldnorms(), "fieldnorms stay on");
assert_eq!(
indexing.index_option(),
TEXT
.get_indexing_options()
.expect("`TEXT` is indexed")
.index_option(),
"positions are still recorded, so a phrase query still works",
);
}
#[test]
fn the_undetermined_lane_is_the_field_this_backend_always_had() {
assert_eq!(lane_field(LaneIdent::UND), SEARCHABLE_FIELD);
assert_eq!(lane_field(LaneIdent::new("zh")), "zh");
assert_eq!(lane_field(LaneIdent::new("rest")), "rest");
}
#[test]
fn an_unfanned_slot_holds_exactly_the_four_fields() {
let dir = tempfile::tempdir().expect("a temporary directory");
let opened = open_unfanned(&dir.path().join("corpus"), false).expect("the slot opens");
let held: Vec<String> = opened
.index
.schema()
.fields()
.map(|(_, entry)| entry.name().to_owned())
.collect();
assert_eq!(held, ["source", "identity", "key", "body"]);
assert_eq!(
opened.fields.searchable(),
vec![opened.fields.body()],
"one searchable field, and it is the body",
);
}
#[test]
fn the_reserved_keys_are_the_schemas_own_field_names() {
assert_eq!(
RESERVED_LANE_KEYS,
["source", "identity", "key", SEARCHABLE_FIELD]
);
}
#[test]
fn the_analyzer_table_answers_by_lane() {
let knobs = LaneAnalyzers::new()
.with("zh", "raw")
.with("en", "en_stem")
.with("zh", "whitespace");
assert_eq!(knobs.analyzer("en"), Some("en_stem"));
assert_eq!(
knobs.analyzer("zh"),
Some("whitespace"),
"the last word for a lane is the one that counts",
);
assert_eq!(
knobs.analyzer("rest"),
None,
"a lane the table says nothing about rides tantivy's own default",
);
assert_eq!(
knobs.iter().collect::<Vec<_>>(),
[("zh", "whitespace"), ("en", "en_stem")],
"in the order the lanes were first named",
);
}