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

How to combine Weighted Search & Association Search #40

Closed
kibaekr opened this issue May 24, 2012 · 17 comments
Closed

How to combine Weighted Search & Association Search #40

kibaekr opened this issue May 24, 2012 · 17 comments

Comments

@kibaekr
Copy link

kibaekr commented May 24, 2012

Weghted Search and Search through Associations works separately, but I was wondering how I could combine them. So I want to add the associative search as one of the weighted params.

Currently, I have

class Mission < ActiveRecord::Base
  include PgSearch
  pg_search_scope :search_by_weight, :against => {:title => 'B', :content => 'C'}, :using => [:tsearch] #, :trigram, :dmetaphone]
  pg_search_scope :search_by_tag, :associated_against => {
   :tags => [:name]
  }

How would I incorporate the search_by_tag as one of the weights 'A'?

@nertzy
Copy link
Collaborator

nertzy commented Jun 1, 2012

Interesting, we definitely overlooked that when we came up with the syntax for :associated_against.

What do you think is a natural way to specify weighting for associated parameters? I can't think of a good syntax offhand, so I'd like to do some thought experiments first to figure out what the best approach would be.

@kibaekr
Copy link
Author

kibaekr commented Jun 8, 2012

Hmm, well my first thought was to put the :associated_against inside the :against. so like

pg_search_scope :search_by_weight, :against => { (:associated_against => {:tags => [:name] }) => 'A', :title => 'B', :content => 'C'}, :using => [:tsearch] #, :trigram, :dmetaphone]

even, though it looks confusing, that was the first thing I attempted to do (it made sense to just put the entire snippet to see if it worked. Obviously the repetitive => may be a problem.

@kibaekr
Copy link
Author

kibaekr commented Jun 24, 2012

Any updates on this issue?

@nertzy
Copy link
Collaborator

nertzy commented Jun 24, 2012

None yet. I haven't had the time to dig into this too deeply.

I like the idea of using hashes as keys of hashes. In fact, it even helps with the coincidence that because of the way we read associated attributes, if you have multiple attributes on the foreign object, they all get grouped together into one string and thus we can only give one weight to the entire thing.

@kibaekr
Copy link
Author

kibaekr commented Jun 25, 2012

Thanks for the quick reply. I'll be on the lookout for an update :)

@pzaich
Copy link

pzaich commented Oct 9, 2012

Upvote :)

@utgarda
Copy link

utgarda commented Nov 21, 2012

A helpful StackOverflow discussion of this issue, also by kibaekr: http://stackoverflow.com/questions/10667242/rails-how-do-i-search-tags-generated-by-act-as-taggable-on-with-pg-search-pos

I'd love to get the new syntax proposed.

@stationkeeping
Copy link

+1

3 similar comments
@cserb
Copy link

cserb commented Dec 6, 2013

+1

@shir
Copy link

shir commented Dec 11, 2013

+1

@assimovt
Copy link

assimovt commented Apr 1, 2014

+1

@jaypinho
Copy link

Apologies if I'm misunderstanding, but shouldn't this issue be closed considering #132 has been answered?

@nertzy
Copy link
Collaborator

nertzy commented May 4, 2015

@jaypinho thanks for the helpful note. Yes, it does look like the answer to #132 applies here as well.

So, we would expect this to work:

pg_search_scope :search_by_tag, :associated_against => {
  :tags => [{:name => 'A'}]
}

If this doesn't work for your use case, feel free to reopen with more information on how to reproduce the problem. Thanks!

@nertzy nertzy closed this as completed May 4, 2015
@mattgilbertnet
Copy link

It looks like in both this issue and #132 , the conversation dropped off without anyone testing out the syntax above. When I tried syntax like that, I get this error:

ActiveRecord::StatementInvalid (PG::UndefinedColumn: ERROR: column events.{:name=>"B"} does not exist

@nertzy
Copy link
Collaborator

nertzy commented Jan 9, 2019

Hmm, I wouldn’t be surprised if something changed in the last several years that introduced the error you’re seeing. We should get test coverage around the problem you’re seeing.

@nertzy
Copy link
Collaborator

nertzy commented Jan 9, 2019

(in a new issue)

@mattgilbertnet
Copy link

I should have checked, but I'm using version 2.0.1. That's newer than the discussion above, but far from up-to-date.

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

10 participants