impress/app/models/item/search/fields/text_field.rb
Matchu 6e09b8bc10 globalized search first draft
Confirmed features:
    * Output (retrieval, sorting, etc.)
    * Name (positive and negative, but new behavior)
    * Flags (positive and negative)

Planned features:
    * users:owns, user:wants

Known issues:
    * Sets are broken
        * Don't render properly
        * Shouldn't actually be done as joined sets, anyway, since
          we actually want (set1_zone1 OR set1_zone2) AND
          (set2_zone1 OR set2_zone2), which will require breaking
          it into multiple terms queries.
    * Name has regressed: ignores phrases, doesn't require *all*
      words. While we're breaking sets into multiple queries,
      maybe we'll do something similar for name. In fact, we
      really kinda have to if we're gonna keep sorting by name,
      since "straw hat" returns all hats. Eww.
2013-01-24 18:24:35 -06:00

29 lines
609 B
Ruby

class Item
module Search
module Fields
class TextField < Field
def initialize(*args)
super(*args)
@values = {true => '', false => ''}
end
def <<(filter)
@values[filter.positive?] << (filter.value + ' ')
end
def to_flex_params
{
key => nil_if_empty(@values[true]),
:"negative_#{key}" => nil_if_empty(@values[false])
}
end
private
def nil_if_empty(str)
str unless str.empty?
end
end
end
end
end