# Generated by Django 2.1.5 on 2019-01-07 14:31

from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ('grafit', '0015_searchresult_searchword'),
    ]

    operations = [
        migrations.AddField(
            model_name='article',
            name='update_web_content',
            field=models.BooleanField(default=True),
        ),
        migrations.AddField(
            model_name='article',
            name='web_content',
            field=models.TextField(default=None, null=True),
        ),
        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', 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);
            """
        ),
    ]
