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 with multiple search terms #488

Open
Joel-Mercier opened this issue Jul 22, 2022 · 0 comments
Open

Multisearch with multiple search terms #488

Joel-Mercier opened this issue Jul 22, 2022 · 0 comments

Comments

@Joel-Mercier
Copy link

Joel-Mercier commented Jul 22, 2022

Thanks for this gem it's really useful !
I have an issue I'm stuck with. I'm using multisearch method and I would like to have the search term "American psycho" for example to only return records where the title contains both terms (at the moment it's returning records with "american" and "psycho" in the title. I haven't found any answers in the github.

include PgSearch::Model
multisearchable against: %i[title body],
                  additional_attributes: ->(r) { { model_type: r.class.name } },
                  if: :published?
PgSearch.multisearch(params[:term]).where(...)

Here is the SQL query it's producing

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', ''' ' || 'american' || ' ''' || ':*') || to_tsquery('simple', ''' ' || 'psycho' || ' ''' || ':*')), 2)) AS rank FROM "pg_search_documents" WHERE ((to_tsvector('simple', coalesce("pg_search_documents"."content"::text, ''))) @@ (to_tsquery('simple', ''' ' || 'american' || ' ''' || ':*') || to_tsquery('simple', ''' ' || 'psycho' || ' ''' || ':*')))) AS pg_search_ce9b9dd18c5c0023f2116f ON "pg_search_documents"."id" = pg_search_ce9b9dd18c5c0023f2116f.pg_search_id WHERE ("pg_search_documents"."model_type" = $1) AND ("pg_search_documents"."searchable_type" = $2)

Is there a way to change these || to && ?

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

1 participant