mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-12-23 21:20:24 +01:00
Add distinct integration tests
This commit is contained in:
parent
9f4184208e
commit
f496cd320d
76
milli/tests/search/distinct.rs
Normal file
76
milli/tests/search/distinct.rs
Normal file
@ -0,0 +1,76 @@
|
||||
use std::collections::HashSet;
|
||||
|
||||
use big_s::S;
|
||||
use milli::update::Settings;
|
||||
use milli::{Criterion, Search, SearchResult};
|
||||
use Criterion::*;
|
||||
|
||||
use crate::search::{self, EXTERNAL_DOCUMENTS_IDS};
|
||||
|
||||
macro_rules! test_distinct {
|
||||
($func:ident, $distinct:ident, $criteria:expr) => {
|
||||
#[test]
|
||||
fn $func() {
|
||||
let criteria = $criteria;
|
||||
let index = search::setup_search_index_with_criteria(&criteria);
|
||||
|
||||
// update distinct attribute
|
||||
let mut wtxn = index.write_txn().unwrap();
|
||||
let mut builder = Settings::new(&mut wtxn, &index, 0);
|
||||
builder.set_distinct_field(S(stringify!($distinct)));
|
||||
builder.execute(|_, _| ()).unwrap();
|
||||
wtxn.commit().unwrap();
|
||||
|
||||
let mut rtxn = index.read_txn().unwrap();
|
||||
|
||||
let mut search = Search::new(&mut rtxn, &index);
|
||||
search.query(search::TEST_QUERY);
|
||||
search.limit(EXTERNAL_DOCUMENTS_IDS.len());
|
||||
search.authorize_typos(true);
|
||||
search.optional_words(true);
|
||||
|
||||
let SearchResult { documents_ids, .. } = search.execute().unwrap();
|
||||
|
||||
let mut distinct_values = HashSet::new();
|
||||
let expected_external_ids: Vec<_> = search::expected_order(&criteria, true, true)
|
||||
.into_iter()
|
||||
.filter_map(|d| {
|
||||
if distinct_values.contains(&d.$distinct) {
|
||||
None
|
||||
} else {
|
||||
distinct_values.insert(d.$distinct.to_owned());
|
||||
Some(d.id)
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
|
||||
let documents_ids = search::internal_to_external_ids(&index, &documents_ids);
|
||||
assert_eq!(documents_ids, expected_external_ids);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
test_distinct!(distinct_string_default_criteria, tag, vec![Words, Typo, Proximity, Attribute, Exactness]);
|
||||
#[rustfmt::skip]
|
||||
test_distinct!(distinct_number_default_criteria, asc_desc_rank, vec![Words, Typo, Proximity, Attribute, Exactness]);
|
||||
#[rustfmt::skip]
|
||||
test_distinct!(distinct_string_criterion_words, tag, vec![Words]);
|
||||
#[rustfmt::skip]
|
||||
test_distinct!(distinct_number_criterion_words, asc_desc_rank, vec![Words]);
|
||||
#[rustfmt::skip]
|
||||
test_distinct!(distinct_string_criterion_words_typo, tag, vec![Words, Typo]);
|
||||
#[rustfmt::skip]
|
||||
test_distinct!(distinct_number_criterion_words_typo, asc_desc_rank, vec![Words, Typo]);
|
||||
#[rustfmt::skip]
|
||||
test_distinct!(distinct_string_criterion_words_proximity, tag, vec![Words, Proximity]);
|
||||
#[rustfmt::skip]
|
||||
test_distinct!(distinct_number_criterion_words_proximity, asc_desc_rank, vec![Words, Proximity]);
|
||||
#[rustfmt::skip]
|
||||
test_distinct!(distinct_string_criterion_words_attribute, tag, vec![Words, Attribute]);
|
||||
#[rustfmt::skip]
|
||||
test_distinct!(distinct_number_criterion_words_attribute, asc_desc_rank, vec![Words, Attribute]);
|
||||
#[rustfmt::skip]
|
||||
test_distinct!(distinct_string_criterion_words_exactness, tag, vec![Words, Exactness]);
|
||||
#[rustfmt::skip]
|
||||
test_distinct!(distinct_number_criterion_words_exactness, asc_desc_rank, vec![Words, Exactness]);
|
@ -9,6 +9,7 @@ use milli::{Criterion, DocumentId, Index};
|
||||
use serde::Deserialize;
|
||||
use slice_group_by::GroupBy;
|
||||
|
||||
mod distinct;
|
||||
mod filters;
|
||||
mod query_criteria;
|
||||
|
||||
|
@ -11,10 +11,10 @@ const ALLOW_OPTIONAL_WORDS: bool = true;
|
||||
const DISALLOW_OPTIONAL_WORDS: bool = false;
|
||||
|
||||
macro_rules! test_criterion {
|
||||
($func:ident, $optional_word:ident, $authorize_typos:ident , $criterion:expr) => {
|
||||
($func:ident, $optional_word:ident, $authorize_typos:ident, $criteria:expr) => {
|
||||
#[test]
|
||||
fn $func() {
|
||||
let criteria = $criterion;
|
||||
let criteria = $criteria;
|
||||
let index = search::setup_search_index_with_criteria(&criteria);
|
||||
let mut rtxn = index.read_txn().unwrap();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user