pg_search -v 1.0.5: Question About pg_search_scope When Two Tables Are Joined

293 views
Skip to first unread message

LightBe Corp

unread,
Jan 15, 2016, 8:10:51 PM1/15/16
to Case Commons Development
I have a pg_search_scope process in my Rails 4.2.2 application. When I initially set this up I had one table that I was searching against. In order to change the ordering of data on my view I ended up joining that table with a second table. I only want to perform text searching in the original table. I have column :name in both tables.

Here are the statements that I have in my model in my Rails model. My assumption was that since I include PgSearch in the model that it would know to check name in that table and not the other.

include PgSearch
  pg_search_scope
:name_search, against: [:name, :address, :zip, :phone, :email, :url, :keywords],
   
using: {tsearch: {dictionary: "english", prefix: true}}

Is there a way to qualify :name or somehow modify my pg_search_scope statement so it selects the correct name field to check? The code above was working as expected before I joined the table to a second one. I was not sure if I need to do the multisearch option since I have no interest in searching in any other tables in my Rails application.

Grant Hutchins

unread,
Jan 15, 2016, 8:40:21 PM1/15/16
to casecom...@googlegroups.com
When pg_search builds its queries, it uses fully-qualified column names in a sub-query which should never cause any ambiguity. 

If you are seeing any behavior that is unexpected, I'd encourage you to build a minimal example that shows the unexpected output, along with its generated SQL, and add it as a GitHub issue.

Otherwise you should be good to go. 

Grant Hutchins
--

---
You received this message because you are subscribed to the Google Groups "Case Commons Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to casecommons-d...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

LightBe Corp

unread,
Jan 15, 2016, 9:03:49 PM1/15/16
to Case Commons Development, gr...@nertzy.com
I figured out what happened. I realized that there was one condition that I had not coded for that obviously would not work hahahahaha. I thought surely nothing had changed in the gem. Everything is working as expected. Good to know that the column names are qualified for future reference.

Thanks!
Reply all
Reply to author
Forward
0 new messages