search pass two
This commit is contained in:
parent
312c61ef61
commit
13d4be8937
24
install.sh
24
install.sh
|
@ -10,13 +10,28 @@ if [ -d "/vagrant" ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Provisioning..."
|
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 add-apt-repository -y ppa:chris-lea/node.js
|
||||||
sudo apt-get update
|
sudo apt-get update
|
||||||
|
|
||||||
sudo apt-get install -y python build-essential pkg-config git \
|
sudo apt-get install -y python build-essential pkg-config git \
|
||||||
python-pip python-virtualenv python-dev zlib1g-dev \
|
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
|
# lxml deps
|
||||||
# libxml2-dev libxslt1-dev
|
# libxml2-dev libxslt1-dev
|
||||||
|
@ -45,7 +60,6 @@ sudo npm install -g bower
|
||||||
|
|
||||||
cd /home/vagrant
|
cd /home/vagrant
|
||||||
|
|
||||||
|
|
||||||
virtualenv .venv
|
virtualenv .venv
|
||||||
source .venv/bin/activate
|
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 chmod +x /usr/local/bin/realms-wiki
|
||||||
|
|
||||||
|
sudo service elasticsearch start
|
||||||
|
|
||||||
realms-wiki start
|
realms-wiki start
|
|
@ -3,11 +3,13 @@ from realms.modules.search.models import Search
|
||||||
|
|
||||||
|
|
||||||
@Wiki.after('write_page')
|
@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,
|
body = dict(name=name,
|
||||||
content=content)
|
content=content,
|
||||||
body.update(kwargs)
|
message=message,
|
||||||
return Search.index('wiki', 'page', body=body)
|
email=email,
|
||||||
|
username=username)
|
||||||
|
return Search.index('wiki', 'page', id_=name, body=body)
|
||||||
|
|
||||||
|
|
||||||
@Wiki.after('rename_page')
|
@Wiki.after('rename_page')
|
||||||
|
|
|
@ -10,7 +10,16 @@ class Search(HookMixin):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def wiki(cls, query):
|
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
|
@classmethod
|
||||||
def users(cls, query):
|
def users(cls, query):
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
from flask import abort, g, render_template, request, redirect, Blueprint, flash, url_for, current_app
|
from flask import abort, g, render_template, request, redirect, Blueprint, flash, url_for, current_app
|
||||||
from .models import Search
|
from .models import Search
|
||||||
|
|
||||||
blueprint = Blueprint('search', __name__)
|
blueprint = Blueprint('search', __name__)
|
||||||
|
|
||||||
|
|
||||||
@blueprint.route('/_search')
|
@blueprint.route('/_search')
|
||||||
def search():
|
def search():
|
||||||
results = Search.wiki(request.args.get('q'))
|
results = Search.wiki(request.args.get('q'))
|
||||||
print results
|
|
||||||
return render_template('search/search.html', results=results)
|
return render_template('search/search.html', results=results)
|
|
@ -51,6 +51,10 @@
|
||||||
border-radius: 0;
|
border-radius: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.navbar .form-control {
|
||||||
|
max-height: 33px;
|
||||||
|
}
|
||||||
|
|
||||||
.checkbox-cell {
|
.checkbox-cell {
|
||||||
width: 4em;
|
width: 4em;
|
||||||
padding: 0.3em;
|
padding: 0.3em;
|
||||||
|
|
|
@ -49,7 +49,15 @@
|
||||||
<li><a href="{{ url_for('wiki.history', name=name) }}"><i class="fa fa-clock-o"></i> History</a></li>
|
<li><a href="{{ url_for('wiki.history', name=name) }}"><i class="fa fa-clock-o"></i> History</a></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<ul class="nav navbar-nav navbar-right">
|
<ul class="nav navbar-nav navbar-right">
|
||||||
|
<li>
|
||||||
|
<form class="navbar-form" role="search" action="{{ url_for('search.search') }}">
|
||||||
|
<div class="form-group">
|
||||||
|
<input name="q" type="text" class="form-control" placeholder="Search">
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</li>
|
||||||
{% if current_user.is_authenticated() %}
|
{% if current_user.is_authenticated() %}
|
||||||
<li class="dropdown user-avatar">
|
<li class="dropdown user-avatar">
|
||||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
|
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
|
||||||
|
|
|
@ -1,4 +1,17 @@
|
||||||
{% extends 'layout.html' %}
|
{% extends 'layout.html' %}
|
||||||
{% block body %}
|
{% block body %}
|
||||||
|
{% if results %}
|
||||||
|
<div class="list-group">
|
||||||
|
{% for r in results %}
|
||||||
|
<a href="{{ url_for('wiki.page', name=r['name']) }}" class="list-group-item">
|
||||||
|
<h4 class="list-group-item-heading">{{ r['name'] }}</h4>
|
||||||
|
<p class="list-group-item-text">
|
||||||
|
{{ r['content'][:100] }}
|
||||||
|
</p>
|
||||||
|
</a>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
{% else %}
|
||||||
|
No Results Found
|
||||||
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
Loading…
Reference in a new issue