Add "position" part of the attribute ranking rule

This commit is contained in:
Loïc Lecrenier
2023-04-13 10:46:09 +02:00
parent 8edad8291b
commit bd9aba4d77
11 changed files with 314 additions and 31 deletions

View File

@ -95,7 +95,7 @@ fn create_index() -> TempIndex {
}
#[test]
fn test_attributes_simple() {
fn test_attribute_fid_simple() {
let index = create_index();
let txn = index.read_txn().unwrap();

View File

@ -0,0 +1,52 @@
use crate::{index::tests::TempIndex, 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!["text".to_owned()]);
s.set_criteria(vec![Criterion::Attribute]);
})
.unwrap();
index
.add_documents(documents!([
{
"id": 0,
"text": "do you know about the quick and talented brown fox",
},
{
"id": 1,
"text": "do you know about the quick brown fox",
},
{
"id": 2,
"text": "the quick and talented brown fox",
},
{
"id": 3,
"text": "fox brown quick the",
},
{
"id": 4,
"text": "the quick brown fox",
},
]))
.unwrap();
index
}
#[test]
fn test_attribute_fid_simple() {
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:?}"), @"[3, 4, 2, 1, 0]");
}

View File

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