lib/picky/query/tokens.rb in picky-4.16.0 vs lib/picky/query/tokens.rb in picky-4.17.0

- old
+ new

@@ -11,10 +11,12 @@ attr_reader :tokens, :ignore_unassigned # Basically forwards to its internal tokens array. # forward *[Enumerable.instance_methods, :slice!, :[], :uniq!, :last, :reject!, :length, :size, :empty?, :each, :exit, :to => :@tokens].flatten + each_forward :partial=, + :to => :@tokens # Create a new Tokens object with the array of tokens passed in. # def initialize tokens, ignore_unassigned = false @tokens = tokens @@ -22,24 +24,31 @@ end # Creates a new Tokens object from a number of Strings. # def self.processed words, originals, ignore_unassigned = false - new words.zip(originals).collect! { |word, original| Token.processed word, original }, ignore_unassigned + new(words.zip(originals).collect! do |word, original| + w, *middle, rest = word.split(/\|/) + if rest + Or.new processed [w, *middle, rest], original.split(/\|/) + else + Token.processed w, original + end + end, ignore_unassigned) end # Generates an array in the form of # [ # [combination], # of token 1 # [combination, combination, combination], # of token 2 # [combination, combination] # of token 3 # ] # - def possible_combinations_in index + def possible_combinations_in categories @tokens.inject([]) do |combinations, token| - possible_combinations = token.possible_combinations_in index - + possible_combinations = token.possible_combinations categories + # Note: Optimization for ignoring tokens that allocate to nothing and # can be ignored. # For example in a special search, where "florian" is not # mapped to any category. # @@ -61,13 +70,21 @@ # def partialize_last @tokens.last.partial = true unless empty? end + # TODO # - # def originals @tokens.map(&:original) + end + def original + @tokens.map(&:original) + end + # TODO + # + def texts + @tokens.map(&:text) end # # def == other \ No newline at end of file