From f2d0a59f1da3a83875e57a38fb5c45e0af993b3f Mon Sep 17 00:00:00 2001 From: Tamo Date: Thu, 16 May 2024 01:06:33 +0200 Subject: [PATCH] when no searchable attributes are defined, makes all the weight equals to zero --- meilisearch/tests/search/hybrid.rs | 8 ++++---- meilisearch/tests/search/mod.rs | 2 +- meilisearch/tests/search/restrict_searchable.rs | 4 ++-- milli/src/fieldids_weights_map.rs | 4 ++-- milli/src/index.rs | 6 +++--- milli/src/update/settings.rs | 4 ++-- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/meilisearch/tests/search/hybrid.rs b/meilisearch/tests/search/hybrid.rs index 68ae4c0aa..67f7909b9 100644 --- a/meilisearch/tests/search/hybrid.rs +++ b/meilisearch/tests/search/hybrid.rs @@ -85,8 +85,8 @@ async fn simple_search() { ) .await; snapshot!(code, @"200 OK"); - snapshot!(response["hits"], @r###"[{"title":"Captain Planet","desc":"He's not part of the Marvel Cinematic Universe","id":"2","_vectors":{"default":[1.0,2.0]},"_rankingScore":0.996969696969697},{"title":"Captain Marvel","desc":"a Shazam ersatz","id":"3","_vectors":{"default":[2.0,3.0]},"_rankingScore":0.996969696969697},{"title":"Shazam!","desc":"a Captain Marvel ersatz","id":"1","_vectors":{"default":[1.0,3.0]},"_rankingScore":0.9472135901451112}]"###); - snapshot!(response["semanticHitCount"], @"1"); + snapshot!(response["hits"], @r###"[{"title":"Captain Marvel","desc":"a Shazam ersatz","id":"3","_vectors":{"default":[2.0,3.0]},"_rankingScore":0.990290343761444},{"title":"Captain Planet","desc":"He's not part of the Marvel Cinematic Universe","id":"2","_vectors":{"default":[1.0,2.0]},"_rankingScore":0.9848484848484848},{"title":"Shazam!","desc":"a Captain Marvel ersatz","id":"1","_vectors":{"default":[1.0,3.0]},"_rankingScore":0.9472135901451112}]"###); + snapshot!(response["semanticHitCount"], @"2"); let (response, code) = index .search_post( @@ -331,7 +331,7 @@ async fn query_combination() { .await; snapshot!(code, @"200 OK"); - snapshot!(response["hits"], @r###"[{"title":"Captain Planet","desc":"He's not part of the Marvel Cinematic Universe","id":"2","_vectors":{"default":[1.0,2.0]},"_rankingScore":0.996969696969697},{"title":"Captain Marvel","desc":"a Shazam ersatz","id":"3","_vectors":{"default":[2.0,3.0]},"_rankingScore":0.996969696969697},{"title":"Shazam!","desc":"a Captain Marvel ersatz","id":"1","_vectors":{"default":[1.0,3.0]},"_rankingScore":0.8848484848484849}]"###); + snapshot!(response["hits"], @r###"[{"title":"Captain Planet","desc":"He's not part of the Marvel Cinematic Universe","id":"2","_vectors":{"default":[1.0,2.0]},"_rankingScore":0.9848484848484848},{"title":"Captain Marvel","desc":"a Shazam ersatz","id":"3","_vectors":{"default":[2.0,3.0]},"_rankingScore":0.9848484848484848},{"title":"Shazam!","desc":"a Captain Marvel ersatz","id":"1","_vectors":{"default":[1.0,3.0]},"_rankingScore":0.9242424242424242}]"###); snapshot!(response["semanticHitCount"], @"null"); // query + vector, no hybrid keyword => @@ -374,6 +374,6 @@ async fn query_combination() { .await; snapshot!(code, @"200 OK"); - snapshot!(response["hits"], @r###"[{"title":"Captain Planet","desc":"He's not part of the Marvel Cinematic Universe","id":"2","_vectors":{"default":[1.0,2.0]},"_rankingScore":0.9848484848484848}]"###); + snapshot!(response["hits"], @r###"[{"title":"Captain Planet","desc":"He's not part of the Marvel Cinematic Universe","id":"2","_vectors":{"default":[1.0,2.0]},"_rankingScore":0.9242424242424242}]"###); snapshot!(response["semanticHitCount"], @"0"); } diff --git a/meilisearch/tests/search/mod.rs b/meilisearch/tests/search/mod.rs index b4350f686..f601e2b03 100644 --- a/meilisearch/tests/search/mod.rs +++ b/meilisearch/tests/search/mod.rs @@ -921,7 +921,7 @@ async fn test_score_details() { "order": 3, "attributeRankingOrderScore": 1.0, "queryWordDistanceScore": 0.8095238095238095, - "score": 0.9727891156462584 + "score": 0.8095238095238095 }, "exactness": { "order": 4, diff --git a/meilisearch/tests/search/restrict_searchable.rs b/meilisearch/tests/search/restrict_searchable.rs index 7bbdca38f..f52efa1f4 100644 --- a/meilisearch/tests/search/restrict_searchable.rs +++ b/meilisearch/tests/search/restrict_searchable.rs @@ -285,10 +285,10 @@ async fn attributes_ranking_rule_order() { @r###" [ { - "id": "2" + "id": "1" }, { - "id": "1" + "id": "2" } ] "### diff --git a/milli/src/fieldids_weights_map.rs b/milli/src/fieldids_weights_map.rs index 5ca2a6146..a737632a4 100644 --- a/milli/src/fieldids_weights_map.rs +++ b/milli/src/fieldids_weights_map.rs @@ -21,9 +21,9 @@ impl FieldidsWeightsMap { /// Create the map from the fields ids maps. /// Should only be called in the case there are NO searchable attributes. - /// The weights and the fields ids will have the same values. + /// All the fields will be inserted in the order of the fields ids map with a weight of 0. pub fn from_field_id_map_without_searchable(fid_map: &FieldsIdsMap) -> Self { - FieldidsWeightsMap { map: fid_map.ids().map(|fid| (fid, fid)).collect() } + FieldidsWeightsMap { map: fid_map.ids().map(|fid| (fid, 0)).collect() } } /// Removes a field id from the map, returning the associated weight previously in the map. diff --git a/milli/src/index.rs b/milli/src/index.rs index 36f0b339e..42b9cb111 100644 --- a/milli/src/index.rs +++ b/milli/src/index.rs @@ -2492,7 +2492,7 @@ pub(crate) mod tests { db_snap!(index, fieldids_weights_map, @r###" fid weight 0 0 | - 1 1 | + 1 0 | "###); index.delete_documents(Default::default()); @@ -2512,7 +2512,7 @@ pub(crate) mod tests { db_snap!(index, fieldids_weights_map, @r###" fid weight 0 0 | - 1 1 | + 1 0 | "###); index @@ -2537,7 +2537,7 @@ pub(crate) mod tests { db_snap!(index, fieldids_weights_map, @r###" fid weight 0 0 | - 1 1 | + 1 0 | "###); let rtxn = index.read_txn().unwrap(); diff --git a/milli/src/update/settings.rs b/milli/src/update/settings.rs index 046644dc4..0599bb9d8 100644 --- a/milli/src/update/settings.rs +++ b/milli/src/update/settings.rs @@ -1587,8 +1587,8 @@ mod tests { db_snap!(index, fieldids_weights_map, @r###" fid weight 0 0 | - 1 1 | - 2 2 | + 1 0 | + 2 0 | "###); // Check that the searchable field have been reset and documents are found now.