From 2290829dd007a738ff42011ab257de120cf463f2 Mon Sep 17 00:00:00 2001 From: Benny Date: Tue, 2 Jan 2024 18:43:13 +0100 Subject: [PATCH] fix zinc search #103 --- Docker.md | 10 +++++----- README.md | 7 +++++-- docker-compose.yml | 3 --- searchgram/bot.py | 1 + searchgram/config.py | 5 +++-- searchgram/zinc.py | 2 +- 6 files changed, 15 insertions(+), 13 deletions(-) diff --git a/Docker.md b/Docker.md index febf10d..21dcdac 100644 --- a/Docker.md +++ b/Docker.md @@ -12,12 +12,14 @@ wget https://raw.githubusercontent.com/tgbot-collection/SearchGram/master/docker In this `docker-compose.yml`, you need to decide which search engine to use, available options are: -* MeiliSearch +* MeiliSearch: default option * MongoDB * ZincSearch Comment out the search engine you don't want to use. +> if you're unable to run zinc, please change data folder permission `chown -R 10001:10001 ./sg_data/zinc` + # 2. (Optional) Prepare the Encrypted Data Volume For added security, it's recommended to use an encrypted data volume. @@ -99,7 +101,7 @@ umount /dev/mapper/sg_data cryptsetup luksClose sg_data ```` -# 3. Obtain APP_ID, APP_HASH, and Bot Token +# 3. get APP_ID, APP_HASH, and Bot Token To get started with SearchGram, you'll need to @@ -111,8 +113,6 @@ To get started with SearchGram, you'll need to All the environment variables are stored in `env/gram.env` and you can see the comments in `config.py` for more details. -Make sure they're correct before you start the container. You can cross-check them with `docker-compose.yml` - ```shell An example of `env/gram.env` is shown below: @@ -123,7 +123,7 @@ TOKEN=token APP_ID=id APP_HASH=hash OWNER_ID=your user_id -MEILI_MASTER_KEY=token +ENGINE=meili # meili, mongo, zinc ``` # 5. Login to client diff --git a/README.md b/README.md index e7d7c68..72fb506 100644 --- a/README.md +++ b/README.md @@ -82,9 +82,12 @@ see [Max indexing memory](https://www.meilisearch.com/docs/learn/configuration/i # Installation **Note: Because chat history should be kept private, we do not offer any public bots.** -**To learn how to use SearchGram in Docker, please refer to the [Docker.md](Docker.md)** -Please follow the steps below to install SearchGram: +Please follow the steps below to install SearchGram on your own server. + +This guide will show you how to install SearchGram with our default search engine, MeiliSearch. + +**To learn how to use SearchGram in Docker with different search engine, please refer to the [Docker.md](Docker.md)** ## 1. Preparation diff --git a/docker-compose.yml b/docker-compose.yml index 8ad88fc..52f0596 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -43,9 +43,6 @@ services: image: public.ecr.aws/zinclabs/zincsearch:latest environment: ZINC_DATA_PATH: "/data" - # GIN_MODE: "release" - ZINC_FIRST_ADMIN_USER: "root" - ZINC_FIRST_ADMIN_PASSWORD: "root" env_file: - env/gram.env volumes: diff --git a/searchgram/bot.py b/searchgram/bot.py index 1f8ab7f..283c583 100644 --- a/searchgram/bot.py +++ b/searchgram/bot.py @@ -146,6 +146,7 @@ def parse_and_search(text, page=1) -> Tuple[str, InlineKeyboardMarkup | None]: user = args.user keyword = args.keyword mode = args.mode + logging.info("Search keyword: %s, type: %s, user: %s, page: %s, mode: %s", keyword, _type, user, page, mode) results = tgdb.search(keyword, _type, user, page, mode) text = parse_search_results(results) if not text: diff --git a/searchgram/config.py b/searchgram/config.py index 127b026..2a91ed7 100644 --- a/searchgram/config.py +++ b/searchgram/config.py @@ -25,9 +25,10 @@ # available values: meili, mongo, zinc, default: meili ENGINE = os.getenv("ENGINE", "meili").lower() +# If you want to use Zinc as search engine, you need to set username and password ZINC_HOST = os.getenv("ZINC_HOST", "http://zinc:4080") -ZINC_USER = os.getenv("ZINC_USER", "root") -ZINC_PASS = os.getenv("ZINC_PASS", "root") +ZINC_USER = os.getenv("ZINC_FIRST_ADMIN_USER", "root") +ZINC_PASS = os.getenv("ZINC_FIRST_ADMIN_PASSWORD", "root") #################################### # Your own user id, for example: 260260121 diff --git a/searchgram/zinc.py b/searchgram/zinc.py index 1b98530..f8b3c7b 100644 --- a/searchgram/zinc.py +++ b/searchgram/zinc.py @@ -73,7 +73,7 @@ def search(self, keyword, _type=None, user=None, page=1, mode=None) -> dict: total_hits = results.hits.total.value total_pages = math.ceil(total_hits / 10) return { - "hits": results.hits.hits, + "hits": [i.source for i in results.hits.hits], "query": keyword, "hitsPerPage": 10, "page": page,