Mercurial Hosting > luan
changeset 285:582e8db4cdb6
add lucene Web_search
git-svn-id: https://luan-java.googlecode.com/svn/trunk@286 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Tue, 02 Dec 2014 06:17:45 +0000 |
parents | 8870840251ea |
children | 91be4027b2a8 |
files | dist/jars/luan-core-trunk.jar dist/jars/luan-logging-trunk.jar dist/jars/luan-lucene-trunk.jar dist/jars/luan-mail-trunk.jar dist/jars/luan-web-trunk.jar lucene/src/luan/modules/lucene/LuceneSearcher.java lucene/src/luan/modules/lucene/Web_search.luan web/src/luan/modules/web/web_run.luan web/src/luan/modules/web/web_shell.luan |
diffstat | 9 files changed, 99 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
diff -r 8870840251ea -r 582e8db4cdb6 dist/jars/luan-core-trunk.jar Binary file dist/jars/luan-core-trunk.jar has changed
diff -r 8870840251ea -r 582e8db4cdb6 dist/jars/luan-logging-trunk.jar Binary file dist/jars/luan-logging-trunk.jar has changed
diff -r 8870840251ea -r 582e8db4cdb6 dist/jars/luan-lucene-trunk.jar Binary file dist/jars/luan-lucene-trunk.jar has changed
diff -r 8870840251ea -r 582e8db4cdb6 dist/jars/luan-mail-trunk.jar Binary file dist/jars/luan-mail-trunk.jar has changed
diff -r 8870840251ea -r 582e8db4cdb6 dist/jars/luan-web-trunk.jar Binary file dist/jars/luan-web-trunk.jar has changed
diff -r 8870840251ea -r 582e8db4cdb6 lucene/src/luan/modules/lucene/LuceneSearcher.java --- a/lucene/src/luan/modules/lucene/LuceneSearcher.java Tue Dec 02 03:55:33 2014 +0000 +++ b/lucene/src/luan/modules/lucene/LuceneSearcher.java Tue Dec 02 06:17:45 2014 +0000 @@ -19,6 +19,7 @@ import org.apache.lucene.search.Collector; import org.apache.lucene.search.TotalHitCountCollector; import org.apache.lucene.search.Scorer; +import org.apache.lucene.search.MatchAllDocsQuery; import org.apache.lucene.index.AtomicReaderContext; import luan.Luan; import luan.LuanState; @@ -179,9 +180,14 @@ } public Object[] search( final LuanState luan, LuanTable queryTbl, Object nObj, LuanTable sortTbl ) throws LuanException, IOException { - Query query = query(queryTbl); - if( query == null ) - throw luan.exception("invalid query"); + Query query; + if( queryTbl == null ) { + query = new MatchAllDocsQuery(); + } else { + query = query(queryTbl); + if( query == null ) + throw luan.exception("invalid query"); + } if( nObj instanceof LuanFunction ) { final LuanFunction fn = (LuanFunction)nObj; Collector col = new MyCollector() {
diff -r 8870840251ea -r 582e8db4cdb6 lucene/src/luan/modules/lucene/Web_search.luan --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lucene/src/luan/modules/lucene/Web_search.luan Tue Dec 02 06:17:45 2014 +0000 @@ -0,0 +1,88 @@ +import "luan:Io" +import "luan:web/Http" +import "luan:String" + + +local function form() %> +<html> +<body> +<form method="post"> +<p>Query: <input name="query" size="60" /></p> +<p>Rows: <input name="rows" value="20" /></p> +<p>Sort: <input name="sort" size="60" /></p> +<p><input type="submit" /></p> +</form> +</body> +</html> +<% end + + +local function result(query,sort,headers,table) %> +<html> +<body> +<p>Query: <b><%=repr(query)%></b></p> +<p>Sort: <b><%=repr(sort)%></b></p> +<table border="1"> +<tr><th></th> +<% +for _, header in ipairs(headers) do + %><th><%=header%></th><% +end +%> +</tr> +<% +for i, row in ipairs(table) do + %> + <tr><td><%=i%></td> + <% + for col in range(1,#headers) do + %><td><%= row[col] or "" %></td><% + end + %></tr><% +end +%> +</body> +</html> +<% end + + +local function index_of(tbl,val) + for i, v in ipairs(tbl) do + if v == val then + return i + end + end + local n = #tbl + 1 + tbl[n] = val + return n +end + + +function of(index) + + return { service = function() + Io.stdout = Http.response.text_writer() + local query_string = Http.request.parameters.query + if query_string == nil then + form() + return + end + local query = load(query_string,"<query>",{},true)() + local rows = to_number(Http.request.parameters.rows) + local sort = load(Http.request.parameters.sort,"<sort>",{},true)() + index.Searcher( function(searcher) + local results, length, total_hits = searcher.search(query,rows,sort) + local headers = {} + local table = {} + for doc in results do + local row = {} + for field, value in pairs(doc) do + row[index_of(headers,field)] = value + end + table[#table+1] = row + end + result(query,sort,headers,table) + end ) + end } + +end
diff -r 8870840251ea -r 582e8db4cdb6 web/src/luan/modules/web/web_run.luan --- a/web/src/luan/modules/web/web_run.luan Tue Dec 02 03:55:33 2014 +0000 +++ b/web/src/luan/modules/web/web_run.luan Tue Dec 02 06:17:45 2014 +0000 @@ -21,7 +21,7 @@ local function form() %> <html> <body> -<form action="run" method="post"> +<form method="post"> <input type="hidden" name="content_type" value="text/plain" /> <input type="submit" value="Execute Luan code below"> <br />
diff -r 8870840251ea -r 582e8db4cdb6 web/src/luan/modules/web/web_shell.luan --- a/web/src/luan/modules/web/web_shell.luan Tue Dec 02 03:55:33 2014 +0000 +++ b/web/src/luan/modules/web/web_shell.luan Tue Dec 02 06:17:45 2014 +0000 @@ -22,7 +22,7 @@ if cmd ~= nil then print( "% "..cmd ) try - local line = load(cmd,"<web_shell>",env,true); + local line = load(cmd,"<web_shell>",env,true) Debug.print_if_something( line() ) catch e do Io.print_to(Io.stderr,e)