# Generated by Django 2.1.5 on 2019-01-09 14:54

from django.db import migrations


class Migration(migrations.Migration):

    dependencies = [
        ('grafit', '0016_add_webcontent_to_article'),
    ]

    operations = [
        migrations.RunSQL(
            """
            DROP MATERIALIZED VIEW grafit_search_index;

            CREATE MATERIALIZED VIEW grafit_search_index AS
                SELECT
                    node.id,
                    node.title,
                    setweight(to_tsvector('english', node.title), 'A') ||
                    setweight(to_tsvector('english', node.text), 'B') ||
                    setweight(to_tsvector('english', COALESCE(node.web_content, '')), 'C')  as document
                FROM grafit_article AS node
                GROUP BY node.id;
                
            DROP INDEX IF EXISTS idx_grafit_search_index;

            CREATE INDEX idx_grafit_search_index
            ON grafit_search_index
            USING gin (document);

            DROP INDEX IF EXISTS grafit_search_unique;
                
            CREATE UNIQUE INDEX grafit_search_unique
            ON grafit_search_index (id);
            """
        ),
    ]
