mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-27 07:14:26 +01:00
Merge pull request #800 from MarinPostma/distinct-attribute-return-correct-name
Fix distinct attribute returning id instead of name
This commit is contained in:
commit
21567eeb8f
@ -110,14 +110,14 @@ async fn get_all(
|
||||
|
||||
println!("{:?}", attributes_for_faceting);
|
||||
|
||||
let searchable_attributes = schema.clone().map(|s| {
|
||||
let searchable_attributes = schema.as_ref().map(|s| {
|
||||
s.indexed_name()
|
||||
.iter()
|
||||
.map(|s| s.to_string())
|
||||
.collect::<Vec<String>>()
|
||||
});
|
||||
|
||||
let displayed_attributes = schema.clone().map(|s| {
|
||||
let displayed_attributes = schema.as_ref().map(|s| {
|
||||
s.displayed_name()
|
||||
.iter()
|
||||
.map(|s| s.to_string())
|
||||
@ -253,7 +253,12 @@ async fn get_distinct(
|
||||
.open_index(&path.index_uid)
|
||||
.ok_or(Error::index_not_found(&path.index_uid))?;
|
||||
let reader = data.db.main_read_txn()?;
|
||||
let distinct_attribute = index.main.distinct_attribute(&reader)?;
|
||||
let distinct_attribute_id = index.main.distinct_attribute(&reader)?;
|
||||
let schema = index.main.schema(&reader)?;
|
||||
let distinct_attribute = match (schema, distinct_attribute_id) {
|
||||
(Some(schema), Some(id)) => schema.name(id).map(str::to_string),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
Ok(HttpResponse::Ok().json(distinct_attribute))
|
||||
}
|
||||
|
@ -677,3 +677,17 @@ async fn search_with_settings_searchable_attributes_2() {
|
||||
let (response, _status_code) = server.search_get(query).await;
|
||||
assert_json_eq!(expect, response["hits"].clone(), ordered: false);
|
||||
}
|
||||
|
||||
// issue #798
|
||||
#[actix_rt::test]
|
||||
async fn distinct_attributes_returns_name_not_id() {
|
||||
let mut server = common::Server::test_server().await;
|
||||
let settings = json!({
|
||||
"distinctAttribute": "color",
|
||||
});
|
||||
server.update_all_settings(settings).await;
|
||||
let (response, _) = server.get_all_settings().await;
|
||||
assert_eq!(response["distinctAttribute"], "color");
|
||||
let (response, _) = server.get_distinct_attribute().await;
|
||||
assert_eq!(response, "color");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user