Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ update_displayed_attributes_1: |-
])
reset_displayed_attributes_1: |-
client.index('movies').reset_displayed_attributes
compact_index_1: |-
client.index('INDEX_UID').compact
get_index_stats_1: |-
client.index('movies').stats
get_indexes_stats_1: |-
Expand Down
6 changes: 3 additions & 3 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2025-04-12 16:19:21 UTC using RuboCop version 1.75.1.
# on 2025-12-29 19:26:11 UTC using RuboCop version 1.75.8.
# 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
Expand All @@ -14,7 +14,7 @@ Metrics/AbcSize:
# Offense count: 4
# Configuration parameters: CountComments, CountAsOne.
Metrics/ClassLength:
Max: 537
Max: 541

# Offense count: 4
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
Expand All @@ -37,7 +37,7 @@ Style/IfUnlessModifier:
Exclude:
- 'lib/meilisearch/index.rb'

# Offense count: 2
# Offense count: 21
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, SplitStrings.
# URISchemes: http, https
Expand Down
13 changes: 13 additions & 0 deletions lib/meilisearch/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,19 @@ def indexing?
stats['isIndexing']
end

### COMPACT

# Run database compaction for this index.
#
# @note Meilisearch must temporarily duplicate the database during compaction. You need at least twice the current size of your database in free disk space.
#
# @see https://www.meilisearch.com/docs/reference/api/compact Meilisearch API Reference
# @return [Models::Task] The index compaction async task.
def compact
response = http_post "/indexes/#{@uid}/compact"
Models::Task.new(response, task_endpoint)
end

# Get the filed distribution of documents in the index.
#
# Calls {#stats}
Expand Down
13 changes: 13 additions & 0 deletions spec/meilisearch/index/compact_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

RSpec.describe Meilisearch::Index, '- Compact' do
it 'runs index compaction task' do
client.create_index('uid').await

task = client.fetch_index('uid').compact
expect(task.type).to eq('indexCompaction')

task.await
expect(task).to be_succeeded
end
end