comparison lucene/src/luan/modules/lucene/Web_search.luan @ 325:78a6a71afbfd

use SimplyHTML git-svn-id: https://luan-java.googlecode.com/svn/trunk@326 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Tue, 03 Mar 2015 06:00:59 +0000
parents 7f7708e8fdd4
children fb18724521d2
comparison
equal deleted inserted replaced
324:b24a35612947 325:78a6a71afbfd
5 local ipairs = Luan.ipairs 5 local ipairs = Luan.ipairs
6 local range = Luan.range 6 local range = Luan.range
7 local Io = require "luan:Io" 7 local Io = require "luan:Io"
8 local Http = require "luan:web/Http" 8 local Http = require "luan:web/Http"
9 local String = require "luan:String" 9 local String = require "luan:String"
10 local Html = require "luan:Html"
10 11
11 12
12 local function basic_style() %> 13 local function form()
13 body {font-family:'Arial',sans-serif;font-size:16px;padding:1em 2em} 14 Html.simple_html_page{
14 input {padding:.5em;border-radius:10px;border:1px solid #ccc;font-size:16px} 15 head = function() %>
15 input.btn {background:#3B619D;color:#FFF;padding:.5em 2em;font-size:20px} 16 <title>Lucene Query</title>
16 h1 {font-weight:bold;font-size: 20px} 17 <% end;
17 p {margin:1em 0 .2em} 18 body = function() %>
18 span.label {min-width:100px;display:inline-block;text-align:right} 19 <div container>
19 div.tip{color:#888;font-size:80%} 20 <h3 margin-top="1.5em">Lucene Query</h3>
20 table.results {margin-top:2em;border-collapse:collapse;font-size:90%} 21 <form horizontal name="form0" method="post" margin-top="2em">
21 table.results th {background:#eee} 22 <div row>
22 table.results th,table.results td {border-left:1px solid #bbb;padding:.4em} 23 <div colspan=2 align="right">
23 table.results tr:nth-child(odd) td {background:#f8f8f8} 24 <label>Query:</label>
24 <% end 25 </div>
25 26 <div colspan=10>
26 local function form() %> 27 <input name="query" size="80" value="Query.all_docs" autofocus />
27 <!DOCTYPE html> 28 <div textcolor="#888">Query examples: <i>Query.term{ type = 'user' }</i> or <i>"type:user AND name:Joe"</i></div>
28 <html lang="en"> 29 </div>
29 <head> 30 </div>
30 <title>Lucene Query</title> 31 <div row margin-top="1em">
31 <style><% basic_style() %></style> 32 <div colspan=2 align="right">
32 </head> 33 <label>Max Rows:</label>
33 <body> 34 </div>
34 <h1>Lucene Query</h1> 35 <div colspan=10>
35 <form name="form0" method="post"> 36 <input name="rows" value="100" size="3" maxlength="5" /></p>
36 <p> 37 </div>
37 <span class="label">Query:</span> <input name="query" size="60" value="Query.all_docs" /> 38 </div>
38 <div class="tip"><span class="label"></span> Query examples: <i>Query.term{ type = 'user' }</i> or <i>"type:user AND name:Joe"</i></div> 39 <div row margin-top="1em">
39 </p> 40 <div colspan=2 align="right">
40 <p><span class="label">Max Rows:</span> <input name="rows" value="100" maxlength="5" onkeypress="return event.charCode >= 48 && event.charCode <= 57" style="width:3em"/></p> 41 <label>Sort:</label>
41 <p> 42 </div>
42 <span class="label">Sort:</span> <input name="sort" size="60" /> 43 <div colspan=10>
43 <div class="tip"><span class="label"></span> Sort examples: Query.sort{{ field = 'id', type='int' }}</div> 44 <input name="sort" size="60" />
44 </p> 45 <div textcolor="#888">Sort examples: Query.sort{{ field = 'id', type='int' }}</div>
45 <p><input type="submit" class="btn"/></p> 46 </div>
46 </form> 47 </div>
47 <script>document.form0.query.focus();</script> 48 <div row margin-top="1em">
48 </body> 49 <div colspan=2></div>
49 </html> 50 <div colspan=10>
50 <% end 51 <input type="submit" textcolor="white" bgcolor="#337ab7" large/>
52 </div>
53 </div>
54 </form>
55 </div>
56 <% end;
57 }
58 end
51 59
52 60
53 local function result(query,sort,headers,table) %> 61 local function result(query,sort,headers,table)
54 <!DOCTYPE html> 62 Html.simple_html_page{
55 <html lang="en"> 63 body = function() %>
56 <head> 64 <div container>
57 <style><% basic_style() %></style> 65 <h3 margin-top="1.5em">Lucene Query Results</h3>
58 </head> 66 <div row>
59 <body> 67 <div colspan=2 align="right">
60 <h1>Lucene Query Results</h1> 68 <label>Query:</label>
61 <p><span class="label">Query:</span> <b><%=query%></b></p> 69 </div>
62 <p><span class="label">Sort:</span> <b><%=sort%></b></p> 70 <div colspan=10>
63 <table class="results"> 71 <b><%=query%></b></p>
64 <tr> 72 </div>
65 <th></th> 73 </div>
66 <% for _, header in ipairs(headers) do %> 74 <div row>
67 <th><%=header%></th> 75 <div colspan=2 align="right">
68 <% end %> 76 <label>Sort:</label>
69 </tr> 77 </div>
70 <% for i, row in ipairs(table) do %> 78 <div colspan=10>
79 <b><%=sort%></b></p>
80 </div>
81 </div>
82 <table border condensed margin-top="1.5em">
71 <tr> 83 <tr>
72 <td><%=i%></td> 84 <th></th>
73 <% for col in range(1, #headers) do %> 85 <% for _, header in ipairs(headers) do %>
74 <td><%= row[col] or "" %></td> 86 <th><%=header%></th>
75 <% end %> 87 <% end %>
76 </tr> 88 </tr>
77 <% end %> 89 <% for i, row in ipairs(table) do %>
78 </table> 90 <tr>
79 </body> 91 <td><%=i%></td>
80 </html> 92 <% for col in range(1, #headers) do %>
81 <% end 93 <td><%= row[col] or "" %></td>
94 <% end %>
95 </tr>
96 <% end %>
97 </table>
98 </div>
99 <% end;
100 }
101 end
82 102
83 103
84 local function index_of(tbl,val) 104 local function index_of(tbl,val)
85 for i, v in ipairs(tbl) do 105 for i, v in ipairs(tbl) do
86 if v == val then 106 if v == val then