Commit f8a6e1c3 by benjaoming

Search "optimization".... layout-wise :)

parent 0012481a
{% extends "wiki/article.html" %}
{% extends "wiki/base.html" %}
{% load wiki_tags i18n humanize %}
{% load url from future %}
{% block pagetitle %}{% trans "Search results for:" %} {{ search_query }}{% endblock %}
{% block wiki_contents_tab %}
{% block wiki_contents %}
<h1>{% trans "Search results for:" %} {{ search_query }}</h1>
<form class="form-search directory-toolbar">
<div class="well well-small">
<div class="pull-right">
{{ search_form.query }}
</div>
<p>{% blocktrans with paginator.object_list.count as cnt %}Your search return <strong>{{ cnt }}</strong> results.{% endblocktrans %}</p>
<div class="clearfix"></div>
</div>
</form>
<table class="table table-striped">
<tr>
<th style="width: 75%">{% trans "Title" %}</th>
......
......@@ -72,10 +72,12 @@ def get_content_snippet(content, keyword, max_words=30):
words = filter(lambda x: x!="", striptags(m.group("after")).replace("\n", " ").split(" "))
after = " ".join(words[:max_words - len(before_words)])
before = " ".join(before_words)
html = "%s <strong>%s</strong> %s" % (before,
striptags(keyword),
after)
html = "%s %s %s" % (before, striptags(keyword), after)
kw_p = re.compile(r'(%s)'%keyword, re.IGNORECASE)
html = kw_p.sub(r"<strong>\1</strong>", html)
html = mark_safe(html)
else:
html = " ".join(filter(lambda x: x!="", striptags(content).replace("\n", " ").split(" "))[:max_words])
return html
@register.filter
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment