diff --git a/contrib/meilisearch/.gitignore b/contrib/meilisearch/.gitignore new file mode 100644 index 0000000..9ee05fe --- /dev/null +++ b/contrib/meilisearch/.gitignore @@ -0,0 +1,2 @@ +venv +data.ms diff --git a/contrib/meilisearch/Makefile b/contrib/meilisearch/Makefile new file mode 100644 index 0000000..2ccd796 --- /dev/null +++ b/contrib/meilisearch/Makefile @@ -0,0 +1,23 @@ + +up: + docker-compose up -d + docker ps + +index: venv + ./venv/bin/python index.py + +venv: + python3 -m venv venv + ./venv/bin/pip install -U pip wheel + ./venv/bin/pip install -r requirements.txt + +down: + docker-compose down + +purge: + make down + rm -rf data.ms + make up + +pull: + docker-compose pull diff --git a/contrib/meilisearch/README.md b/contrib/meilisearch/README.md new file mode 100644 index 0000000..6ac6e66 --- /dev/null +++ b/contrib/meilisearch/README.md @@ -0,0 +1,19 @@ +# Meilisearch + +Indexation naïve et systématique du contenu. + +Fonctionne avec un [meilisearch](https://www.meilisearch.com/) local, ou dans un conteneur, tant que ça écoute http://localhost:7700 + +## Demo + +Lance meilisearch dans un conteneur + + make up + +Index le site (avec du code en python) + + make index + +Mailisearch propose une UI web pour tester la recherche : [http://localhost:7700](http://localhost:7700) + +Il est possible de copier l'index, le dossier `data.ms` sur un serveur, pour effectuer des recherches (en lecture seule). diff --git a/contrib/meilisearch/docker-compose.yml b/contrib/meilisearch/docker-compose.yml new file mode 100644 index 0000000..6b88b9b --- /dev/null +++ b/contrib/meilisearch/docker-compose.yml @@ -0,0 +1,11 @@ +--- + +version: "3" + +services: + meilisearch: + image: getmeili/meilisearch:latest + volumes: + - ./data.ms:/data.ms + ports: + - 7700:7700 diff --git a/contrib/meilisearch/index.py b/contrib/meilisearch/index.py new file mode 100755 index 0000000..83c6cba --- /dev/null +++ b/contrib/meilisearch/index.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python3 + +from pathlib import Path +from io import StringIO + +import yaml +from markdown import markdown +from meilisearch import Client + + +def pages(): + "return all pages" + for readme in Path('../..').glob('**/README.md'): + if readme == Path("README.md"): # it's the home + continue + with open(readme, 'r') as file: + head = StringIO() + body = StringIO() + state = None + for line in file: + if state is None and line == "---\n": + state = "head" + continue + if state == "head": + if line == "---\n": + state = "body" + continue + head.write(line) + else: + body.write(line) + if head.tell() == 0: # empty + continue + head.seek(0) + head = yaml.safe_load(head) + body.seek(0) + txt = markdown(body.read()) + # removing ../../, README.md and replace / with _ + yield str(readme)[11:-10].replace("/", "_"), head['title'], txt + + +if __name__ == "__main__": + client = Client('http://127.0.0.1:7700') + try: + idx = client.get_index('pages') + except Exception: + client.create_index('pages', dict(primaryKey='path')) + print("the index is created") + else: + print("the index is already here") + + for path, title, body in pages(): + client.index('pages').add_documents([{ + 'path': path, + 'title': title, + 'body': body, + }]) + print(title, path) diff --git a/contrib/meilisearch/requirements.txt b/contrib/meilisearch/requirements.txt new file mode 100644 index 0000000..5fac84f --- /dev/null +++ b/contrib/meilisearch/requirements.txt @@ -0,0 +1,3 @@ +pyyaml +meilisearch +markdown