Super beta search
This commit is contained in:
parent
7392532f71
commit
ef4f7d7aca
|
@ -1,9 +1,10 @@
|
|||
/venv
|
||||
/.idea
|
||||
/db.sqlite3
|
||||
/*.sqlite3
|
||||
/static
|
||||
/media
|
||||
/log
|
||||
/xapian_index
|
||||
stale_outputs_checked
|
||||
__pycache__
|
||||
Thoughts.iml
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
#!/usr/bin/env bash
|
||||
# first argument of the script is Xapian version (e.g. 1.4.18)
|
||||
|
||||
VERSION=$1
|
||||
|
||||
if [ -z "$VERSION" ]; then
|
||||
echo "usage: $0 version_number" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# prepare
|
||||
mkdir -p $VIRTUAL_ENV/packages && cd $VIRTUAL_ENV/packages
|
||||
|
||||
CORE=xapian-core-$VERSION
|
||||
BINDINGS=xapian-bindings-$VERSION
|
||||
|
||||
# download
|
||||
echo "Downloading source..."
|
||||
curl -O https://oligarchy.co.uk/xapian/$VERSION/${CORE}.tar.xz
|
||||
curl -O https://oligarchy.co.uk/xapian/$VERSION/${BINDINGS}.tar.xz
|
||||
|
||||
# extract
|
||||
echo "Extracting source..."
|
||||
tar xf ${CORE}.tar.xz
|
||||
tar xf ${BINDINGS}.tar.xz
|
||||
|
||||
# install
|
||||
echo "Installing Xapian-core..."
|
||||
cd $VIRTUAL_ENV/packages/${CORE}
|
||||
./configure --prefix=$VIRTUAL_ENV && make && make install
|
||||
|
||||
PYTHON_FLAG=--with-python3
|
||||
|
||||
# The bindings for Python require python-sphinx
|
||||
echo "Installing Python-Sphinx..."
|
||||
SPHINX2_FIXED_VERSION=1.4.12
|
||||
if [ $(printf "${VERSION}\n${SPHINX2_FIXED_VERSION}" | sort -V | head -n1) = "${SPHINX2_FIXED_VERSION}" ]; then
|
||||
pip install sphinx
|
||||
else
|
||||
pip install "sphinx<2"
|
||||
fi
|
||||
|
||||
echo "Installing Xapian-bindings..."
|
||||
cd $VIRTUAL_ENV/packages/${BINDINGS}
|
||||
./configure --prefix=$VIRTUAL_ENV $PYTHON_FLAG && make && make install
|
||||
|
||||
# clean
|
||||
cd $VIRTUAL_ENV
|
||||
rm -rf $VIRTUAL_ENV/packages
|
||||
|
||||
# test
|
||||
echo "Testing Xapian..."
|
||||
python -c "import xapian"
|
|
@ -0,0 +1,16 @@
|
|||
from haystack import indexes
|
||||
from .models import Thought
|
||||
|
||||
# print("Hello")
|
||||
|
||||
class ThoughtIndex(indexes.SearchIndex, indexes.Indexable):
|
||||
text = indexes.CharField(document=True, use_template=True, template_name="search/indexes/main/thought_text.txt")
|
||||
|
||||
# author = indexes.CharField(model_attr='user')
|
||||
# pub_date = indexes.DateTimeField(model_attr='pub_date')
|
||||
|
||||
def get_model(self):
|
||||
return Thought
|
||||
|
||||
def index_queryset(self, using=None):
|
||||
return Thought.objects
|
|
@ -5,3 +5,5 @@ Pygments~=2.8.1
|
|||
Markdown~=3.3.4
|
||||
jetforce
|
||||
python-decouple
|
||||
django-haystack
|
||||
git+https://github.com/notanumber/xapian-haystack.git
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
{{ object.text }}
|
||||
{{ object.extended_text|truncatechars:238 }}
|
||||
{{ object.media_alt|truncatechars:238 }}
|
|
@ -0,0 +1,39 @@
|
|||
{% extends "whispermaphone/page.html" %}
|
||||
|
||||
{% block navigation %} nav here pls {% endblock %}
|
||||
|
||||
{% block main %}
|
||||
<form method="get" action="search">
|
||||
<table>
|
||||
{{ form.as_table }}
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>
|
||||
<input type="submit" value="Search">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
{% if query %}
|
||||
<h3>Results</h3>
|
||||
|
||||
{% for result in page.object_list %}
|
||||
<p>
|
||||
<a href="/?show={{ result.object.uuid }}">{{ result.object.text }}</a>
|
||||
</p>
|
||||
{% empty %}
|
||||
<p>No results found.</p>
|
||||
{% endfor %}
|
||||
|
||||
<!-- {% if page.has_previous or page.has_next %}
|
||||
<div>
|
||||
{% if page.has_previous %}<a href="?q={{ query }}&page={{ page.previous_page_number }}">{% endif %}« Previous{% if page.has_previous %}</a>{% endif %}
|
||||
|
|
||||
{% if page.has_next %}<a href="?q={{ query }}&page={{ page.next_page_number }}">{% endif %}Next »{% if page.has_next %}</a>{% endif %}
|
||||
</div>
|
||||
{% endif %} -->
|
||||
{% else %}
|
||||
{# Show some example queries to run, maybe query syntax, something else? #}
|
||||
{% endif %}
|
||||
</form>
|
||||
{% endblock %}
|
|
@ -12,8 +12,9 @@ https://docs.djangoproject.com/en/3.1/ref/settings/
|
|||
|
||||
from pathlib import Path
|
||||
from decouple import config
|
||||
import os
|
||||
|
||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||
# Build paths inside the project like this: BASE_DIR / "subdir".
|
||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
|
||||
|
||||
|
@ -33,60 +34,68 @@ if DEBUG:
|
|||
ALLOWED_HOSTS = ["*"]
|
||||
|
||||
|
||||
# Application definition
|
||||
|
||||
INSTALLED_APPS = [
|
||||
'django.contrib.contenttypes',
|
||||
'django.contrib.staticfiles',
|
||||
'main',
|
||||
"django.contrib.contenttypes",
|
||||
"django.contrib.staticfiles",
|
||||
|
||||
"haystack",
|
||||
|
||||
"main",
|
||||
]
|
||||
|
||||
HAYSTACK_CONNECTIONS = {
|
||||
"default": {
|
||||
"ENGINE": "xapian_backend.XapianEngine",
|
||||
"PATH": str(BASE_DIR / "xapian_index")
|
||||
},
|
||||
}
|
||||
|
||||
MIDDLEWARE = [
|
||||
'django.middleware.security.SecurityMiddleware',
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.middleware.csrf.CsrfViewMiddleware',
|
||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||
"django.middleware.security.SecurityMiddleware",
|
||||
"django.middleware.common.CommonMiddleware",
|
||||
"django.middleware.csrf.CsrfViewMiddleware",
|
||||
"django.middleware.clickjacking.XFrameOptionsMiddleware",
|
||||
]
|
||||
|
||||
CSRF_COOKIE_SECURE = True
|
||||
|
||||
ROOT_URLCONF = 'whispermaphone.urls'
|
||||
ROOT_URLCONF = "whispermaphone.urls"
|
||||
|
||||
TEMPLATES = [
|
||||
{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'DIRS': [],
|
||||
'APP_DIRS': True,
|
||||
'OPTIONS': {
|
||||
'context_processors': [
|
||||
'django.template.context_processors.debug',
|
||||
'django.template.context_processors.request',
|
||||
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
||||
"DIRS": ["templates"],
|
||||
"APP_DIRS": True,
|
||||
"OPTIONS": {
|
||||
"context_processors": [
|
||||
"django.template.context_processors.debug",
|
||||
"django.template.context_processors.request",
|
||||
],
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
WSGI_APPLICATION = 'whispermaphone.wsgi.application'
|
||||
WSGI_APPLICATION = "whispermaphone.wsgi.application"
|
||||
|
||||
|
||||
# Database
|
||||
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': BASE_DIR / 'db.sqlite3',
|
||||
"default": {
|
||||
"ENGINE": "django.db.backends.sqlite3",
|
||||
"NAME": BASE_DIR / "db.sqlite3",
|
||||
}
|
||||
}
|
||||
|
||||
DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'
|
||||
DEFAULT_AUTO_FIELD = "django.db.models.AutoField"
|
||||
|
||||
# Internationalization
|
||||
# https://docs.djangoproject.com/en/3.1/topics/i18n/
|
||||
|
||||
LANGUAGE_CODE = 'en-us'
|
||||
LANGUAGE_CODE = "en-us"
|
||||
|
||||
TIME_ZONE = 'UTC'
|
||||
TIME_ZONE = "UTC"
|
||||
|
||||
USE_I18N = True
|
||||
|
||||
|
@ -98,8 +107,8 @@ USE_TZ = True
|
|||
# Static files (CSS, JavaScript, Images)
|
||||
# https://docs.djangoproject.com/en/3.1/howto/static-files/
|
||||
|
||||
STATIC_URL = '/static/'
|
||||
STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.ManifestStaticFilesStorage'
|
||||
STATIC_URL = "/static/"
|
||||
STATICFILES_STORAGE = "django.contrib.staticfiles.storage.ManifestStaticFilesStorage"
|
||||
STATIC_ROOT = BASE_DIR / "static/"
|
||||
|
||||
MEDIA_ROOT = BASE_DIR / "media/"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
from django.conf.urls.static import static
|
||||
from django.urls import path
|
||||
from django.urls import path, include
|
||||
|
||||
from main import views
|
||||
from main.feed import MainFeed
|
||||
|
@ -10,4 +10,5 @@ urlpatterns = [
|
|||
path("about", views.about, name="about"),
|
||||
path("post", views.post, name="post"),
|
||||
path("feed", MainFeed()),
|
||||
path("search", include('haystack.urls')),
|
||||
] + (static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) if settings.DEBUG else [])
|
||||
|
|
Loading…
Reference in New Issue