mirror of https://gitlab.com/tildes/tildes.git
Browse Source
Allow users to search their own posts
Allow users to search their own posts
This actually involves the necessary backend changes for full comment search, but I'm a little nervous about the privacy implications of that, and don't want to enable it for everyone out of nowhere. So for now, this just allows users to search *their own* comments or topics. These views and templates are starting to get real ugly, and probably need a major re-thinking soon.merge-requests/85/head
Deimos
5 years ago
12 changed files with 202 additions and 12 deletions
-
55tildes/alembic/versions/679090fd4977_add_search_column_index_for_comments.py
-
1tildes/prospector.yaml
-
14tildes/scss/modules/_form.scss
-
8tildes/scss/modules/_sidebar.scss
-
11tildes/sql/init/triggers/comments/comments.sql
-
8tildes/tildes/models/comment/comment.py
-
5tildes/tildes/models/comment/comment_query.py
-
2tildes/tildes/request_methods.py
-
1tildes/tildes/routes.py
-
23tildes/tildes/templates/user.jinja2
-
10tildes/tildes/templates/user_search.jinja2
-
68tildes/tildes/views/user.py
@ -0,0 +1,55 @@ |
|||||
|
"""Add search column/index for comments |
||||
|
|
||||
|
Revision ID: 679090fd4977 |
||||
|
Revises: 9fc0033a2b61 |
||||
|
Create Date: 2019-10-12 17:46:13.418316 |
||||
|
|
||||
|
""" |
||||
|
from alembic import op |
||||
|
import sqlalchemy as sa |
||||
|
from sqlalchemy.dialects import postgresql |
||||
|
|
||||
|
# revision identifiers, used by Alembic. |
||||
|
revision = "679090fd4977" |
||||
|
down_revision = "9fc0033a2b61" |
||||
|
branch_labels = None |
||||
|
depends_on = None |
||||
|
|
||||
|
|
||||
|
def upgrade(): |
||||
|
op.add_column( |
||||
|
"comments", sa.Column("search_tsv", postgresql.TSVECTOR(), nullable=True) |
||||
|
) |
||||
|
op.create_index( |
||||
|
"ix_comments_search_tsv_gin", |
||||
|
"comments", |
||||
|
["search_tsv"], |
||||
|
unique=False, |
||||
|
postgresql_using="gin", |
||||
|
) |
||||
|
|
||||
|
op.execute( |
||||
|
""" |
||||
|
CREATE TRIGGER comment_update_search_tsv_insert |
||||
|
BEFORE INSERT ON comments |
||||
|
FOR EACH ROW |
||||
|
EXECUTE PROCEDURE tsvector_update_trigger(search_tsv, 'pg_catalog.english', markdown); |
||||
|
|
||||
|
CREATE TRIGGER comment_update_search_tsv_update |
||||
|
BEFORE UPDATE ON comments |
||||
|
FOR EACH ROW |
||||
|
WHEN (OLD.markdown IS DISTINCT FROM NEW.markdown) |
||||
|
EXECUTE PROCEDURE tsvector_update_trigger(search_tsv, 'pg_catalog.english', markdown); |
||||
|
""" |
||||
|
) |
||||
|
|
||||
|
# increase the timeout since updating search for all comments could take a while |
||||
|
op.execute("SET statement_timeout TO '10min'") |
||||
|
op.execute( |
||||
|
"UPDATE comments SET search_tsv = to_tsvector('pg_catalog.english', markdown)" |
||||
|
) |
||||
|
|
||||
|
|
||||
|
def downgrade(): |
||||
|
op.drop_index("ix_comments_search_tsv_gin", table_name="comments") |
||||
|
op.drop_column("comments", "search_tsv") |
@ -0,0 +1,10 @@ |
|||||
|
{# Copyright (c) 2019 Tildes contributors <code@tildes.net> #} |
||||
|
{# SPDX-License-Identifier: AGPL-3.0-or-later #} |
||||
|
|
||||
|
{% extends 'user.jinja2' %} |
||||
|
|
||||
|
{% block title %}Search {{ user }}'s posts for "{{ search }}"{% endblock %} |
||||
|
|
||||
|
{% block main_heading %}Search results for "{{ search }}"{% endblock %} |
||||
|
|
||||
|
{% block no_posts_message %}No results found{% endblock %} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue