From 85e731229e63073257c4cd85bfa3ca68ada6d48f Mon Sep 17 00:00:00 2001 From: Bruno Casali Date: Thu, 30 Mar 2023 13:29:48 +0100 Subject: [PATCH 1/2] Add csv_delimiter option when adding CSV documents --- lib/meilisearch/index.rb | 8 ++++++-- spec/meilisearch/index/documents_spec.rb | 17 +++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/lib/meilisearch/index.rb b/lib/meilisearch/index.rb index 45f1364e..3d462267 100644 --- a/lib/meilisearch/index.rb +++ b/lib/meilisearch/index.rb @@ -96,9 +96,13 @@ def add_documents_ndjson(documents, primary_key = nil) alias replace_documents_ndjson add_documents_ndjson alias add_or_replace_documents_ndjson add_documents_ndjson - def add_documents_csv(documents, primary_key = nil) + def add_documents_csv(documents, primary_key = nil, delimiter = nil) options = { headers: { 'Content-Type' => 'text/csv' }, convert_body?: false } - http_post "/indexes/#{@uid}/documents", documents, { primaryKey: primary_key }.compact, options + + http_post "/indexes/#{@uid}/documents", documents, { + primaryKey: primary_key, + csvDelimiter: delimiter + }.compact, options end alias replace_documents_csv add_documents_csv alias add_or_replace_documents_csv add_documents_csv diff --git a/spec/meilisearch/index/documents_spec.rb b/spec/meilisearch/index/documents_spec.rb index 9d629ed4..6dbe3d53 100644 --- a/spec/meilisearch/index/documents_spec.rb +++ b/spec/meilisearch/index/documents_spec.rb @@ -78,6 +78,23 @@ expect(index.documents['results'].count).to eq(3) end + it 'adds CSV documents (as an array of documents with a different separator)' do + documents = <<~CSV + "objectRef:number"|"title:string"|"comment:string" + "1239"|"Pride and Prejudice"|"A great book" + "4569"|"Le Petit Prince"|"A french book" + "49"|"Harry Potter and the Half-Blood Prince"|"The best book" + CSV + + response = index.add_documents_csv(documents, 'objectRef', '|') + index.wait_for_task(response['taskUid']) + + expect(index.documents['results'].count).to eq(3) + expect(index.documents['results'][1]['objectRef']).to eq(4569) + expect(index.documents['results'][1]['title']).to eq('Le Petit Prince') + expect(index.documents['results'][1]['comment']).to eq('A french book') + end + it 'adds documents in a batch (as a array of documents)' do task = index.add_documents_in_batches(documents, 5) expect(task).to be_a(Array) From ee293e0b3e71d7cf8c7adf3705a0b46eee8f9cd0 Mon Sep 17 00:00:00 2001 From: Bruno Casali Date: Thu, 30 Mar 2023 13:31:22 +0100 Subject: [PATCH 2/2] Regenerate rubocop-todo file --- .rubocop_todo.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index c7748c6c..01a5cdf0 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2022-07-27 15:08:15 UTC using RuboCop version 1.32.0. +# on 2023-03-30 12:31:09 UTC using RuboCop version 1.48.1. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -8,22 +8,22 @@ # Offense count: 1 # This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: Include. +# Configuration parameters: Severity, Include. # Include: **/*.gemspec Gemspec/RequireMFA: Exclude: - 'meilisearch.gemspec' -# Offense count: 46 -# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods. -# IgnoredMethods: refine +# Offense count: 45 +# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns. +# AllowedMethods: refine Metrics/BlockLength: - Max: 626 + Max: 624 # Offense count: 2 # Configuration parameters: CountComments, CountAsOne. Metrics/ClassLength: - Max: 317 + Max: 318 # Offense count: 1 # Configuration parameters: Max, CountKeywordArgs.