diff --git a/install.sh b/install.sh index 5197390..5fb737f 100755 --- a/install.sh +++ b/install.sh @@ -10,13 +10,28 @@ if [ -d "/vagrant" ]; then fi echo "Provisioning..." -sudo apt-get update -sudo apt-get install -y software-properties-common python-software-properties + +if ! type "add-apt-repository" > /dev/null; then + sudo apt-get update + sudo apt-get install -y software-properties-common python-software-properties +fi + +# Elastic Search +wget -qO - http://packages.elasticsearch.org/GPG-KEY-elasticsearch | sudo apt-key add - +echo 'deb http://packages.elasticsearch.org/elasticsearch/1.4/debian stable main' | sudo tee /etc/apt/sources.list.d/elastic.list + sudo add-apt-repository -y ppa:chris-lea/node.js sudo apt-get update + sudo apt-get install -y python build-essential pkg-config git \ python-pip python-virtualenv python-dev zlib1g-dev \ -libffi-dev libyaml-dev libssl-dev nodejs +libffi-dev libyaml-dev libssl-dev nodejs openjdk-7-jre-headless elasticsearch + +# Create swap file because ES eats up RAM and 14.04 doesn't have swap by default +sudo fallocate -l 1G /swapfile +sudo chmod 600 /swapfile +sudo mkswap /swapfile +sudo swapon /swapfile # lxml deps # libxml2-dev libxslt1-dev @@ -45,7 +60,6 @@ sudo npm install -g bower cd /home/vagrant - virtualenv .venv source .venv/bin/activate @@ -64,4 +78,6 @@ sudo mv /tmp/realms-wiki /usr/local/bin sudo chmod +x /usr/local/bin/realms-wiki +sudo service elasticsearch start + realms-wiki start \ No newline at end of file diff --git a/realms/modules/search/hooks.py b/realms/modules/search/hooks.py index d8a7467..1c682c2 100644 --- a/realms/modules/search/hooks.py +++ b/realms/modules/search/hooks.py @@ -3,11 +3,13 @@ from realms.modules.search.models import Search @Wiki.after('write_page') -def wiki_write_page(name, content, **kwargs): +def wiki_write_page(name, content, message=None, username=None, email=None, **kwargs): body = dict(name=name, - content=content) - body.update(kwargs) - return Search.index('wiki', 'page', body=body) + content=content, + message=message, + email=email, + username=username) + return Search.index('wiki', 'page', id_=name, body=body) @Wiki.after('rename_page') diff --git a/realms/modules/search/models.py b/realms/modules/search/models.py index e0d92c1..c0ea692 100644 --- a/realms/modules/search/models.py +++ b/realms/modules/search/models.py @@ -10,7 +10,16 @@ class Search(HookMixin): @classmethod def wiki(cls, query): - return elastic.search(index='wiki', body={"query": {"match_all": {}}}) + if not query: + return [] + + res = elastic.search(index='wiki', body={"query": { + "multi_match": { + "query": query, + "fields": ["name^3", "content"] + }}}) + + return [hit["_source"] for hit in res['hits']['hits']] @classmethod def users(cls, query): diff --git a/realms/modules/search/views.py b/realms/modules/search/views.py index 049d849..f08068f 100644 --- a/realms/modules/search/views.py +++ b/realms/modules/search/views.py @@ -1,10 +1,10 @@ from flask import abort, g, render_template, request, redirect, Blueprint, flash, url_for, current_app from .models import Search + blueprint = Blueprint('search', __name__) @blueprint.route('/_search') def search(): results = Search.wiki(request.args.get('q')) - print results return render_template('search/search.html', results=results) \ No newline at end of file diff --git a/realms/static/css/style.css b/realms/static/css/style.css index 0709810..1116438 100644 --- a/realms/static/css/style.css +++ b/realms/static/css/style.css @@ -51,6 +51,10 @@ border-radius: 0; } +.navbar .form-control { + max-height: 33px; +} + .checkbox-cell { width: 4em; padding: 0.3em; diff --git a/realms/templates/layout.html b/realms/templates/layout.html index 665ba8b..082bc74 100644 --- a/realms/templates/layout.html +++ b/realms/templates/layout.html @@ -49,7 +49,15 @@