From 06cd958095cf852b1893c3486480465c0545f6e5 Mon Sep 17 00:00:00 2001
From: Bryan Brancotte <bryan.brancotte@pasteur.fr>
Date: Mon, 12 Dec 2022 14:33:43 +0100
Subject: [PATCH] prefill when empty

---
 .../commands/makeautocompleteindex.py           | 17 +++++++++++++++++
 setup.cfg                                       |  2 +-
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/autocomplete_multi_models/management/commands/makeautocompleteindex.py b/autocomplete_multi_models/management/commands/makeautocompleteindex.py
index fd38926..b10880a 100644
--- a/autocomplete_multi_models/management/commands/makeautocompleteindex.py
+++ b/autocomplete_multi_models/management/commands/makeautocompleteindex.py
@@ -18,4 +18,21 @@ class Command(BaseCommand):
         business_process.rebuild_index()
         te = time.time()
         print(f"Index rebuild in {int((te - ts) * 100) / 100}s, it contains {models.IndexedWord.objects.count()} words")
+        if not models.IndexedWord.objects.exists():
+            print("DB is empty, prefilling it with some words")
+            for s in [
+                "Coming soon",
+                "coming soon",
+                "coming",
+                "soon",
+                "Work in progress",
+                "work",
+                "progress",
+                "HUB",
+                "Bioinformatics and Biostatistics",
+                "Bioinformatics and Biostatistics HUB",
+                "bioinformatics",
+                "biostatistics",
+            ]:
+                models.IndexedWord.objects.get_or_create(word=s, occurrence=1)
         business_process.set_setting_in_storage(utils.REBUILD_NEEDED, False)
diff --git a/setup.cfg b/setup.cfg
index 8090a51..2849107 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,6 +1,6 @@
 [metadata]
 name = autocomplete-multi-models
-version = 0.4.1
+version = 0.4.3
 description = An app that index fields across multiple models, and expose an api to query for word similar to the query.
 long_description = file: README.md
 author = Bryan Brancotte
-- 
GitLab