Skip to content

Commit 3bc4199

Browse files
authored
Implement search using Xapian (#1016)
2 parents dec36b3 + 66a55d9 commit 3bc4199

File tree

21 files changed

+705
-471
lines changed

21 files changed

+705
-471
lines changed

.env.template

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
HTV_BACKEND_PUBLIC_URL=https://localhost/api
22
HTV_FRONTEND_PUBLIC_URL=https://localhost
33
CADDY_SITE_ADDRESS=localhost
4-
MEILI_MASTER_KEY=

.github/workflows/backend.yml

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,28 @@ jobs:
1313
run:
1414
working-directory: ./backend
1515

16-
services:
17-
meilisearch:
18-
image: "getmeili/meilisearch:v1.3.1"
19-
ports: ["7700:7700"]
20-
env:
21-
MEILI_MASTER_KEY: "1234567890"
16+
env:
17+
# Make Python system packages (such as Xapian) accessible
18+
PYTHONPATH: /usr/lib/python3/dist-packages
2219

2320
steps:
2421
- name: Checkout repo
2522
uses: actions/checkout@v4
2623

24+
- name: Install Xapian
25+
run: sudo apt-get -y -q install python3-xapian
26+
27+
# Stopwords are included in the Alpine Xapian package, but for some reason they are not included
28+
# in the Ubuntu package. This downloads them from the same source as the Alpine package:
29+
# https://gitlab.alpinelinux.org/alpine/aports/-/blob/3.19-stable/community/xapian-core/APKBUILD#L12
30+
- name: Download stopwords
31+
working-directory: ${{ runner.temp }}
32+
run: |
33+
curl -o xapian-core-1.4.26.tar.xz https://oligarchy.co.uk/xapian/1.4.26/xapian-core-1.4.26.tar.xz
34+
tar -xf xapian-core-1.4.26.tar.xz
35+
mkdir -p /usr/share/xapian-core/stopwords
36+
cp xapian-core-1.4.26/languages/stopwords/english.list /usr/share/xapian-core/stopwords/english.list
37+
2738
- name: Install poetry
2839
run: pipx install "poetry<2.0"
2940

@@ -51,5 +62,4 @@ jobs:
5162
env:
5263
HTV_BACKEND_DATABASE_URI: "sqlite:///${{ github.workspace }}/storage/database/database.sqlite3"
5364
HTV_BACKEND_USERS_DATABASE_URI: "sqlite:///${{ github.workspace }}/storage/database/users.sqlite3"
54-
MEILI_MASTER_KEY: "1234567890"
55-
MEILI_URL: "http://localhost:7700"
65+
HTV_SEARCH_INDEX_DIR: "${{ github.workspace }}/storage/index"

.github/workflows/scheduled.yml

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,28 @@ jobs:
1313
run:
1414
working-directory: ./backend
1515

16-
services:
17-
meilisearch:
18-
image: "getmeili/meilisearch:v1.3.1"
19-
ports: ["7700:7700"]
20-
env:
21-
MEILI_MASTER_KEY: "1234567890"
16+
env:
17+
# Make Python system packages (such as Xapian) accessible
18+
PYTHONPATH: /usr/lib/python3/dist-packages
2219

2320
steps:
2421
- name: Checkout repo
2522
uses: actions/checkout@v4
2623

24+
- name: Install Xapian
25+
run: sudo apt-get -y -q install python3-xapian
26+
27+
# Stopwords are included in the Alpine Xapian package, but for some reason they are not included
28+
# in the Ubuntu package. This downloads them from the same source as the Alpine package:
29+
# https://gitlab.alpinelinux.org/alpine/aports/-/blob/3.19-stable/community/xapian-core/APKBUILD#L12
30+
- name: Download stopwords
31+
working-directory: ${{ runner.temp }}
32+
run: |
33+
curl -o xapian-core-1.4.26.tar.xz https://oligarchy.co.uk/xapian/1.4.26/xapian-core-1.4.26.tar.xz
34+
tar -xf xapian-core-1.4.26.tar.xz
35+
mkdir -p /usr/share/xapian-core/stopwords
36+
cp xapian-core-1.4.26/languages/stopwords/english.list /usr/share/xapian-core/stopwords/english.list
37+
2738
- name: Install poetry
2839
run: pipx install "poetry<2.0"
2940

@@ -43,5 +54,4 @@ jobs:
4354
HTV_TEST_MOCK_REQUESTS: "false"
4455
HTV_BACKEND_DATABASE_URI: "sqlite:///${{ github.workspace }}/storage/database/database.sqlite3"
4556
HTV_BACKEND_USERS_DATABASE_URI: "sqlite:///${{ github.workspace }}/storage/database/users.sqlite3"
46-
MEILI_MASTER_KEY: "1234567890"
47-
MEILI_URL: "http://localhost:7700"
57+
HTV_SEARCH_INDEX_DIR: "${{ github.workspace }}/storage/index"

backend/Dockerfile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM python:3.12-alpine3.19
1+
FROM python:3.12-alpine3.21
22

33
RUN apk --update add \
44
build-base \
@@ -13,7 +13,9 @@ RUN apk --update add \
1313
make \
1414
cargo \
1515
sqlite \
16-
tmux
16+
tmux \
17+
xapian-core \
18+
xapian-bindings-python3
1719

1820
RUN pip install "poetry<2.0"
1921

@@ -35,4 +37,7 @@ ENV TZ=UTC
3537
ENV ALEMBIC_CONFIG=./howtheyvote/alembic/alembic.ini
3638
ENV PATH="/howtheyvote/backend/.venv/bin:$PATH"
3739

40+
# Make Python system packages (such as Xapian) accessible
41+
ENV PYTHONPATH=/usr/lib/python3.12/site-packages
42+
3843
CMD gunicorn -b [::]:5000 --workers=5 --forwarded-allow-ips=* howtheyvote.wsgi:app

0 commit comments

Comments
 (0)