mrkamel/search_cop

RAILS 6 - Search in ActionText

thomaschauffour opened this issue · 3 comments

Hello,

I'd like to know if I can search in "rich_text" (ActionText) with SearchCop ? If yes, how to do this ?

  has_rich_text :content

  include SearchCop

  search_scope :search do
    attributes :title
  end

Thanks,
Thomas

afaik, rich text is text content with html markup. search cop is capable of searching in every kind of text data, either tokenized (fulltext mode) or as is via sql LIKE, i.e. when using LIKE search cop will search through the rich text and will treat the html markup as all other text. Usually that should not be an issue. If it is an issue for you, you can e.g store a separate copy of your rich text with markup being removed and search in this one then.

before_save :set_stripped_content

def set_stripped_content
  self.stripped_content = strip_html(content)
end

i guess this doesn't fully answer your question as you probably want to directly search in the associated RichText model/table. i did not yet play with that, but i guess it's a polymorphic association, so you might be able to reference it somehow like other kinds of associations. I'll try to check it out.

This seems to work:

  search_scope :search do
    attributes :title
    attributes content: 'rich_text_content.body'
  end