Skip to content

Latest commit

Β 

History

156 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Meilisearch Network Search for WordPress

Replace WordPress default search with Meilisearch across your entire multisite network with automatic autocomplete.

Features

  • 🌐 Network-wide search - Search across all sites in your WordPress multisite network
  • ⚑ Lightning fast - Powered by Meilisearch's instant search engine
  • πŸ” Automatic autocomplete - Real-time search suggestions as you type
  • 🎯 Easy configuration - Network admin settings page with connection testing
  • πŸ”§ WP-CLI support - Bulk indexing and management via command line
  • πŸ”„ Auto-sync - Content automatically indexed on publish/update
  • πŸš€ Modern PHP - Uses Fiber + ReactPHP for concurrent operations (PHP 8.1+)
  • πŸ“Š Real-time Metrics - Monitor index statistics and performance without cache
  • πŸ”Ž Index Analyzer - Automatically detect multiple WordPress networks and their index patterns
  • πŸ”— Multi-Pattern Search - Search across multiple WordPress networks simultaneously

Requirements

  • WordPress 6.0+
  • WordPress Multisite
  • PHP 8.1+
  • Self-hosted Meilisearch instance
  • Composer (for development)

Installation

1. Install Meilisearch

Follow the official Meilisearch installation guide.

For Docker:

docker run -d \
  --name meilisearch \
  -p 7700:7700 \
  -e MEILI_MASTER_KEY=your-master-key \
  -v $(pwd)/meili_data:/meili_data \
  getmeili/meilisearch:latest

2. Install Plugin

  1. Clone or download this repository to wp-content/plugins/meilisearch
  2. Run composer install --no-dev in the plugin directory
  3. Network activate the plugin in WordPress Network Admin

3. Configure

  1. Go to Network Admin β†’ Settings β†’ Meilisearch
  2. Enter your Meilisearch host URL (e.g., http://localhost:7700)
  3. Enter your Meilisearch master key
  4. Enable the plugin
  5. Save settings

4. Index Content

Use WP-CLI to index all sites:

wp meilisearch index --network

Or index a specific site:

wp meilisearch index --url=site.example.com

Configuration

The plugin is configured only in the Network Admin panel:

  • Network Admin β†’ Meilisearch β†’ Dashboard - Overview and quick access
  • Network Admin β†’ Meilisearch β†’ Settings - Configure connection and index format
  • Network Admin β†’ Meilisearch β†’ Metrics - Real-time index statistics (no cache)
  • Network Admin β†’ Meilisearch β†’ Index Analyzer - Detect multiple WordPress networks and patterns
  • Network Admin β†’ Meilisearch β†’ Multi-Pattern Search - Configure cross-network search
  • Network Admin β†’ Meilisearch β†’ Experimental - Enable/disable experimental Meilisearch features

Settings are stored network-wide using get_site_option().

Index Analyzer

The Index Analyzer page helps identify and manage multiple WordPress networks sharing the same Meilisearch server:

  • Automatic Pattern Detection - Analyzes all indexes to identify naming patterns
  • Network URL Discovery - Maps index patterns to their WordPress network URLs
  • Multi-Network Support - Perfect for hosting multiple WordPress installations
  • Real-time Analysis - No caching, always shows current state

This is especially useful when:

  • Managing multiple WordPress Multisite installations
  • Each network uses different index naming formats
  • You need to identify which indexes belong to which network

Multi-Pattern Search

The Multi-Pattern Search page allows you to search across multiple WordPress networks that share the same Meilisearch server:

  • Cross-Network Search - Include results from other WordPress networks in your searches
  • Pattern Selection - Choose which index patterns to include in search results
  • Real-time Configuration - Changes take effect immediately without reindexing
  • Visual Interface - Easy checkbox selection with network URL display

Use cases:

  • Corporate Portals - Search across public and internal networks
  • Multi-Brand Sites - Unified search across different brand networks
  • Migration Support - Include both old and new index patterns during transitions

See full Multi-Pattern Search documentation for detailed usage.

WP-CLI Commands

O plugin inclui comandos WP-CLI completos para gerenciamento. Veja a documentaΓ§Γ£o completa.

Comandos Principais

# Verificar saΓΊde do servidor Meilisearch
wp meilisearch health

# Listar todos os Γ­ndices
wp meilisearch list_indexes

# Reindexar todos os blogs da rede
wp meilisearch reindex

# Reindexar blog especΓ­fico
wp meilisearch reindex --blog_id=2

# Buscar posts
wp meilisearch search "termo de busca"

# Ver estatΓ­sticas
wp meilisearch stats

# Criar Γ­ndice manualmente
wp meilisearch create_index 2

# Deletar Γ­ndice
wp meilisearch delete_index 2 --yes

Para mais detalhes, exemplos e casos de uso, consulte docs/WP-CLI.md.

Architecture

Multi-Index Strategy

Each site in the network gets its own Meilisearch index:

  • Site 1: wp_1_posts
  • Site 2: wp_2_posts
  • Site 3: wp_3_posts

Search Behavior

When a search is performed, the plugin:

  1. Intercepts the WordPress search query (pre_get_posts hook)
  2. Performs a multi-index search across all network sites
  3. Returns combined results ordered by relevance
  4. Maintains WordPress pagination

Auto-Indexing

Content is automatically indexed when:

  • A post is published or updated (save_post hook)
  • A post is deleted (delete_post hook)
  • A new site is created (wpmu_new_blog hook)
  • A site is deleted (wp_delete_site hook)

Indexed Content Types

The plugin indexes:

  • All post types (posts, pages, custom post types)
  • Post metadata (title, content, excerpt)
  • Taxonomies (categories, tags)
  • Author information
  • Timestamps for sorting

Development

Setup

# Install dependencies (Pest 4.x requires PHP 8.3+)
composer install

# Run tests (Pest)
composer test
# or
vendor/bin/pest

# Run tests with coverage
composer test:coverage

# Check code standards (phpcs is installed globally via Composer:
# composer global require squizlabs/php_codesniffer wp-coding-standards/wpcs phpcompatibility/phpcompatibility-wp
# ensure the Composer global bin dir is on your PATH, e.g. $(composer global config bin-dir --absolute))
phpcs

# Auto-fix code standards
phpcbf

# Lint / static analysis (mago)
composer mago:lint
composer mago:analyze

# Generate API documentation
bash bin/generate-docs.sh
# Or with composer
composer docs

Testing: unit tests use Pest 4.x and run in isolation with lightweight stubs for the WordPress functions they touch β€” no WordPress install or database is required. Because Pest 4 requires PHP 8.3+, the test suite runs on PHP 8.3 even though the plugin itself supports PHP 8.1+.

File Structure

meilisearch/
β”œβ”€β”€ includes/
β”‚   β”œβ”€β”€ class-client.php          # Meilisearch client wrapper
β”‚   β”œβ”€β”€ class-indexer.php         # Indexing logic
β”‚   β”œβ”€β”€ class-searcher.php        # Search queries
β”‚   β”œβ”€β”€ class-autocomplete.php    # Autocomplete API
β”‚   └── class-cli.php             # WP-CLI commands
β”œβ”€β”€ admin/
β”‚   β”œβ”€β”€ class-dashboard.php        # Dashboard overview
β”‚   β”œβ”€β”€ class-metrics.php          # Real-time metrics page
β”‚   β”œβ”€β”€ class-index-analyzer.php   # Network pattern analyzer
β”‚   └── class-network-settings.php # Network admin UI
β”œβ”€β”€ public/
β”‚   └── class-search-override.php  # Frontend search replacement
β”œβ”€β”€ assets/
β”‚   β”œβ”€β”€ js/autocomplete.js        # Frontend autocomplete
β”‚   └── css/autocomplete.css      # Autocomplete styles
β”œβ”€β”€ docs/
β”‚   └── WP-CLI.md                 # WP-CLI documentation
└── .github/
    └── copilot-instructions.md    # AI agent instructions

How It Works

1. Indexing with Fiber

The plugin uses PHP 8.1 Fibers for concurrent indexing:

$fiber = new Fiber(function() use ($site) {
    switch_to_blog($site->blog_id);
    // Index posts for this site
    restore_current_blog();
});
$fiber->start();

2. Multi-Index Search

Searches across all network indexes simultaneously:

$results = $client->multiSearch([
    ['indexUid' => 'wp_1_posts', 'q' => $query],
    ['indexUid' => 'wp_2_posts', 'q' => $query],
    ['indexUid' => 'wp_3_posts', 'q' => $query],
]);

3. Autocomplete

Real-time suggestions via REST API:

GET /wp-json/meilisearch/v1/autocomplete?q=search+term

Troubleshooting

Connection Failed

Check that Meilisearch is running:

curl http://localhost:7700/health

No Search Results

Reindex all content:

wp meilisearch reindex --network

Check index status:

wp meilisearch status --network

Performance Issues

  • Ensure Meilisearch has adequate resources
  • Consider increasing batch size in class-indexer.php
  • Use a dedicated Meilisearch instance for production

License

GPLv2 or later

Contributing

Contributions are welcome! Please follow WordPress coding standards and include tests for new features.

Credits

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages