Skip to content

Commit

Permalink
fix zinc search #103
Browse files Browse the repository at this point in the history
  • Loading branch information
BennyThink committed Jan 2, 2024
1 parent d34f89c commit 2290829
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 13 deletions.
10 changes: 5 additions & 5 deletions Docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions searchgram/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions searchgram/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion searchgram/zinc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 2290829

Please sign in to comment.