Skip to content

Commit 63f7b18

Browse files
committed
chg: [v6.7] update delete old indexes + doc + add reindexing tool
1 parent 347e489 commit 63f7b18

3 files changed

Lines changed: 118 additions & 2 deletions

File tree

HOWTO.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,24 @@ meilisearch = True
9898
meilisearch_url = http://<meilisearch_url> # URL where Meilisearch is running (e.g., `http://127.0.0.1:7700`)
9999
meilisearch_key = <meilisearch_db_password> # Meilisearch master key or API key
100100
```
101+
102+
### Reindex after upgrading to v6.7
103+
104+
> ⚠️ Meilisearch indexes created with AIL versions **before v6.7** are **automatically removed during the update**.
105+
> Search indexing was refactored, so the indexes must be rebuilt using the new schema.
106+
107+
Use `tools/reindex_meilisearch.py` to rebuild the indexes:
108+
109+
```bash
110+
# Reindex everything
111+
python3 tools/reindex_meilisearch.py --type all
112+
113+
# Reindex only one dataset
114+
python3 tools/reindex_meilisearch.py --type messages
115+
```
116+
117+
If you want to **reset and recreate the indexes** before reindexing:
118+
119+
```bash
120+
python3 tools/reindex_meilisearch.py --reset --type all
121+
```

bin/lib/search_engine.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ def load_indexes_names():
6262

6363

6464
INDEX_NAMES = load_indexes_names()
65-
66-
6765
def get_indexes_names():
6866
return INDEX_NAMES
6967

@@ -399,6 +397,20 @@ def index_file_names():
399397
if document:
400398
Engine.update(index, document)
401399

400+
401+
INDEXING_FUNCTIONS = {
402+
'all': index_all,
403+
'crawled': index_crawled,
404+
'chats': index_chats,
405+
'messages': index_messages,
406+
'user_accounts': index_user_accounts,
407+
'images_descriptions': index_images_descriptions,
408+
'screenshots_descriptions': index_screenshots_descriptions,
409+
'domains_descriptions': index_domains_descriptions,
410+
'titles': index_titles,
411+
'file_names': index_file_names,
412+
}
413+
402414
## --INDEXER-- ##
403415

404416

tools/reindex_meilisearch.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
"""
4+
Reindex Meilisearch data from AIL.
5+
6+
By default, this script indexes one or more datasets without deleting existing
7+
indexes. If `--reset` is provided, it first deletes and recreates all indexes.
8+
In both cases, index creation/configuration is ensured before indexing starts.
9+
"""
10+
11+
import argparse
12+
import os
13+
import sys
14+
15+
sys.path.append(os.environ['AIL_BIN'])
16+
##################################
17+
# Import Project packages
18+
##################################
19+
from lib import search_engine
20+
21+
def ensure_indexes_ready(reset=False):
22+
"""Ensure indexes exist and are configured before indexing."""
23+
engine = search_engine.Engine
24+
25+
if reset:
26+
engine._delete_all()
27+
engine.create_indexes()
28+
else:
29+
existing = set(engine.get_indexes())
30+
required = set(search_engine.get_indexes_names())
31+
for index_name in sorted(required - existing):
32+
engine._create_index(index_name)
33+
engine.setup_indexes_searchable_filterable_sortable()
34+
35+
36+
def run_indexing(index_type):
37+
indexing_fct = search_engine.INDEXING_FUNCTIONS[index_type]
38+
indexing_fct()
39+
40+
41+
def parse_args():
42+
parser = argparse.ArgumentParser(
43+
description='Optionally reset Meilisearch indexes and index one dataset or everything.'
44+
)
45+
parser.add_argument(
46+
'-t',
47+
'--type',
48+
dest='index_type',
49+
default='all',
50+
choices=sorted(search_engine.INDEXING_FUNCTIONS.keys()),
51+
help='Dataset type to index (default: all)',
52+
)
53+
parser.add_argument(
54+
'--reset',
55+
action='store_true',
56+
help='Delete and recreate all indexes before indexing',
57+
)
58+
return parser.parse_args()
59+
60+
61+
def main():
62+
args = parse_args()
63+
if args.reset:
64+
print('Resetting indexes and preparing configuration...')
65+
else:
66+
print('Preparing indexes and configuration (no reset)...')
67+
68+
if not search_engine.is_meilisearch_enabled():
69+
raise RuntimeError('Meilisearch is disabled in configuration')
70+
71+
if not search_engine.Engine.is_up():
72+
raise RuntimeError('Meilisearch is not reachable')
73+
74+
ensure_indexes_ready(reset=args.reset)
75+
print('Indexes are ready.')
76+
77+
print(f'Start indexing: {args.index_type}')
78+
run_indexing(args.index_type)
79+
print('Indexing finished.')
80+
81+
82+
if __name__ == '__main__':
83+
main()

0 commit comments

Comments
 (0)