Casecommons / pg_search

pg_search builds ActiveRecord named scopes that take advantage of PostgreSQL’s full text search

Home Page:http://www.casebook.net

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Search documents with blank content

vanboom opened this issue · comments

commented

It is possible for the user to reference an attribute or attributes for multisearchable that contains no data. If there is no data for the content of the pg_search_document, a record is created anyway.

Suggestion - it may be more efficient to not create a pg_search_document record when there is no searchable data to be stored.

def create_or_update_pg_search_document
if !pg_search_document
create_pg_search_document(pg_search_document_attrs)
elsif should_update_pg_search_document?
pg_search_document.update(pg_search_document_attrs)
end
end

commented

A work around exists using the if feature...

  multisearchable :against=>[:serial_number, :model_number], if: :has_multisearchable?

  def has_multisearchable?
      serial_number.present? or model_number.present?
  end