changeset 542:7170a0c414d5

better numeric term query
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 01 Jun 2015 21:48:57 -0600
parents fda38db30e65
children 9767da72545b
files lucene/src/luan/modules/lucene/Lucene.luan
diffstat 1 files changed, 15 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
diff -r fda38db30e65 -r 7170a0c414d5 lucene/src/luan/modules/lucene/Lucene.luan
--- a/lucene/src/luan/modules/lucene/Lucene.luan	Mon Jun 01 18:13:06 2015 -0600
+++ b/lucene/src/luan/modules/lucene/Lucene.luan	Mon Jun 01 21:48:57 2015 -0600
@@ -17,6 +17,8 @@
 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"
+local BytesRef = require "java:org.apache.lucene.util.BytesRef"
+local NumericUtils = require "java:org.apache.lucene.util.NumericUtils"
 local Sort = require "java:org.apache.lucene.search.Sort"
 local SortField = require "java:org.apache.lucene.search.SortField"
 
@@ -90,7 +92,19 @@
 			return TermQuery.new(Term.new(field,value))
 		end
 		if tp == "number" then
-			return queryTbl.range(field,value,value)
+			local br = BytesRef.new()
+			tp = number_type(value)
+			if tp == "integer" then
+				NumericUtils.intToPrefixCoded(value,0,br)
+			elseif tp == "long" then
+				NumericUtils.longToPrefixCoded(value,0,br)
+			elseif tp == "double" then
+				value = NumericUtils.doubleToSortableLong(value)
+				NumericUtils.longToPrefixCoded(value,0,br)
+			else
+				error("invalid term value type: "..tp)
+			end
+			return TermQuery.new(Term.new(field,br))
 		end
 		error("invalid term value type: "..tp)
 	end