Skip to content

Instantly share code, notes, and snippets.

@jwenerd
Created July 2, 2019 18:49
Show Gist options
  • Save jwenerd/c5a9974daaa71a06d4c2c865293c4fce to your computer and use it in GitHub Desktop.
Save jwenerd/c5a9974daaa71a06d4c2c865293c4fce to your computer and use it in GitHub Desktop.

Revisions

  1. jwenerd created this gist Jul 2, 2019.
    41 changes: 41 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    --------------------------------------------------------------------------------------------------------
    # FROM Global Search

    SELECT Count(*)
    FROM "pg_search_documents"
    INNER JOIN
    (
    SELECT "pg_search_documents"."id" AS pg_search_id,
    (Ts_rank((To_tsvector('simple', COALESCE("pg_search_documents"."content"::text, ''))), (To_tsquery('simple', ''' '
    || 'len'
    || ' '''
    || ':*')), 0)) AS rank
    FROM "pg_search_documents"
    WHERE (((
    To_tsvector('simple', COALESCE("pg_search_documents"."content"::text, ''))) @@ (to_tsquery('simple', ''' '
    || 'len'
    || ' '''
    || ':*'))))) AS pg_search_ce9b9dd18c5c0023f2116f
    ON "pg_search_documents"."id" = pg_search_ce9b9dd18c5c0023f2116f.pg_search_id
    WHERE "pg_search_documents"."searchable_type" = 'Question'


    --------------------------------------------------------------------------------------------------------
    # FROM Question Search

    SELECT Count(*)
    FROM "questions"
    INNER JOIN
    (
    SELECT "questions"."id" AS pg_search_id,
    (Ts_rank((To_tsvector('simple', COALESCE("questions"."title"::text, ''))
    || To_tsvector('simple', COALESCE("questions"."searchable_content"::text, ''))), (To_tsquery('simple', ''' '
    || 'len'
    || ' ''')), 0)) AS rank
    FROM "questions"
    WHERE (((
    To_tsvector('simple', COALESCE("questions"."title"::text, ''))
    || To_tsvector('simple', COALESCE("questions"."searchable_content"::text, ''))) @@ (to_tsquery('simple', ''' '
    || 'len'
    || ' '''))))) AS pg_search_17d5efa695de036a7acb61
    ON "questions"."id" = pg_search_17d5efa695de036a7acb61.pg_search_id