Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Postgres Full Text search. #1

Merged
merged 55 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
5c37fde
Fix docstring.
cyrillkuettel Jun 25, 2024
b8cf6ca
Use postgres as default for the database
cyrillkuettel Jun 25, 2024
78642f3
wip
cyrillkuettel Jun 26, 2024
b11eeed
update
cyrillkuettel Jul 1, 2024
21d7c3b
update
cyrillkuettel Jul 2, 2024
f52f3f6
works sort of
cyrillkuettel Jul 2, 2024
f459eed
Use all the fields in the headline
cyrillkuettel Jul 2, 2024
3a13bb1
update
cyrillkuettel Jul 2, 2024
d8c80bc
Increase robustness for unsafe getattr call
cyrillkuettel Jul 2, 2024
13cc7ae
Using the precomputed ts_query instead of recomputing it each time.
cyrillkuettel Jul 2, 2024
da82be3
Display comments
cyrillkuettel Jul 2, 2024
6b76406
fix flake8
cyrillkuettel Jul 2, 2024
efa9ba9
Fixes a couple of mypy issues
cyrillkuettel Jul 2, 2024
4e39dd2
Attempts to resolve more mypy errors.
cyrillkuettel Jul 2, 2024
ff3b42e
clean up
cyrillkuettel Jul 2, 2024
dcc90c7
Clean up, add some docstring.
cyrillkuettel Jul 2, 2024
61bb501
Add SearchableFile
cyrillkuettel Jul 2, 2024
df1507c
tests: migrate away from SQlite In-Memory db.
cyrillkuettel Jul 2, 2024
f9a64e8
Cosmetics
cyrillkuettel Jul 3, 2024
926ac25
Update readme with instructions for setup
cyrillkuettel Jul 3, 2024
d692261
finish migration, fix mypy, add SearchableFile.
cyrillkuettel Jul 3, 2024
8edf635
Merge remote-tracking branch 'origin/develop' into postgres-full-text
cyrillkuettel Jul 3, 2024
61bc680
Use event listener to update the searchable text of files.
cyrillkuettel Jul 3, 2024
f091fd7
Added a new headline expression for the searchable_text_de_CH column …
cyrillkuettel Jul 3, 2024
c1c41df
try to solve query
cyrillkuettel Jul 3, 2024
084813e
fulltext works
cyrillkuettel Jul 4, 2024
66f479d
Apply suggestions from code review
cyrillkuettel Jul 4, 2024
4739ae3
Disble browser-native autocomplete
cyrillkuettel Jul 4, 2024
b13f041
Remove unnecessary cast
cyrillkuettel Jul 4, 2024
14993d5
Abstract File class to make associable not break
cyrillkuettel Jul 4, 2024
8d52b58
Don't Inherit from Associable in `File` but in models which derive
cyrillkuettel Jul 4, 2024
c632fe0
Type mayhem
cyrillkuettel Jul 4, 2024
057b27f
Add weighted search results with ts_rank.
cyrillkuettel Jul 6, 2024
7f18025
update
cyrillkuettel Jul 8, 2024
9b758de
Allow to copy agenda items (SEA-1355).
cyrillkuettel Jul 8, 2024
4f94bac
start adding filter html again
cyrillkuettel Jul 9, 2024
005f6c5
Styling and fix sidebar with.
cyrillkuettel Jul 9, 2024
d4d38d6
Add filter (wip)
cyrillkuettel Jul 9, 2024
0c91907
no runtime error
cyrillkuettel Jul 9, 2024
8bd8adf
fixed almost all type errors.
cyrillkuettel Jul 9, 2024
2fa84f7
Ignore call-overload for funky sqlalchemy stuff.
cyrillkuettel Jul 9, 2024
5da2be1
fixe all flake8.
cyrillkuettel Jul 9, 2024
eb3be32
Attempts to fix myp.
cyrillkuettel Jul 9, 2024
d16e248
install poppler for CI
cyrillkuettel Jul 9, 2024
2734f24
install poppler
cyrillkuettel Jul 9, 2024
112042e
Fixes almost all mypy execpt one, compile requirements
cyrillkuettel Jul 9, 2024
7222c9a
Merge remote-tracking branch 'origin/full-text-enhancements' into pos…
cyrillkuettel Jul 9, 2024
46b7685
update
cyrillkuettel Jul 9, 2024
57633f4
Merge branch 'develop' into postgres-full-text
cyrillkuettel Jul 10, 2024
ab15cce
Fixes several things and clean up after merge.
cyrillkuettel Jul 10, 2024
a7fae57
update
cyrillkuettel Jul 10, 2024
2ccb547
Clean up
cyrillkuettel Jul 10, 2024
2527a40
Get rid of structure [skip ci]
cyrillkuettel Jul 10, 2024
64c1707
fix typo [skip ci]
cyrillkuettel Jul 10, 2024
14cf32a
Fix bug with seek(0)
cyrillkuettel Jul 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ jobs:
libpq-dev \
make \
postgresql \
libpoppler-cpp-dev \
pkg-config \
python3-dev \
--fix-missing

- name: Checkout repo
Expand Down Expand Up @@ -75,6 +78,9 @@ jobs:
libpq-dev \
make \
postgresql \
libpoppler-cpp-dev \
pkg-config \
python3-dev \
--fix-missing

export LC_ALL="C.UTF-8"
Expand Down
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@ Getting Started
---------------

```
sudo apt install postgresql libpq-dev python3-dev build-essential weasyprint
```

Create the PostgreSQL database:
```
sudo -u postgres bash -c "psql <<EOF
CREATE USER dev WITH PASSWORD 'postgres' LOGIN NOINHERIT;
ALTER USER dev WITH SUPERUSER;
CREATE DATABASE privatim;
GRANT ALL PRIVILEGES ON DATABASE privatim TO dev;
EOF"


git clone [email protected]:seantis/privatim.git
cd privatim
python3 -m venv venv
Expand Down Expand Up @@ -35,7 +48,7 @@ make run
## Run the project's tests

```
pytest -n 3
pytest -n auto
```


Expand Down
4 changes: 2 additions & 2 deletions development.ini.example
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ pyramid.available_languages =
# pyramid.includes =
# pyramid_debugtoolbar

sqlalchemy.url = sqlite:///%(here)s/privatim.sqlite
# sqlalchemy.url = postgresql://dev:postgres@localhost:5432/privatim
# sqlalchemy.url = sqlite:///%(here)s/privatim.sqlite
sqlalchemy.url = postgresql://dev:postgres@localhost:5432/privatim

session.type = file
session.data_dir = %(here)s/data/sessions/data
Expand Down
61 changes: 47 additions & 14 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This file was autogenerated by uv via the following command:
# uv pip compile setup.cfg - -o requirements.txt --no-emit-package setuptools
-e .
alembic==1.13.1
alembic==1.13.2
# via
# privatim (setup.cfg)
# privatim
Expand All @@ -21,10 +21,14 @@ bcrypt==4.1.3
# privatim
beaker==1.13.0
# via pyramid-beaker
certifi==2024.6.2
brotli==1.1.0
# via fonttools
certifi==2024.7.4
# via
# requests
# sentry-sdk
cffi==1.16.0
# via weasyprint
chameleon==4.5.4
# via pyramid-chameleon
charset-normalizer==3.3.2
Expand All @@ -33,9 +37,11 @@ click==8.1.7
# via
# privatim (setup.cfg)
# privatim
cssselect2==0.7.0
# via weasyprint
dnspython==2.6.1
# via email-validator
email-validator==2.1.2
email-validator==2.2.0
# via
# privatim (setup.cfg)
# privatim
Expand All @@ -47,9 +53,13 @@ fasteners==0.19
# via
# privatim (setup.cfg)
# privatim
fonttools==4.53.1
# via weasyprint
greenlet==3.0.3
# via sqlalchemy
humanize==4.9.0
html5lib==1.1
# via weasyprint
humanize==4.10.0
# via
# privatim (setup.cfg)
# privatim
Expand All @@ -74,18 +84,23 @@ markupsafe==2.1.5
# privatim
# werkzeug
# wtforms
nh3==0.2.17
nh3==0.2.18
# via
# privatim (setup.cfg)
# privatim
packaging==24.1
# via zope-sqlalchemy
pastedeploy==3.1.0
# via plaster-pastedeploy
pillow==10.3.0
pdftotext==2.2.2
# via
# privatim (setup.cfg)
# privatim
pillow==10.4.0
# via
# privatim (setup.cfg)
# privatim
# weasyprint
plaster==1.1.2
# via
# plaster-pastedeploy
Expand All @@ -99,12 +114,14 @@ psycopg2==2.9.9
# via
# privatim (setup.cfg)
# privatim
pycparser==2.22
# via cffi
pydyf==0.10.0
# via weasyprint
pygments==2.18.0
# via pyramid-debugtoolbar
pypdf==4.2.0
# via
# privatim (setup.cfg)
# privatim
pyphen==0.15.0
# via weasyprint
pyramid==2.0.2
# via
# privatim (setup.cfg)
Expand Down Expand Up @@ -156,13 +173,15 @@ sedate==1.1.0
# via
# privatim (setup.cfg)
# privatim
sentry-sdk==2.5.1
sentry-sdk==2.8.0
# via
# privatim (setup.cfg)
# privatim
six==1.16.0
# via python-dateutil
sqlalchemy==2.0.30
# via
# html5lib
# python-dateutil
sqlalchemy==2.0.31
# via
# privatim (setup.cfg)
# alembic
Expand All @@ -178,6 +197,10 @@ sqlalchemy-utils==0.41.2
# via
# privatim (setup.cfg)
# privatim
tinycss2==1.3.0
# via
# cssselect2
# weasyprint
transaction==4.0
# via
# privatim (setup.cfg)
Expand All @@ -193,7 +216,6 @@ typing-extensions==4.12.2
# privatim (setup.cfg)
# alembic
# privatim
# pypdf
# sqlalchemy
urllib3==2.2.2
# via
Expand All @@ -205,6 +227,15 @@ waitress==3.0.0
# via
# privatim (setup.cfg)
# privatim
weasyprint==62.3
# via
# privatim (setup.cfg)
# privatim
webencodings==0.5.1
# via
# cssselect2
# html5lib
# tinycss2
webob==1.8.7
# via
# privatim (setup.cfg)
Expand Down Expand Up @@ -246,6 +277,8 @@ zope-sqlalchemy==3.1
# via
# privatim (setup.cfg)
# privatim
zopfli==0.2.3
# via fonttools

# The following packages were excluded from the output:
# setuptools
6 changes: 3 additions & 3 deletions requirements/compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ echo "-e ." | uv pip compile setup.cfg - \

echo "Building tests_requirements.txt"
uv pip compile setup.cfg \
--extra testing \
--extra typing \
--extra test \
--extra mypy \
-o tests_requirements.txt \
-c requirements.txt \
-c requirements.txt
"$@"
22 changes: 7 additions & 15 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ install_requires =
Markdown
markupsafe
nh3
pdftotext
pyramid
pyramid_beaker
pyramid_chameleon
Expand All @@ -53,7 +54,7 @@ install_requires =
typing_extensions
WebOb
waitress
WeasyPrint
weasyprint==62.3
WTForms
werkzeug
plaster_pastedeploy
Expand Down Expand Up @@ -84,24 +85,14 @@ console_scripts =
add_meeting = privatim.cli.add_meeting:main
delete_meetings = privatim.cli.delete_meetings:main
upgrade = privatim.cli.upgrade:upgrade
print_tsvectors = privatim.cli.helpers:print_tsvectors
print_text = privatim.cli.helpers:print_text
reindex = privatim.cli.helpers:reindex
shell = privatim.cli.shell:shell

[options.extras_require]
dev =
bandit[toml]
flake8
flake8-bugbear
flake8-comprehensions
flake8-markupsafe@git+https://github.com/vmagamedov/flake8-markupsafe#egg=b391bd13df9330e01666d304b7f4403d67e5ceba
flake8-noqa
flake8-pyi
flake8-type-checking
pre-commit
pytest-profiling
scrambler

mypy =
mypy
mypy==1.10.1
mypy_zope>1.0.0
lxml-stubs
types-babel
Expand All @@ -124,6 +115,7 @@ test =
pytest
pytest-cov
pytest-codecov
pytest-postgresql
pytest-xdist
pytest-sugar
pyquery
Expand Down
9 changes: 8 additions & 1 deletion src/privatim/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from functools import partial
from fanstatic import Fanstatic
from sqlalchemy.dialects.postgresql import TSVECTOR

from privatim.layouts.action_menu import ActionMenuEntry
from pyramid.config import Configurator
from pyramid_beaker import session_factory_from_settings
Expand Down Expand Up @@ -69,7 +71,7 @@
user = request.user
if not user:
return ''
return request.route_url('download_general_file', id=user.picture.id)
return request.route_url('download_file', id=user.picture.id)

config.add_request_method(profile_pic, 'profile_pic', property=True)
config.add_request_method(MessageQueue, 'messages', reify=True)
Expand Down Expand Up @@ -147,4 +149,9 @@
),
)

context.operations.add_column(

Check warning on line 152 in src/privatim/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/privatim/__init__.py#L152

Added line #L152 was not covered by tests
'consultations',
Column('searchable_text_de_CH', TSVECTOR())
)

context.commit()
1 change: 1 addition & 0 deletions src/privatim/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from pyramid.threadlocal import get_current_request


from typing import TYPE_CHECKING
if TYPE_CHECKING:
from collections.abc import Callable
Expand Down
Loading