Permalink
Browse files

simple sinatra app for live testing

  • Loading branch information...
1 parent d386a93 commit f9acccd0fd503acda80e7e61c5e6ffa2e5083212 @igrigorik committed Dec 29, 2009
Showing with 49 additions and 0 deletions.
  1. +49 −0 examples/web.rb
View
@@ -0,0 +1,49 @@
+require "rubygems"
+require "sinatra"
+require "textquery"
+require "erb"
+
+$KCODE = 'u'
+
+get "/" do
+ params['textstring'] = 'some random text'
+ params['query'] = 'some AND (text AND NOT (random OR match OR word))'
+ @result = TextQuery.new(params['query']).eval(params['textstring'])
+
+ erb :test
+end
+
+post "/" do
+ @result = TextQuery.new(params['query']).eval(params['textstring'])
+ erb :test
+end
+
+__END__
+
+@@ test
+<p>Result: <strong><%= @result ? "Matched" : "No match" %></strong></p>
+
+<form action="/" method="post">
+ <label>Text</label><br />
+ <textarea name="textstring" cols="100" rows="6"><%= params['textstring'] %></textarea><br />
+
+ <label>Query</label><br />
+ <textarea name="query" cols="100" rows="2"><%= params['query'] %></textarea><br />
+
+ <br />
+ <input type="submit">
+</form>
+
+<pre style="background-color:#ccc; padding:2em;">
+Supported operators and rules:
+ * AND (spaces are implicit AND’s)
+ * OR
+ * NOT ('-' is an alias)
+ * 'quoted strings'
+
+Examples queries:
+ * 'to be' OR NOT 'to_be'
+ * -omitstring
+ * a AND b
+ * a AND (b AND NOT (c OR d))
+</pre>

0 comments on commit f9acccd

Please sign in to comment.