Skip to content

Instantly share code, notes, and snippets.

View thedanielhanke's full-sized avatar

Daniel Hanke thedanielhanke

  • RE: GmbH
  • Cologne, Germany
View GitHub Profile
@thedanielhanke
thedanielhanke / parse_query.rb
Created February 2, 2016 21:26 — forked from aliang/parse_query.rb
search query string parser, google-ish
# via http://jablan.radioni.ca/post/4982485974/parsing-search-query-in-ruby
def parse_query s
s.scan(/((\S+)\:\s?)?([+-])?(("(.+?)")|(\S+))/).map{|match|
Hash[
[nil, :prefix, :plusminus, nil, nil, :phrase, :word].zip(match).select(&:all?)
]
}
end