Skip to content

Instantly share code, notes, and snippets.

@danielnolan
Last active August 29, 2015 13:56
Show Gist options
  • Save danielnolan/9003127 to your computer and use it in GitHub Desktop.
Save danielnolan/9003127 to your computer and use it in GitHub Desktop.
doesn't make sense
#mine
def self.keyword_search_mobile(attributes={}, user_attributes={}, offset = nil, limit = nil)
scope = []
if !attributes[:search].blank?
search = attributes.with_indifferent_access[:search]
scope = self.all(
:conditions => [
"short_desc ~* ? OR keywords ~* ? OR title ~* ?",
/\y#{search}\y/, /\y#{search}\y/, /\y#{search}\y/
]
)
scope = scope.all(self.product_type_list.disable_on_mobile => false)
scope = scope.all(offset: offset.to_i) if offset
scope = scope.all(limit: limit.to_i) if limit
end
scope
end
#created by platform
def keyword_search_mobile(attributes={}, user_attributes={}, offset = nil, limit = nil)
scope = self.all
if !attributes[:search].blank?
scope = scope & all(:'short_desc' => attributes.with_indifferent_access[:search])
end
scope = scope.all(:order => [:title.asc])
scope = scope.all(offset: offset.to_i) if offset
scope = scope.all(limit: limit.to_i) if limit
scope
end
#for mine to work with the params the way that ios sdk passes
#you have to add with_indifferent_access to the check if the search attribute is blank
def self.keyword_search_mobile(attributes={}, user_attributes={}, offset = nil, limit = nil)
scope = []
if !attributes.with_indifferent_access[:search].blank?
search = attributes.with_indifferent_access[:search]
scope = self.all(
:conditions => [
"short_desc ~* ? OR keywords ~* ? OR title ~* ?",
/\y#{search}\y/, /\y#{search}\y/, /\y#{search}\y/
]
)
scope = scope.all(self.product_type_list.disable_on_mobile => false)
scope = scope.all(offset: offset.to_i) if offset
scope = scope.all(limit: limit.to_i) if limit
end
scope
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment