Skip to content

Implicit FULLTEXT indexes from e_search#5566

Open
Deltik wants to merge 1 commit intoe107inc:masterfrom
Deltik:fix/5209
Open

Implicit FULLTEXT indexes from e_search#5566
Deltik wants to merge 1 commit intoe107inc:masterfrom
Deltik:fix/5209

Conversation

@Deltik
Copy link
Member

@Deltik Deltik commented Jan 25, 2026

Motivation and Context

After the migration from MyISAM to InnoDB (#4501), the search functionality broke with the error:

Can't find FULLTEXT index matching the column list

This is because InnoDB requires explicit FULLTEXT indexes while MyISAM supported FULLTEXT search implicitly. Users reported that searching for content in news, downloads, forums, and other areas returned no results (#5209).

The workaround was to manually run ALTER TABLE ... ADD FULLTEXT for each search field, but this is error-prone and requires database expertise.

Fixes: #5209

Description

This PR introduces automatic detection and creation of FULLTEXT indexes based on the search_fields configuration in e_search addons.

New Components:

  • e_search_fulltext_indexer_class.php: Parses e_search addon configs to derive required FULLTEXT indexes. Handles complex table aliases and JOIN clauses to map search fields to their actual tables.

Changes to Existing Components:

  • db_verify_class.php:

    • Integrates the FULLTEXT indexer into the comparison flow
    • init(true) now clears all dependent caches (MySQL table list, core preferences, and db_verify's own cache) for programmatic use
    • Missing FULLTEXT indexes are detected and can be fixed via the existing db_verify repair mechanism
  • plugin_class.php:

    • New createSearchIndexes() method called during plugin installation
    • Automatically creates FULLTEXT indexes for plugins with e_search addons immediately after table creation
  • install.php:

    • Creates FULLTEXT indexes for core e_search addons during fresh installation

How It Works:

  1. When db_verify compares tables, it calls getSearchFieldIndexes()
  2. The indexer loads all e_search addon configs via getAddonConfig()
  3. For each config, it parses the table clause to extract table/alias mappings (handling JOINs like news AS n LEFT JOIN #user AS u ON...)
  4. It maps search_fields (e.g., n.news_title) to actual table.column
  5. Generates FULLTEXT index definitions with naming convention ft_{table}_{column}
  6. These derived indexes are merged with file-defined indexes for comparison

For Existing Sites:
Users can go to Admin → Database → Verify SQL, select the affected plugins, and click "Fix Selected Items" to create the missing FULLTEXT indexes.

How Has This Been Tested?

  • Unit tests: 19 tests for the FULLTEXT indexer covering:

    • Table alias parsing (simple tables, AS aliases, implicit aliases, complex JOINs)
    • Search field mapping to table.column pairs
    • Index definition generation
    • Full workflow integration
  • Integration test: Verifies that installing the forum plugin (which has e_search) automatically creates FULLTEXT indexes with no pending migrations afterward

  • Manual testing:

    • Fresh installation creates FULLTEXT indexes for core search
    • Plugin installation via web interface creates indexes
    • db_verify correctly detects and repairs missing indexes
    • Search functionality works after index creation

Types of Changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Performance enhancement (non-breaking change which improves efficiency)
  • Code cleanup (non-breaking change which makes code smaller or more readable)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation (a change to man pages or other documentation)

Checklist

After the migration from MyISAM to InnoDB (issue e107inc#4501), the search
functionality broke because InnoDB requires explicit FULLTEXT indexes,
while MyISAM supported them implicitly.

This commit introduces automatic detection and creation of FULLTEXT
indexes based on the `search_fields` configuration in e_search addons:

## New Components

- `e_search_fulltext_indexer_class.php`: Parses e_search addon configs
  to derive required FULLTEXT indexes. Handles complex table aliases
  and JOIN clauses to map search fields to their actual tables.

## Changes to Existing Components

- `db_verify_class.php`:
  - Integrates the FULLTEXT indexer into the comparison flow
  - `init(true)` now clears all dependent caches (MySQL table list,
    core preferences, and db_verify's own cache) for programmatic use
  - Missing FULLTEXT indexes are detected and can be fixed via the
    existing db_verify repair mechanism

- `plugin_class.php`:
  - New `createSearchIndexes()` method called during plugin installation
  - Automatically creates FULLTEXT indexes for plugins with e_search
    addons immediately after table creation

- `install.php`:
  - Creates FULLTEXT indexes for core e_search addons during fresh
    installation

## How It Works

1. When db_verify compares tables, it calls `getSearchFieldIndexes()`
2. The indexer loads all e_search addon configs via `getAddonConfig()`
3. For each config, it parses the `table` clause to extract table/alias
   mappings (handling JOINs like `news AS n LEFT JOIN #user AS u ON...`)
4. It maps `search_fields` (e.g., `n.news_title`) to actual table.column
5. Generates FULLTEXT index definitions with naming convention
   `ft_{table}_{column}`
6. These derived indexes are merged with file-defined indexes for
   comparison

## Testing

- Unit tests for the FULLTEXT indexer (19 tests)
- Integration test verifying plugin installation creates indexes
- Manual testing with forum plugin installation via web interface

Fixes: e107inc#5209
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: The search menu and page doesn't found any content on the page

1 participant