diff s4-blog.sh @ 344:7ff49d1c2987

Support '<', '>' for date search keyword
author HIROSE Yuuji <yuuji@gentei.org>
date Tue, 25 Oct 2016 13:04:49 +0859
parents bad68ea6c30a
children dd0c70353869
line wrap: on
line diff
--- a/s4-blog.sh	Tue Oct 25 11:29:32 2016 +0859
+++ b/s4-blog.sh	Tue Oct 25 13:04:49 2016 +0859
@@ -471,16 +471,25 @@
     rowid=$((${kwd#\#} + 0))	# Force to be a number
     kc="ar.rowid = $rowid"
   else
-    for k in `echo "$kwd" | sed "s/'/''/g"`; do
-      if expr x"$k" : 'x@[1-9][][0-9]*-[][0-9:-]*$' >/dev/null 1>&2; then
-	# Like '@2016-10-10', expands to "s.ctime GLOB '@2016-10-10'"
-	ctime=${k#@}
+    for k in `echo "$kwd" | sed "s/'/''/g"`; do		# With wrap quotes
+      if expr x"$k" : 'x@[><= ]*[1-9][][0-9]*-[][0-9:-]*$' >/dev/null >&2; then
+	# '@<2016-10-10'	-> ctime < '2016-10-10'
+	# '@>=2016-10-10'	-> ctime >= '2016-10-10'
+	# '@2016-10-10'		-> ctime GLOB '@2016-10-10'
+	k=${k#@}
+	case "$k" in
+	  [\<\>]*)	op=${k%%[!<>=]*}; ctime=${k##*[><= ]} ;;
+	  *)	op='GLOB'; ctime="${k##*[><= ]}*" ;;
+	esac
+	kc=$kc${kc:+" AND "}"ctime $op '${ctime}'"
 	# Not sure GROUP BY a.blogid is comfortable for searchers...?
-	kc=$kc${kc:+" AND "}"ctime GLOB '${ctime}*'"
 	##### kwdgrp=" GROUP BY a.blogid"   ## Add this to lessen results
       elif [ x"$k" = x"@today" -o x"$k" = x"@今日" ]; then
 	ctime=`date +%F`
 	kc=$kc${kc:+" AND "}"ctime GLOB '${ctime}*'"
+      elif [ x"$k" = x"@week" ]; then
+	ctime=`query "SELECT datetime('now', 'localtime', '-7 days');"`
+	kc=$kc${kc:+" AND "}"ctime > '${ctime}'"
       else
 	kc=$kc${kc:+" AND "}"content LIKE '%$k%'"
       fi

yatex.org