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

Weights on associations #529

Open
trevorfoxsoft opened this issue Jan 19, 2024 · 3 comments
Open

Weights on associations #529

trevorfoxsoft opened this issue Jan 19, 2024 · 3 comments

Comments

@trevorfoxsoft
Copy link

I am using search scopes and want to apply weights to associations. I have seen #132 and #40 but the syntax presented in them doesn’t seem to work.

  pg_search_scope :full_search,
                  against: {
                    title: "A",
                    introduction: "B",
                    hashtag: "C"
                  },
                  associated_against: {
                    content_rows: [
                      { text_1: "D" },
                      { text_2: "E" },
                      { image_caption_1: "F" },
                      { image_caption_2: "G" }
                    ]
                  }

Gives the error PG::UndefinedColumn: ERROR: column content_rows.{:text_1=>"D"} does not exist LINE 1: ...IN (SELECT "content_pages"."id" AS id, string_agg("content_r... ^

And

  pg_search_scope :full_search,
                  against: {
                    title: "A",
                    introduction: "B",
                    hashtag: "C"
                  },
                  associated_against: {
                    content_rows: {
                      text_1: "D",
                      text_2: "E",
                      image_caption_1: "F",
                      image_caption_2: "G"
                    }
                  }

gives PG::InternalError: ERROR: unrecognized weight: 69 .

Is there a way to do this?

@trevorfoxsoft
Copy link
Author

Also just tried this syntax, which gives me the same unrecognized weight error

  pg_search_scope :full_search,
                  against: [
                    [ "title", "A" ],
                    [ "introduction", "B" ],
                    [ "hashtag", "E" ]
                  ],
                  associated_against: {
                    content_rows: [
                      [ "text_1", "C" ],
                      [ "text_2", "D" ],
                      [ "image_caption_1", "F" ],
                      [ "image_caption_2", "G" ]
                    ]
                  },

@ngcheung
Copy link

the second syntax is correct, but the error is because 'E' isn't a supported weight by postgres.setweight only goes up to 'D'. https://www.postgresql.org/docs/current/textsearch-controls.html

@tsvallender
Copy link

Aah excellent, thanks. I'll forward this on to someone still working on the project it was relevant to as I never did get it fixed.

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

3 participants