Mercurial Hosting > luan
changeset 536:3058870cbe83
add Luan.number_type and Lucene.query.range
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 01 Jun 2015 00:27:45 -0600 |
parents | 289908469e02 |
children | 5fed3de0aac7 |
files | core/src/luan/modules/BasicLuan.java core/src/luan/modules/Luan.luan lucene/src/luan/modules/lucene/Lucene.luan |
diffstat | 3 files changed, 44 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/core/src/luan/modules/BasicLuan.java Sun May 31 00:00:17 2015 -0600 +++ b/core/src/luan/modules/BasicLuan.java Mon Jun 01 00:27:45 2015 -0600 @@ -225,4 +225,9 @@ } } + public static String number_type(LuanState luan,Number v) throws LuanException { + Utils.checkNotNull(luan,v); + return v.getClass().getSimpleName().toLowerCase(); + } + }
--- a/core/src/luan/modules/Luan.luan Sun May 31 00:00:17 2015 -0600 +++ b/core/src/luan/modules/Luan.luan Mon Jun 01 00:27:45 2015 -0600 @@ -15,6 +15,7 @@ M.load = BasicLuan.load M.load_file = BasicLuan.load_file M.new_error = BasicLuan.new_error +M.number_type = BasicLuan.number_type M.pairs = BasicLuan.pairs M.pcall = BasicLuan.pcall M.range = BasicLuan.range
--- a/lucene/src/luan/modules/lucene/Lucene.luan Sun May 31 00:00:17 2015 -0600 +++ b/lucene/src/luan/modules/lucene/Lucene.luan Mon Jun 01 00:27:45 2015 -0600 @@ -3,11 +3,14 @@ local pairs = Luan.pairs local ipairs = Luan.ipairs local type = Luan.type +local number_type = Luan.number_type local error = Luan.error local Table = require "luan:Table" local LuceneIndex = require "java:luan.modules.lucene.LuceneIndex" local Term = require "java:org.apache.lucene.index.Term" local TermQuery = require "java:org.apache.lucene.search.TermQuery" +local TermRangeQuery = require "java:org.apache.lucene.search.TermRangeQuery" +local NumericRangeQuery = require "java:org.apache.lucene.search.NumericRangeQuery" local MatchAllDocsQuery = require "java:org.apache.lucene.search.MatchAllDocsQuery" local BooleanQuery = require "java:org.apache.lucene.search.BooleanQuery" local BooleanClause = require "java:org.apache.lucene.search.BooleanClause" @@ -77,9 +80,42 @@ field and value or error "missing term" iter()==nil or error "only one term allowed" field = index.map_field_name(field) - return TermQuery.new(Term.new(field,value)) + local tp = type(value) + if tp == "string" then + return TermQuery.new(Term.new(field,value)) + end + if tp == "number" then + return queryTbl.range(field,value,value) + end + error("invalid term value type: "..tp) end - + + function queryTbl.range(field,min,max,include_min,include_max) + if include_min == nil then include_min = true end + if include_max == nil then include_max = true end + field = index.map_field_name(field) + local tp = type(min) + tp == type(max) or error "min and max types don't match" + if tp == "string" then + return TermRangeQuery.newStringRange(field,min,max,include_min,include_max) + end + if tp == "number" then + tp = number_type(min) + tp == number_type(max) or error "min and max number types don't match" + if tp == "integer" then + return NumericRangeQuery.newIntRange(field,min,max,include_min,include_max) + end + if tp == "long" then + return NumericRangeQuery.newLongRange(field,min,max,include_min,include_max) + end + if tp == "double" then + return NumericRangeQuery.newDoubleRange(field,min,max,include_min,include_max) + end + error("invalid term value type: "..tp) + end + error("invalid term value type: "..tp) + end + function queryTbl.boolean(t) local boolean_query = BooleanQuery.new() for query, occur_string in pairs(t) do