ORDER BY COALESCE(updated_at, created_at) DESC LIMIT %s", limit)
def search(self, query, limit=None):
- return self._get_posts("SELECT blog.* FROM blog \
+ posts = self._get_posts("SELECT blog.* FROM blog \
LEFT JOIN blog_search_index search_index ON blog.id = search_index.post_id \
WHERE search_index.document @@ websearch_to_tsquery('english', %s) \
ORDER BY ts_rank(search_index.document, websearch_to_tsquery('english', %s)) DESC \
LIMIT %s", query, query, limit)
+ return list(posts)
+
def has_had_recent_activity(self, **kwargs):
t = datetime.timedelta(**kwargs)
</nav>
<h1 class="title is-1">{{ _("IPFire Blog") }}</h1>
+
+ {% if q %}
+ <h6 class="subtitle is-5">
+ {{ _("Search Results for '%s'") % q }}
+ </h6>
+ {% end %}
</div>
</div>
</section>
</div>
{% end %}
+ {% if q and not posts %}
+ <div class="notification">
+ {{ _("No Results Found For '%s'") % q }}
+ </div>
+ {% end %}
+
{% module BlogList(posts, relative=True) %}
</div>
<div class="column is-4">
<div class="block">
- <div class="container">
+ <form method="GET" action="">
<div class="field">
- <p class="control">
- <form method="GET" action="/search">
- <input class="input is-primary" type="text" name="q" placeholder="Search...">
- </form>
- </p>
+ <div class="control has-icons-left">
+ <input class="input is-medium" type="text"
+ name="q" {% if q %}value="{{ q }}"{% end %}
+ placeholder="{{ _("Search...") }}">
+ <span class="icon is-small is-left">
+ <i class="fas fa-search"></i>
+ </span>
+ </div>
</div>
- </div>
+ </form>
</div>
{% module BlogHistoryNavigation() %}
class IndexHandler(base.BaseHandler):
def get(self):
- posts = self.backend.blog.get_newest(limit=10)
+ latest_post = None
- # Allow this to be cached for 5 minutes
- if not self.current_user:
- self.set_expires(300)
+ # Fetch the search query
+ q = self.get_argument("q", None)
+
+ # If the user is searching, perform the search
+ if q:
+ posts = self.backend.blog.search(q)
+
+ # Otherwise fetch the latest posts
+ else:
+ posts = self.backend.blog.get_newest(limit=10)
- # Extract the latest post
- latest_post = posts.pop(0)
+ # Extract the latest post
+ latest_post = posts.pop(0)
- self.render("blog/index.html", posts=posts, latest_post=latest_post)
+ self.render("blog/index.html", q=q, posts=posts, latest_post=latest_post)
class AuthorHandler(base.BaseHandler):