diff options
author | rhenium <re4k@re4k.info> | 2013-06-01 00:16:52 +0900 |
---|---|---|
committer | rhenium <re4k@re4k.info> | 2013-06-01 00:16:52 +0900 |
commit | cf51cb4bb07ccd6cfc17d0ee9d22377cc1ea9fc9 (patch) | |
tree | 47109e7f9ce82d822d752fd43259ab79780e00ec | |
parent | 90abe9df522b3fafdf83e0578d6ee3fac58905a5 (diff) | |
download | aclog-cf51cb4bb07ccd6cfc17d0ee9d22377cc1ea9fc9.tar.gz |
add search help page
-rw-r--r-- | app/controllers/help_controller.rb | 4 | ||||
-rw-r--r-- | app/controllers/search_controller.rb | 12 | ||||
-rw-r--r-- | app/views/help/search.html.haml | 39 | ||||
-rw-r--r-- | app/views/shared/sidebar/_help.html.haml | 1 | ||||
-rw-r--r-- | app/views/shared/sidebar/_i.html.haml | 5 | ||||
-rw-r--r-- | config/routes.rb | 12 |
6 files changed, 64 insertions, 9 deletions
diff --git a/app/controllers/help_controller.rb b/app/controllers/help_controller.rb new file mode 100644 index 0000000..0cf1567 --- /dev/null +++ b/app/controllers/help_controller.rb @@ -0,0 +1,4 @@ +class HelpController < ApplicationController + def search + end +end diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index 96396c8..6cb5014 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -10,13 +10,13 @@ class SearchController < ApplicationController def parse_query(input) str = input.dup strings = [] - str.gsub!(/"((?:\\"|[^"])*?)"/) {|m| strings << $1; " ##{strings.size - 1} " } + str.gsub!(/"((?:\\"|[^"])*?)"/) {|m| strings << $1; "##{strings.size - 1}" } groups = [] while str.sub!(/\(([^()]*?)\)/) {|m| groups << $1; " $#{groups.size - 1} " }; end conv = -> s do - s.scan(/\S+(?: OR \S+)*/).map {|co| - co.split(" OR ").map {|token| + s.scan(/\S+(?: +OR +\S+)*/).map {|co| + co.split(/ +OR +/).map {|token| if /^\$(\d+)$/ =~ token conv.call(groups[$1.to_i]) else @@ -44,8 +44,10 @@ class SearchController < ApplicationController u = User.find_by(screen_name: $1) uid = u && u.id || 0 tweets[:user_id].__send__(positive ? :eq :not_eq, uid) - when /^-?date:(\d{4}(-?)\d{2}\2\d{2})(?:\.\.|-)(\d{4}\2\d{2}\2\d{2})$/ # $1: begin, $2: end - tweets[:id].__send__(positive ? :in : :not_in, snowflake(Date.parse($1))...snowflake(Date.parse($3) + 1)) + when /^-?since:(\d{4}(-?)\d{2}\2\d{2})$/ + tweets[:id].__send__(positive ? :gteq : :lt, snowflake(Date.parse($1))) + when /^-?until:(\d{4}(-?)\d{2}\2\d{2})$/ + tweets[:id].__send__(positive ? :lt : :gteq, snowflake(Date.parse($1) + 1)) when /^-?favs?:(\d+)$/ tweets[:favorites_count].__send__(positive ? :gteq : :lt, $1.to_i) when /^-?rts?:(\d+)$/ diff --git a/app/views/help/search.html.haml b/app/views/help/search.html.haml new file mode 100644 index 0000000..b4c50bd --- /dev/null +++ b/app/views/help/search.html.haml @@ -0,0 +1,39 @@ +%h2 search options +%table + %tr + %th example + %th finds tweets... + %tr + %td aclog search + %td (containing "aclog") and (containing "search") + %tr + %td "happy hour" + %td (containing "happy hour") + %tr + %td love OR hate + %td (containing "aclog") or (containing "search") + %tr + %td beer -root + %td (containing "beer") and (not (containing "root")) + %tr + %td user:cn + %td (sent from the user @cn) + %tr + %td source:"Tweet Button" + %td (sent from the client "Tweet Button") + %tr + %td fav:30 + %td (favorited 30 times and more) + %tr + %td rt:30 + %td (retweeted 30 times and more) + %tr + %td since:20130401 until:20130531 + %td (sent between 2013-04-01 and 2013-05-31) + %tr + %td aclog fav:10 OR rt:5 + %td (containing "aclog") and ((favorited 10 times and more) or (retweeted 5 times and more)) + %tr + %td (aclog -fav:10) OR rt:5 + %td ((containing "aclog") and (not (favorited 10 times and more))) or (retweeted 5 times and more) + diff --git a/app/views/shared/sidebar/_help.html.haml b/app/views/shared/sidebar/_help.html.haml new file mode 100644 index 0000000..774d930 --- /dev/null +++ b/app/views/shared/sidebar/_help.html.haml @@ -0,0 +1 @@ += render "shared/sidebar/i" diff --git a/app/views/shared/sidebar/_i.html.haml b/app/views/shared/sidebar/_i.html.haml index 406fcaa..1b7f893 100644 --- a/app/views/shared/sidebar/_i.html.haml +++ b/app/views/shared/sidebar/_i.html.haml @@ -3,6 +3,11 @@ = link_to "about", about_path %li = link_to "api", about_api_path + %li + = link_to "search help", help_search_path +%ul.nav.nav-tabs.nav-stacked + %li + = link_to "search", search_path %ul.nav.nav-tabs.nav-stacked %li = link_to "best", best_path diff --git a/config/routes.rb b/config/routes.rb index f92e144..0b44a62 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,7 +2,7 @@ Aclog::Application.routes.draw do root to: "about#index" # JSON - scope "api", format: "json" do + scope "/api", format: "json" do get "/users/:action", controller: "users" get "/tweets/:action", controller: "tweets" end @@ -28,13 +28,17 @@ Aclog::Application.routes.draw do post "/deactivate", action: "deactivate" end - scope "about", controller: "about" do + scope "/about", controller: "about" do get "/", action: "about", as: "about" get "/api", action: "api", as: "about_api" end + scope "/help", controller: "help" do + get "/search", action: "search", as: "help_search" + end + # User pages - scope ":screen_name", controller: "users" do + scope "/:screen_name", controller: "users" do get "/stats", action: "stats", as: "user_stats" get "/discovered_by", action: "discovered_by", as: "user_discovered_by" get "/discovered_users", action: "discovered_users", as: "user_discovered_users" @@ -53,7 +57,7 @@ Aclog::Application.routes.draw do end # TweetController / Tweets - scope ":screen_name" do + scope "/:screen_name" do get "/", action: "index", as: "user" get "/best", action: "best", as: "user_best" get "/favorited", action: "favorited", as: "user_favorited" |