Add a simple test to check that attributes are ranking correctly

This commit is contained in:
Kerollmops 2023-04-12 18:17:28 +02:00 committed by Loïc Lecrenier
parent 30f7bd03f6
commit d9cebff61c
3 changed files with 60 additions and 1 deletions

View File

@ -25,7 +25,7 @@ impl RankingRuleGraphTrait for AttributeGraph {
universe: &RoaringBitmap, universe: &RoaringBitmap,
) -> Result<ComputedCondition> { ) -> Result<ComputedCondition> {
let AttributeCondition { term, .. } = condition; let AttributeCondition { term, .. } = condition;
// maybe compute_query_term_subset_docids should accept a universe as argument // maybe compute_query_term_subset_docids_within_field_id should accept a universe as argument
let mut docids = compute_query_term_subset_docids_within_field_id( let mut docids = compute_query_term_subset_docids_within_field_id(
ctx, ctx,
&term.term_subset, &term.term_subset,

View File

@ -0,0 +1,58 @@
use std::collections::HashMap;
use crate::{
index::tests::TempIndex, search::new::tests::collect_field_values, Criterion, Search,
SearchResult, TermsMatchingStrategy,
};
fn create_index() -> TempIndex {
let index = TempIndex::new();
index
.update_settings(|s| {
s.set_primary_key("id".to_owned());
s.set_searchable_fields(vec![
"title".to_owned(),
"description".to_owned(),
"plot".to_owned(),
]);
s.set_criteria(vec![Criterion::Attribute]);
})
.unwrap();
index
.add_documents(documents!([
{
"id": 0,
"title": "the quick brown fox jumps over the lazy dog",
"description": "Pack my box with five dozen liquor jugs",
"plot": "How vexingly quick daft zebras jump",
},
{
"id": 1,
"title": "Pack my box with five dozen liquor jugs",
"description": "the quick brown foxes jump over the lazy dog",
"plot": "How vexingly quick daft zebras jump",
},
{
"id": 2,
"title": "How vexingly quick daft zebras jump",
"description": "Pack my box with five dozen liquor jugs",
"plot": "the quick brown fox jumps over the lazy dog",
}
]))
.unwrap();
index
}
#[test]
fn test_attributes_are_ranked_correctly() {
let index = create_index();
let txn = index.read_txn().unwrap();
let mut s = Search::new(&txn, &index);
s.terms_matching_strategy(TermsMatchingStrategy::All);
s.query("the quick brown fox");
let SearchResult { documents_ids, .. } = s.execute().unwrap();
insta::assert_snapshot!(format!("{documents_ids:?}"), @"[0, 1, 2]");
}

View File

@ -1,3 +1,4 @@
pub mod attribute;
pub mod distinct; pub mod distinct;
#[cfg(feature = "default")] #[cfg(feature = "default")]
pub mod language; pub mod language;