Skip to content
  1. Extras
  2. mSearch
  3. Interface
  4. Indexing

Indexing ​

Tab for creating and managing the search index.

Purpose ​

Building the index is resource-heavy, so it runs in batches via Ajax. On this tab you can create an index, watch progress, and clear it if needed.

Interface ​

Statistics ​

MetricDescription
Total resourcesTotal resources in the system
IndexedResources in the index
Words in indexTotal word count

Controls ​

ControlDescription
Batch sizeResources per request (1–500)
Create indexStart indexing
Clear indexRemove all index entries

Progress bar ​

Shows indexing progress in percent.

How indexing works ​

  1. Data extraction — resource fields are loaded from DB per mse_index_fields
  2. Splitting — text split by regex from mse_index_split_words
  3. Filtering — words shorter than mse_index_min_word_length are dropped
  4. Morphology — base forms generated via phpMorphy for each word
  5. Save — words and weights written to index table

System settings ​

SettingDefaultDescription
mse_index_fieldspagetitle:3,...Indexed fields with weights
mse_index_min_word_length3Minimum word length
mse_index_split_words#\s|[,.:;!?...]#uRegex for splitting
mse_use_schedulerfalseUse Scheduler for deferred indexing

Field weights ​

mse_index_fields sets weight per field. Format:

field1:weight1,field2:weight2,...

Higher weight ranks matches in that field higher.

Example configs ​

Standard:

pagetitle:3,longtitle:2,description:2,introtext:2,content:1

With TV:

pagetitle:3,content:1,tv_subtitle:2,tv_keywords:3

MiniShop3 products:

pagetitle:3,description:2,content:1,article:5,vendor_name:2

When to reindex ​

The index updates automatically on resource save. Full reindex is needed:

  • After first install
  • After changing indexing settings
  • After bulk content import

Recommendations ​

Batch sizeUse case
50Default for most servers
10–20Weak servers or large documents
100+Strong servers and fast hosting

Optimal value

If you get timeout errors during indexing, reduce batch size.

Scheduler integration ​

mSearch supports deferred indexing via Scheduler, so indexing runs in the background and does not slow down saves.

Enabling ​

  1. Install Scheduler
  2. Enable system setting mse_use_scheduler

Behavior ​

On resource save:

Without SchedulerWith Scheduler
Indexing runs immediatelyTask added to queue
Slows saveSave is fast
Blocks interfaceIndexing in background

Task mse_index_resource ​

The task is registered automatically when mSearch is installed (if Scheduler is already installed).

Parameters:

ParameterDescription
resource_idResource ID to index
(none)Full reindex of all resources

Manual full reindex ​

  1. Go to Extras → Scheduler
  2. Find task mse_index_resource (namespace: msearch)
  3. Run the task with no parameters

Regular reindex

Use Scheduler to run reindex on a schedule, e.g. weekly.

Logging ​

The task logs progress to MODX log:

[mSearch indexResource task] Starting full reindex...
[mSearch indexResource task] Progress: 100/500 (indexed: 100)
...
[mSearch indexResource task] Full reindex completed. Total indexed: 500

Fallback without Scheduler ​

If Scheduler is not installed or the task is missing, mSearch falls back to direct indexing.

Events ​

EventDescription
mseOnBeforeIndexBefore indexing a resource. Can add fields.
mseOnGetWorkFieldsChange list of fields to index
mseOnAfterIndexAfter indexing a resource

Example: custom words ​

php
<?php
switch ($modx->event->name) {
    case 'mseOnBeforeIndex':
        $msearch->fields['custom_field'] = 1;
        $resource->set('custom_field', 'Extra keywords');
        break;
}

Example: MiniShop3 product options ​

php
<?php
switch ($modx->event->name) {
    case 'mseOnBeforeIndex':
        if ($resource->get('class_key') !== 'msProduct') {
            return;
        }

        $options = $modx->getCollection('msProductOption', [
            'product_id' => $resource->get('id'),
        ]);

        foreach ($options as $option) {
            $key = 'option_' . $option->get('key');
            $msearch->fields[$key] = 1;
            $resource->set($key, $option->get('value'));
        }
        break;
}