Sha256: a2188f522b2d2f127f03c380ec54e3667868a3e04f46afd758d30eb57f235391
Contents?: true
Size: 958 Bytes
Versions: 18
Compression:
Stored size: 958 Bytes
Contents
# frozen_string_literal: true module Thredded class SearchParser def initialize(query) @query = query @keywords = %w(in by order) end def parse parsed_input = parse_keywords parsed_input['text'] = parse_text parsed_input end def parse_keywords found_terms_hash = {} @keywords.each do |keyword| regex = Regexp.new(keyword + '\s*:\s*\w+', Regexp::IGNORECASE) keyword_scan = @query.scan(regex) @query = @query.gsub(regex, '') next unless keyword_scan.present? keyword_scan.each do |term| found_terms_hash[keyword] ||= [] found_terms_hash[keyword] << term.delete(' ').split(':')[1] end end found_terms_hash end def parse_text regex = Regexp.new('\"[^"]*\"') found_terms = @query.scan(regex) @query = @query.sub(regex, '') found_terms.concat(@query.split(/\s+/)) end end end
Version data entries
18 entries across 18 versions & 1 rubygems