Update Haystack indexer to use Xapian

This commit is contained in:
Skia 2018-11-26 19:54:51 +01:00
parent c071ed66bc
commit 65e0b15b31
6 changed files with 12 additions and 13 deletions

2
.gitignore vendored
View File

@ -10,6 +10,6 @@ doc/html
data/ data/
/static/ /static/
sith/settings_custom.py sith/settings_custom.py
sith/whoosh_index/ sith/search_indexes/
.coverage .coverage
coverage_report/ coverage_report/

View File

@ -5,7 +5,10 @@ test:
stage: test stage: test
script: script:
- apt-get update - apt-get update
- apt-get install -y gettext - apt-get install -y gettext python3-xapian
- pushd /usr/lib/python3/dist-packages/xapian && ln -s _xapian* _xapian.so && popd
- export PYTHONPATH="/usr/lib/python3/dist-packages:$PYTHONPATH"
- python -c 'import xapian' # Fail immediately if there is a problem with xapian
- pip install -r requirements.txt - pip install -r requirements.txt
- pip install coverage - pip install coverage
- ./manage.py compilemessages - ./manage.py compilemessages

View File

@ -30,14 +30,14 @@ generate a complete HTML documentation that will be available in the *./doc/html
### Dependencies: ### Dependencies:
See requirements.txt See requirements.txt
You may need to install some dev libraries like `libmysqlclient-dev`, `libssl-dev`, `libjpeg-dev`, or `zlib1g-dev` to install all the You may need to install some dev libraries like `libmysqlclient-dev`, `libssl-dev`, `libjpeg-dev`, `python3-xapian`, or `zlib1g-dev` to install all the
requiered dependancies with pip. You may also need `mysql-client`. Don't also forget `python3-dev` if you don't have it requiered dependancies with pip. You may also need `mysql-client`. Don't also forget `python3-dev` if you don't have it
already. already.
You can check all of them with: You can check all of them with:
``` ```
sudo apt install libmysqlclient-dev libssl-dev libjpeg-dev zlib1g-dev python3-dev libffi-dev python3-dev libgraphviz-dev pkg-config sudo apt install libmysqlclient-dev libssl-dev libjpeg-dev zlib1g-dev python3-dev libffi-dev python3-dev libgraphviz-dev pkg-config python3-xapian
``` ```
The development is done with sqlite, but it is advised to set a more robust DBMS for production (Postgresql for example) The development is done with sqlite, but it is advised to set a more robust DBMS for production (Postgresql for example)

View File

@ -71,12 +71,7 @@ def notification(request, notif_id):
def search_user(query, as_json=False): def search_user(query, as_json=False):
res = ( res = SearchQuerySet().models(User).filter_or(text__contains=query)[:20]
SearchQuerySet()
.models(User)
.filter(text=query)
.filter_or(text__contains=query)[:20]
)
return [r.object for r in res] return [r.object for r in res]

View File

@ -11,7 +11,7 @@ phonenumbers
django-ajax-selects django-ajax-selects
reportlab reportlab
django-haystack django-haystack
whoosh xapian-haystack
django-debug-toolbar django-debug-toolbar
libsass libsass
django-ordered-model django-ordered-model

View File

@ -184,8 +184,9 @@ TEMPLATES = [
HAYSTACK_CONNECTIONS = { HAYSTACK_CONNECTIONS = {
"default": { "default": {
"ENGINE": "haystack.backends.whoosh_backend.WhooshEngine", "ENGINE": "xapian_backend.XapianEngine",
"PATH": os.path.join(os.path.dirname(__file__), "whoosh_index"), "PATH": os.path.join(os.path.dirname(__file__), "search_indexes", "xapian"),
"INCLUDE_SPELLING": True,
} }
} }