mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-03 03:47:02 +02:00
Merge #946
946: Sort displayedAttributes field r=MarinPostma a=gorogoroumaru Fix #943 displayedAttributes use the HashSet struct which is an unsorted structure, so I changed the implementation from HashSet into BTreeSet. Co-authored-by: gorogoroumaru <zokutyou2@gmail.com>
This commit is contained in:
commit
f359b64d59
8 changed files with 96 additions and 11 deletions
|
@ -1,4 +1,4 @@
|
|||
use std::collections::{BTreeMap, BTreeSet, HashSet};
|
||||
use std::collections::{BTreeMap, BTreeSet};
|
||||
|
||||
use actix_web::{delete, get, post};
|
||||
use actix_web::{web, HttpResponse};
|
||||
|
@ -405,7 +405,7 @@ async fn get_displayed(
|
|||
async fn update_displayed(
|
||||
data: web::Data<Data>,
|
||||
path: web::Path<IndexParam>,
|
||||
body: web::Json<Option<HashSet<String>>>,
|
||||
body: web::Json<Option<BTreeSet<String>>>,
|
||||
) -> Result<HttpResponse, ResponseError> {
|
||||
let index = data
|
||||
.db
|
||||
|
@ -539,7 +539,7 @@ fn get_indexed_attributes(schema: &Schema) -> Vec<String> {
|
|||
}
|
||||
}
|
||||
|
||||
fn get_displayed_attributes(schema: &Schema) -> HashSet<String> {
|
||||
fn get_displayed_attributes(schema: &Schema) -> BTreeSet<String> {
|
||||
if schema.is_displayed_all() {
|
||||
["*"].iter().map(|s| s.to_string()).collect()
|
||||
} else {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::collections::HashMap;
|
||||
use std::collections::{HashMap, BTreeMap};
|
||||
|
||||
use actix_web::web;
|
||||
use actix_web::HttpResponse;
|
||||
|
@ -24,7 +24,7 @@ pub fn services(cfg: &mut web::ServiceConfig) {
|
|||
struct IndexStatsResponse {
|
||||
number_of_documents: u64,
|
||||
is_indexing: bool,
|
||||
fields_distribution: HashMap<String, usize>,
|
||||
fields_distribution: BTreeMap<String, usize>,
|
||||
}
|
||||
|
||||
#[get("/indexes/{index_uid}/stats", wrap = "Authentication::Private")]
|
||||
|
|
|
@ -777,3 +777,33 @@ async fn update_existing_primary_key_is_error() {
|
|||
assert_eq!(response["errorCode"], "primary_key_already_present");
|
||||
assert_eq!(response["errorType"], "invalid_request_error");
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn test_facets_distribution_attribute() {
|
||||
let mut server = common::Server::test_server().await;
|
||||
|
||||
let (response, _status_code) = server.get_index_stats().await;
|
||||
|
||||
let expected = json!({
|
||||
"isIndexing": false,
|
||||
"numberOfDocuments":77,
|
||||
"fieldsDistribution":{
|
||||
"age":77,
|
||||
"gender":77,
|
||||
"phone":77,
|
||||
"name":77,
|
||||
"registered":77,
|
||||
"latitude":77,
|
||||
"email":77,
|
||||
"tags":77,
|
||||
"longitude":77,
|
||||
"color":77,
|
||||
"address":77,
|
||||
"balance":77,
|
||||
"about":77,
|
||||
"picture":77,
|
||||
},
|
||||
});
|
||||
|
||||
assert_json_eq!(expected, response, ordered: true);
|
||||
}
|
|
@ -468,3 +468,56 @@ async fn settings_that_contains_wildcard_is_wildcard() {
|
|||
assert_eq!(response["searchableAttributes"].as_array().unwrap()[0], "*");
|
||||
assert_eq!(response["displayedAttributes"].as_array().unwrap()[0], "*");
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn test_displayed_attributes_field() {
|
||||
let mut server = common::Server::test_server().await;
|
||||
|
||||
let body = json!({
|
||||
"rankingRules": [
|
||||
"typo",
|
||||
"words",
|
||||
"proximity",
|
||||
"attribute",
|
||||
"wordsPosition",
|
||||
"exactness",
|
||||
"desc(registered)",
|
||||
"desc(age)",
|
||||
],
|
||||
"distinctAttribute": "id",
|
||||
"searchableAttributes": [
|
||||
"id",
|
||||
"name",
|
||||
"color",
|
||||
"gender",
|
||||
"email",
|
||||
"phone",
|
||||
"address",
|
||||
"registered",
|
||||
"about"
|
||||
],
|
||||
"displayedAttributes": [
|
||||
"age",
|
||||
"email",
|
||||
"gender",
|
||||
"name",
|
||||
"registered",
|
||||
],
|
||||
"stopWords": [
|
||||
"ad",
|
||||
"in",
|
||||
"ut",
|
||||
],
|
||||
"synonyms": {
|
||||
"road": ["avenue", "street"],
|
||||
"street": ["avenue"],
|
||||
},
|
||||
"attributesForFaceting": ["name"],
|
||||
});
|
||||
|
||||
server.update_all_settings(body.clone()).await;
|
||||
|
||||
let (response, _status_code) = server.get_all_settings().await;
|
||||
|
||||
assert_json_eq!(body, response, ordered: true);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue