Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multisearch slow #209

Open
robbieshepherd opened this issue Dec 29, 2014 · 9 comments
Open

multisearch slow #209

robbieshepherd opened this issue Dec 29, 2014 · 9 comments

Comments

@robbieshepherd
Copy link

Struggling to get multisearch to work in a timely manner. I have approx 60k rows to search across, and results are taking 7-10 seconds.

My models look like:

multisearchable :against => [:heading, :tagline, :tags],
  :order_within_rank => "stories.created_at DESC",
  :ignoring => :accents,
  :using => {
    :tsearch => {:dictionary => "english"},
    :trigram => {:dictionary => "english"}
  },
  :if => :published?

My dev log shows:

  �[1m�[35m (3846.2ms)�[0m  SELECT COUNT(*) FROM "pg_search_documents" WHERE (((to_tsvector('simple', unaccent(coalesce("pg_search_documents"."content"::text, '')))) @@ (to_tsquery('simple', ''' ' || unaccent('g20') || ' '''))) OR ((unaccent(coalesce("pg_search_documents"."content"::text, ''))) % unaccent('g20')))
  Rendered application/_search.html.haml (1.2ms)
  �[1m�[36mCACHE (0.0ms)�[0m  �[1mSELECT COUNT(*) FROM "pg_search_documents" WHERE (((to_tsvector('simple', unaccent(coalesce("pg_search_documents"."content"::text, '')))) @@ (to_tsquery('simple', ''' ' || unaccent('g20') || ' '''))) OR ((unaccent(coalesce("pg_search_documents"."content"::text, ''))) % unaccent('g20')))�[0m
  �[1m�[35mPgSearch::Document Load (3872.0ms)�[0m  SELECT "pg_search_documents".*, ((ts_rank((to_tsvector('simple', unaccent(coalesce("pg_search_documents"."content"::text, '')))), (to_tsquery('simple', ''' ' || unaccent('g20') || ' ''')), 0))) AS pg_search_rank FROM "pg_search_documents" WHERE (((to_tsvector('simple', unaccent(coalesce("pg_search_documents"."content"::text, '')))) @@ (to_tsquery('simple', ''' ' || unaccent('g20') || ' '''))) OR ((unaccent(coalesce("pg_search_documents"."content"::text, ''))) % unaccent('g20'))) ORDER BY pg_search_rank DESC, "pg_search_documents"."id" ASC LIMIT 10 OFFSET 0

Why a simple count query is taking 4 seconds is beyond me. I've also tried storing the searchable data in a tsv_vector column as mentioned in https://github.com/Casecommons/pg_search/wiki/Building-indexes but it made no difference. Can anyone help point me as to what I'm doing wrong?

Thanks

@umerfarooq
Copy link

+1

@benoror
Copy link

benoror commented Jun 14, 2016

I'm Having a similar issue, did you guys found the root cause? Or any optimization/workaround? Thx!

@asia653
Copy link

asia653 commented Jul 5, 2017

Did you guys find a solution?

@kevinnguyen8699
Copy link

I'm having a similar issue

@benoror
Copy link

benoror commented Aug 23, 2018

I ended up switching search to a Elasticsearch instance

@mojobiri
Copy link

Had to do the same

@arcreative
Copy link

arcreative commented Jul 19, 2019

I'm wondering if there's a particular reason that the pg_search_documents.content field isn't of tsvector type? Haven't dug into it too deep, but seems to me that keeping this as a text field and doing the heavy lifting every time is pretty naive?

@grncdr
Copy link

grncdr commented Mar 12, 2020

I'm wondering if there's a particular reason that the pg_search_documents.content field isn't of tsvector type? Haven't dug into it too deep, but seems to me that keeping this as a text field and doing the heavy lifting every time is pretty naive?

I am not using pg_search yet, but I was looking at the migration it created and wondering exactly the same thing.

@nertzy
Copy link
Collaborator

nertzy commented Apr 10, 2020

Not all pg_search scopes use tsearch.

That said, using a tsvector is a great idea. I've been wanting to move towards generating the multisearch Active Record model instead of bundling PgSearch::Document directly in the gem, but I haven't gotten around to it yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants