Casecommons / pg_search

pg_search builds ActiveRecord named scopes that take advantage of PostgreSQL’s full text search
http://www.casebook.net
MIT License
1.3k stars 369 forks source link

column: add support for Arel::Nodes::SqlLiteral #503

Closed kyrofa closed 1 year ago

kyrofa commented 1 year ago

This PR resolves #252, allowing for more more advanced columns, such as extracting elements out of json arrays, or fields out of json objects. This is intended to be entirely backward compatible.

chiperific commented 12 months ago

Is this going to be released? I don't see this code in v.2.3.6

egrueter-dev commented 11 months ago

Can we get some proper documentation about how to use this?

comictvn commented 5 months ago

Can we get some proper documentation about how to use this?

me too

diddeb commented 4 months ago

➕ 1️⃣ on the docs. Or just a stupid-simple example for moots like myself.

kalashnikovisme commented 4 months ago

Found something useful in tests. An example, that works for me:

class Car < ApplicationRecord
  store_accessor :options, :number
end

class Driver < ApplicationRecord
  has_many :cars

  pg_search_scope(
    :pg_search,
    against: [:first_name, :last_name, :middle_name],
    associated_against: {
      cars: [Arel.sql("cars.options->>'number'")]
    },
    using: { tsearch: { prefix: true } }
  )
end

But looks like tsearch does not work for "cars.options->>'number'") column. Trying to fix it right now. It works well for first_name, etc. of Driver still.

As I know tsvector does not work with JSONB by default. As I see there is converting jsonb to string to be appropriate for tsvector, but it does not work.

jakemcallister commented 1 month ago

did you ever get this working?