Skip to content

Refactor Meilisearch::Index class #676

@psylone

Description

@psylone

Description

The Meilisearch::Index class is over 1400 lines long and handles too many responsibilities: documents, search, facet search, settings, stats, and compaction. This makes it difficult to navigate, maintain, and review changes.

The class can be split into focused modules, each responsible for a specific area of the API, without breaking the public interface.

Basic example

All public methods continue to work without changes:

index = client.index('movies')
index.add_documents([{ id: 1, title: 'Cloud Atlas' }])
index.search('cloud')
index.settings

Internally, the Meilisearch::Index class would include separate modules:

module Meilisearch
  class Index < HTTPRequest
    require 'meilisearch/index/documents'
    require 'meilisearch/index/search'
    require 'meilisearch/index/settings'
    # ...
  end
end

Each self-contained module would live under the Meilisearch::Index class namespace (e.g. Meilisearch::Index::Documents, Meilisearch::Index::Search):

# lib/meilisearch/index/search.rb
module Meilisearch
  class Index
    module Search
    end

    include Search
  end
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions