Skip to content

Commit

Permalink
add: meilisearch
Browse files Browse the repository at this point in the history
  • Loading branch information
MagicTheDev committed Apr 3, 2024
1 parent ce5bd80 commit 4d5485e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
18 changes: 9 additions & 9 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions gamewide/search/track.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from utility.classes import MongoDatabase
from meilisearch_python_sdk import AsyncClient
from utility.config import Config
from loguru import logger

import asyncio


Expand All @@ -13,7 +15,7 @@ async def main():
all_tags = [x["_id"] for x in (await db_client.global_clans.aggregate(pipeline).to_list(length=None))]
bot_clan_tags = await db_client.clans_db.distinct("tag")
all_tags = list(set(all_tags + bot_clan_tags))
print(f"{len(all_tags)} tags")
logger.info(f"{len(all_tags)} tags")
size_break = 100_000
all_tags = [all_tags[i:i + size_break] for i in range(0, len(all_tags), size_break)]

Expand All @@ -33,9 +35,9 @@ async def main():
{"$unset": ["_id"]}
]
docs_to_insert = await db_client.global_clans.aggregate(pipeline=pipeline).to_list(length=None)
print(len(docs_to_insert), "docs")
logger.info(f"{len(docs_to_insert)} docs")

# An index is where the documents are stored.
index = client.index('players')
await index.add_documents_in_batches(documents=docs_to_insert, batch_size=100_000, primary_key="id", compress=True)
await index.add_documents_in_batches(documents=docs_to_insert, batch_size=1_000, primary_key="id", compress=True)
await asyncio.sleep(15)

0 comments on commit 4d5485e

Please sign in to comment.