mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-03 11:57:07 +02:00
rename identifier into primaryKey; fix #514
This commit is contained in:
parent
8ffa80883a
commit
c984d8d5a5
24 changed files with 142 additions and 142 deletions
|
@ -285,8 +285,8 @@ impl Server {
|
|||
self.delete_request_async(&url)
|
||||
}
|
||||
|
||||
pub fn get_identifier(&mut self) -> (Value, StatusCode) {
|
||||
let url = format!("/indexes/{}/settings/identifier", self.uid);
|
||||
pub fn get_primary_key(&mut self) -> (Value, StatusCode) {
|
||||
let url = format!("/indexes/{}/settings/primary_key", self.uid);
|
||||
self.get_request(&url)
|
||||
}
|
||||
|
||||
|
@ -394,7 +394,7 @@ impl Server {
|
|||
pub fn populate_movies(&mut self) {
|
||||
let body = json!({
|
||||
"uid": "movies",
|
||||
"identifier": "id",
|
||||
"primaryKey": "id",
|
||||
});
|
||||
self.create_index(body);
|
||||
|
||||
|
|
|
@ -417,14 +417,14 @@ fn create_index_failed() {
|
|||
|
||||
// Resolve issue https://github.com/meilisearch/MeiliSearch/issues/492
|
||||
#[test]
|
||||
fn create_index_with_identifier_and_index() {
|
||||
fn create_index_with_primary_key_and_index() {
|
||||
let mut server = common::Server::with_uid("movies");
|
||||
|
||||
// 1 - Create the index
|
||||
|
||||
let body = json!({
|
||||
"uid": "movies",
|
||||
"identifier": "id",
|
||||
"primaryKey": "id",
|
||||
});
|
||||
|
||||
let (_response, status_code) = server.create_index(body);
|
||||
|
@ -512,84 +512,84 @@ fn create_index_with_invalid_uid() {
|
|||
assert_eq!(message, "Index must have a valid uid; Index uid can be of type integer or string only composed of alphanumeric characters, hyphens (-) and underscores (_).");
|
||||
}
|
||||
|
||||
// Test that it's possible to add identifier if it's not already set on index creation
|
||||
// Test that it's possible to add primary_key if it's not already set on index creation
|
||||
#[test]
|
||||
fn create_index_and_add_indentifier_after() {
|
||||
let mut server = common::Server::with_uid("movies");
|
||||
|
||||
// 1 - Create the index with no identifier
|
||||
// 1 - Create the index with no primary_key
|
||||
|
||||
let body = json!({
|
||||
"uid": "movies",
|
||||
});
|
||||
let (response, status_code) = server.create_index(body);
|
||||
assert_eq!(status_code, 201);
|
||||
assert_eq!(response["identifier"], json!(null));
|
||||
assert_eq!(response["primaryKey"], json!(null));
|
||||
|
||||
// 2 - Update the index and add an identifier.
|
||||
// 2 - Update the index and add an primary_key.
|
||||
|
||||
let body = json!({
|
||||
"identifier": "id",
|
||||
"primaryKey": "id",
|
||||
});
|
||||
|
||||
let (response, status_code) = server.update_index(body);
|
||||
assert_eq!(status_code, 200);
|
||||
eprintln!("response: {:#?}", response);
|
||||
assert_eq!(response["identifier"].as_str().unwrap(), "id");
|
||||
assert_eq!(response["primaryKey"].as_str().unwrap(), "id");
|
||||
|
||||
// 3 - Get index to verify if the identifier is good
|
||||
// 3 - Get index to verify if the primary_key is good
|
||||
|
||||
let (response, status_code) = server.get_index();
|
||||
assert_eq!(status_code, 200);
|
||||
assert_eq!(response["identifier"].as_str().unwrap(), "id");
|
||||
assert_eq!(response["primaryKey"].as_str().unwrap(), "id");
|
||||
|
||||
}
|
||||
|
||||
// Test that it's impossible to change the identifier
|
||||
// Test that it's impossible to change the primary_key
|
||||
#[test]
|
||||
fn create_index_and_update_indentifier_after() {
|
||||
let mut server = common::Server::with_uid("movies");
|
||||
|
||||
// 1 - Create the index with no identifier
|
||||
// 1 - Create the index with no primary_key
|
||||
|
||||
let body = json!({
|
||||
"uid": "movies",
|
||||
"identifier": "id",
|
||||
"primaryKey": "id",
|
||||
});
|
||||
let (response, status_code) = server.create_index(body);
|
||||
assert_eq!(status_code, 201);
|
||||
assert_eq!(response["identifier"].as_str().unwrap(), "id");
|
||||
assert_eq!(response["primaryKey"].as_str().unwrap(), "id");
|
||||
|
||||
// 2 - Update the index and add an identifier.
|
||||
// 2 - Update the index and add an primary_key.
|
||||
|
||||
let body = json!({
|
||||
"identifier": "skuid",
|
||||
"primaryKey": "skuid",
|
||||
});
|
||||
|
||||
let (_response, status_code) = server.update_index(body);
|
||||
assert_eq!(status_code, 400);
|
||||
|
||||
// 3 - Get index to verify if the identifier still the first one
|
||||
// 3 - Get index to verify if the primary_key still the first one
|
||||
|
||||
let (response, status_code) = server.get_index();
|
||||
assert_eq!(status_code, 200);
|
||||
assert_eq!(response["identifier"].as_str().unwrap(), "id");
|
||||
assert_eq!(response["primaryKey"].as_str().unwrap(), "id");
|
||||
}
|
||||
|
||||
|
||||
// Test that schema inference work well
|
||||
#[test]
|
||||
fn create_index_without_identifier_and_add_document() {
|
||||
fn create_index_without_primary_key_and_add_document() {
|
||||
let mut server = common::Server::with_uid("movies");
|
||||
|
||||
// 1 - Create the index with no identifier
|
||||
// 1 - Create the index with no primary_key
|
||||
|
||||
let body = json!({
|
||||
"uid": "movies",
|
||||
});
|
||||
let (response, status_code) = server.create_index(body);
|
||||
assert_eq!(status_code, 201);
|
||||
assert_eq!(response["identifier"], json!(null));
|
||||
assert_eq!(response["primaryKey"], json!(null));
|
||||
|
||||
// 2 - Add a document
|
||||
|
||||
|
@ -600,27 +600,27 @@ fn create_index_without_identifier_and_add_document() {
|
|||
|
||||
server.add_or_update_multiple_documents(body);
|
||||
|
||||
// 3 - Get index to verify if the identifier is good
|
||||
// 3 - Get index to verify if the primary_key is good
|
||||
|
||||
let (response, status_code) = server.get_index();
|
||||
assert_eq!(status_code, 200);
|
||||
assert_eq!(response["identifier"].as_str().unwrap(), "id");
|
||||
assert_eq!(response["primaryKey"].as_str().unwrap(), "id");
|
||||
}
|
||||
|
||||
|
||||
// Test search with no identifier
|
||||
// Test search with no primary_key
|
||||
#[test]
|
||||
fn create_index_without_identifier_and_search() {
|
||||
fn create_index_without_primary_key_and_search() {
|
||||
let mut server = common::Server::with_uid("movies");
|
||||
|
||||
// 1 - Create the index with no identifier
|
||||
// 1 - Create the index with no primary_key
|
||||
|
||||
let body = json!({
|
||||
"uid": "movies",
|
||||
});
|
||||
let (response, status_code) = server.create_index(body);
|
||||
assert_eq!(status_code, 201);
|
||||
assert_eq!(response["identifier"], json!(null));
|
||||
assert_eq!(response["primaryKey"], json!(null));
|
||||
|
||||
// 2 - Search
|
||||
|
||||
|
|
|
@ -644,7 +644,7 @@ fn search_with_settings_basic() {
|
|||
"desc(vote_average)"
|
||||
],
|
||||
"distinctAttribute": null,
|
||||
"identifier": "id",
|
||||
"primaryKey": "id",
|
||||
"searchableAttributes": [
|
||||
"title",
|
||||
"tagline",
|
||||
|
@ -751,7 +751,7 @@ fn search_with_settings_stop_words() {
|
|||
"desc(vote_average)"
|
||||
],
|
||||
"distinctAttribute": null,
|
||||
"identifier": "id",
|
||||
"primaryKey": "id",
|
||||
"searchableAttributes": [
|
||||
"title",
|
||||
"tagline",
|
||||
|
@ -858,7 +858,7 @@ fn search_with_settings_synonyms() {
|
|||
"desc(vote_average)"
|
||||
],
|
||||
"distinctAttribute": null,
|
||||
"identifier": "id",
|
||||
"primaryKey": "id",
|
||||
"searchableAttributes": [
|
||||
"title",
|
||||
"tagline",
|
||||
|
@ -970,7 +970,7 @@ fn search_with_settings_ranking_rules() {
|
|||
"desc(popularity)"
|
||||
],
|
||||
"distinctAttribute": null,
|
||||
"identifier": "id",
|
||||
"primaryKey": "id",
|
||||
"searchableAttributes": [
|
||||
"title",
|
||||
"tagline",
|
||||
|
@ -1077,7 +1077,7 @@ fn search_with_settings_searchable_attributes() {
|
|||
"desc(vote_average)"
|
||||
],
|
||||
"distinctAttribute": null,
|
||||
"identifier": "id",
|
||||
"primaryKey": "id",
|
||||
"searchableAttributes": [
|
||||
"tagline",
|
||||
"overview",
|
||||
|
@ -1183,7 +1183,7 @@ fn search_with_settings_displayed_attributes() {
|
|||
"desc(vote_average)"
|
||||
],
|
||||
"distinctAttribute": null,
|
||||
"identifier": "id",
|
||||
"primaryKey": "id",
|
||||
"searchableAttributes": [
|
||||
"title",
|
||||
"tagline",
|
||||
|
@ -1254,7 +1254,7 @@ fn search_with_settings_searchable_attributes_2() {
|
|||
"desc(vote_average)"
|
||||
],
|
||||
"distinctAttribute": null,
|
||||
"identifier": "id",
|
||||
"primaryKey": "id",
|
||||
"searchableAttributes": [
|
||||
"tagline",
|
||||
"overview",
|
||||
|
|
|
@ -291,7 +291,7 @@ fn test_default_settings_2() {
|
|||
let mut server = common::Server::with_uid("movies");
|
||||
let body = json!({
|
||||
"uid": "movies",
|
||||
"identifier": "id",
|
||||
"primaryKey": "id",
|
||||
});
|
||||
server.create_index(body);
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ fn index_new_fields_default() {
|
|||
let mut server = common::Server::with_uid("movies");
|
||||
let body = json!({
|
||||
"uid": "movies",
|
||||
"identifier": "id",
|
||||
"primaryKey": "id",
|
||||
});
|
||||
server.create_index(body);
|
||||
|
||||
|
@ -60,7 +60,7 @@ fn index_new_fields_true() {
|
|||
let mut server = common::Server::with_uid("movies");
|
||||
let body = json!({
|
||||
"uid": "movies",
|
||||
"identifier": "id",
|
||||
"primaryKey": "id",
|
||||
});
|
||||
server.create_index(body);
|
||||
|
||||
|
@ -116,7 +116,7 @@ fn index_new_fields_false() {
|
|||
let mut server = common::Server::with_uid("movies");
|
||||
let body = json!({
|
||||
"uid": "movies",
|
||||
"identifier": "id",
|
||||
"primaryKey": "id",
|
||||
});
|
||||
server.create_index(body);
|
||||
|
||||
|
@ -169,7 +169,7 @@ fn index_new_fields_true_then_false() {
|
|||
let mut server = common::Server::with_uid("movies");
|
||||
let body = json!({
|
||||
"uid": "movies",
|
||||
"identifier": "id",
|
||||
"primaryKey": "id",
|
||||
});
|
||||
server.create_index(body);
|
||||
|
||||
|
@ -228,7 +228,7 @@ fn index_new_fields_false_then_true() {
|
|||
let mut server = common::Server::with_uid("movies");
|
||||
let body = json!({
|
||||
"uid": "movies",
|
||||
"identifier": "id",
|
||||
"primaryKey": "id",
|
||||
});
|
||||
server.create_index(body);
|
||||
|
||||
|
|
|
@ -111,7 +111,7 @@ fn send_undefined_rule() {
|
|||
let mut server = common::Server::with_uid("movies");
|
||||
let body = json!({
|
||||
"uid": "movies",
|
||||
"identifier": "id",
|
||||
"primaryKey": "id",
|
||||
});
|
||||
server.create_index(body);
|
||||
|
||||
|
@ -128,7 +128,7 @@ fn send_malformed_custom_rule() {
|
|||
let mut server = common::Server::with_uid("movies");
|
||||
let body = json!({
|
||||
"uid": "movies",
|
||||
"identifier": "id",
|
||||
"primaryKey": "id",
|
||||
});
|
||||
server.create_index(body);
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ fn update_stop_words() {
|
|||
let mut server = common::Server::with_uid("movies");
|
||||
let body = json!({
|
||||
"uid": "movies",
|
||||
"identifier": "id",
|
||||
"primaryKey": "id",
|
||||
});
|
||||
server.create_index(body);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue