Don't forget to lycansubscribe

added support for phrases in quotes

Changed files
+16 -5
app
+1 -1
app/models/searchable.rb
··· 26 26 scope :matching_terms, ->(terms) { 27 27 where( 28 28 (["(posts.text ~* ?)"] * (terms.length)).join(" AND "), 29 - *(terms.map { |x| "\\y#{x}\\y" }) 29 + *(terms.map { |x| "\\y" + x.gsub(/\s+/, "\\s+") + "\\y" }) 30 30 ) 31 31 } 32 32
+14 -3
app/query_parser.rb
··· 1 1 class QueryParser 2 - def parse_terms(query) 3 - query = query.strip.gsub('%', "\\%") 4 - query.split(/ +/) 2 + attr_reader :terms 3 + 4 + def initialize(query) 5 + @terms = [] 6 + query = query.strip 7 + 8 + while match = query.match(/".+?"/) 9 + range = match.begin(0)...match.end(0) 10 + phrase = query[range][1..-2].strip 11 + query[range] = ' ' 12 + @terms << phrase 13 + end 14 + 15 + @terms += query.split(/ +/) 5 16 end 6 17 end
+1 -1
app/server.rb
··· 55 55 return json_error('MissingParameter', 'Missing "collection" parameter') 56 56 end 57 57 58 - terms = QueryParser.new.parse_terms(params[:query]) 58 + terms = QueryParser.new(params[:query]).terms 59 59 60 60 collection = case params[:collection] 61 61 when 'likes' then user.likes