search_cop icon indicating copy to clipboard operation
search_cop copied to clipboard

generator for attribute options

Open anaice opened this issue 6 years ago • 3 comments

Hello @mrkamel

I was wondering if it would be possible to use a generator directly in the options of an attribute.

search_scope :search do
  attributes person: [ "person.full_name", "person.display_name", "person.doc_id"]
  options :person, left_wildcard: false
  attributes partner_doc_id: ["person.doc_id" ]
  options :partner_doc_id, raw_ilike: true

  #...

  generator :raw_ilike do |column_name, raw_value|
    "(  #{column_name} IS NOT NULL AND
       regexp_replace(#{column_name}, '[^a-zA-Z0-9]+', '','g') ILIKE ('%' || regexp_replace('#{raw_value}', '[^a-zA-Z0-9]+', '','g') || '%') 
      )
     "
  end
end

I know the generator is designed for hash based queries, but it would be a very useful feature to be able to apply it directly to an attribute.

anaice avatar Oct 11 '19 13:10 anaice

Hi, sry for the delayed response. Currently, it's not possible. I'm of course open for contributions, but i won't add it myself due to lack of time and i've no need for it.

mrkamel avatar Oct 23 '19 19:10 mrkamel

Hi. Sorry for the delay here too. I understand your point. I'll study the code a bit and see if I can implement this. Anyway, thanks for your time.

anaice avatar Oct 28 '19 17:10 anaice

I am going to try taking a stab at adding this functionality. Seems like a very useful feature.

westonganger avatar Apr 22 '22 17:04 westonganger