This project is an example for using Django's full text search based on PostgreSQL.
The version found in the main branch provides an application with a search
form. The actual search uses Django's icontains which on an SQL level maps
to like while ignoring the case of letters. This works only for simple
search requests and is very inefficient.
The search functionality is gradually improved in additional feature branches:
Before you can run the application in the main branch you need to install:
Next start downloading some ebooks:
sh scripts/rsync_gutenberg.shDownloading the entire library of Project Gutenberg will take hours. But for testing this script only needs to run for a couple of minutes until it downloaded a few dozen or hundreds of ebooks.
You can leave this running in the background in case you want a larger amount of ebooks eventually.
Next, launch the docker container providing the PostgreSQL database server:
docker-compose upWhile the server runs, you cannot enter new commands in the terminal, so open
a new one for the commands to follow. (Alternatively you could add the option
--detach to the above call.)
After that, set up the poetry environment and pre-commit hook:
sh scripts/setup_project.shOnce this is finished, open a poetry shell:
poetry shellAny further commands should be run in this shell.
Next, set up the database:
sh scripts/reset_local_database.shThis creates or clears the database and loads a few ebooks into it.
Finally, you can run the local development server. Optionally you can specify the port to avoid clashes with existing services:
python manage.py runserver 8078To search, navigate to http://127.0.0.1:8078/ and enter a single word search term, for example "house". (Later branches allow more sophisticated searches).
To browse the documents available, navigate to
http://127.0.0.1:8078/admin/gutensearch/document/. For the login, use
admin as username and deMo.123 as password.
After that, open the slides stored in
Full text search with Django and PostgreSQL.odp and work your way through
them. For each new feature introduced there is an educational
pull request
showing the code needed to implement it (based on the previous feature
branch).