From 3523b9568ed781b2d27e2e7fca2c8bc426bd1369 Mon Sep 17 00:00:00 2001 From: Nobuhiro IMAI Date: Mon, 2 Jan 2012 01:49:29 +0900 Subject: [PATCH 1/3] calculating "words" is independent from search results --- lib/earthquake/commands.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/earthquake/commands.rb b/lib/earthquake/commands.rb index 931a90d..a7dd49e 100644 --- a/lib/earthquake/commands.rb +++ b/lib/earthquake/commands.rb @@ -200,17 +200,17 @@ command :search do |m| search_options = config[:search_options] ? config[:search_options].dup : {} + words = m[1].split(/\s+/).reject{|x| x[0] =~ /^-|^(OR|AND)$/ }.map{|x| + case x + when /^from:(.+)/, /^to:(.+)/ + $1 + else + x + end + } puts_items twitter.search(m[1], search_options)["results"].each { |s| s["user"] = {"screen_name" => s["from_user"]} s["_disable_cache"] = true - words = m[1].split(/\s+/).reject{|x| x[0] =~ /^-|^(OR|AND)$/ }.map{|x| - case x - when /^from:(.+)/, /^to:(.+)/ - $1 - else - x - end - } s["_highlights"] = words } end From 1a0a88f2e35ec008f6afab6bd9e5896f41df0194 Mon Sep 17 00:00:00 2001 From: Nobuhiro IMAI Date: Mon, 2 Jan 2012 01:51:15 +0900 Subject: [PATCH 2/3] reject "AND" and "OR" properly --- lib/earthquake/commands.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/earthquake/commands.rb b/lib/earthquake/commands.rb index a7dd49e..d24012a 100644 --- a/lib/earthquake/commands.rb +++ b/lib/earthquake/commands.rb @@ -200,14 +200,15 @@ command :search do |m| search_options = config[:search_options] ? config[:search_options].dup : {} - words = m[1].split(/\s+/).reject{|x| x[0] =~ /^-|^(OR|AND)$/ }.map{|x| + words = m[1].split(/\s+/).map{|x| case x when /^from:(.+)/, /^to:(.+)/ $1 + when /^-/, "AND", "OR" else x end - } + }.compact puts_items twitter.search(m[1], search_options)["results"].each { |s| s["user"] = {"screen_name" => s["from_user"]} s["_disable_cache"] = true From d3630027b2b0c780ee29b6a7e72f481d3bc392ba Mon Sep 17 00:00:00 2001 From: Nobuhiro IMAI Date: Mon, 2 Jan 2012 01:52:46 +0900 Subject: [PATCH 3/3] use shellsplit to handle phrase properly --- lib/earthquake/commands.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/earthquake/commands.rb b/lib/earthquake/commands.rb index d24012a..3e38efd 100644 --- a/lib/earthquake/commands.rb +++ b/lib/earthquake/commands.rb @@ -200,7 +200,7 @@ command :search do |m| search_options = config[:search_options] ? config[:search_options].dup : {} - words = m[1].split(/\s+/).map{|x| + words = m[1].shellsplit.map{|x| case x when /^from:(.+)/, /^to:(.+)/ $1