Mercurial Hosting > luan
comparison src/goodjava/lucene/api/LuceneUtils.java @ 1771:c62324841dfb
improve NumberFieldParser and add key map lucene query
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 25 Jun 2023 15:05:09 -0600 |
parents | e5d48b85351c |
children |
comparison
equal
deleted
inserted
replaced
1770:6c01d54edcac | 1771:c62324841dfb |
---|---|
6 import java.util.ArrayList; | 6 import java.util.ArrayList; |
7 import org.apache.lucene.document.Document; | 7 import org.apache.lucene.document.Document; |
8 import org.apache.lucene.index.IndexableField; | 8 import org.apache.lucene.index.IndexableField; |
9 import org.apache.lucene.index.Term; | 9 import org.apache.lucene.index.Term; |
10 import org.apache.lucene.util.BytesRef; | 10 import org.apache.lucene.util.BytesRef; |
11 import org.apache.lucene.util.NumericUtils; | 11 import goodjava.lucene.queryparser.NumberFieldParser; |
12 | 12 |
13 | 13 |
14 public final class LuceneUtils { | 14 public final class LuceneUtils { |
15 private LuceneUtils() {} // never | 15 private LuceneUtils() {} // never |
16 | 16 |
54 | 54 |
55 public static Term term(String name,Object value) { | 55 public static Term term(String name,Object value) { |
56 if( value instanceof String ) { | 56 if( value instanceof String ) { |
57 return new Term(name,(String)value); | 57 return new Term(name,(String)value); |
58 } else if( value instanceof Long ) { | 58 } else if( value instanceof Long ) { |
59 BytesRef br = new BytesRef(); | 59 return NumberFieldParser.term(name,(Long)value); |
60 NumericUtils.longToPrefixCoded((Long)value,0,br); | |
61 return new Term(name,br); | |
62 } else if( value instanceof Integer ) { | 60 } else if( value instanceof Integer ) { |
63 BytesRef br = new BytesRef(); | 61 return NumberFieldParser.term(name,(Integer)value); |
64 NumericUtils.intToPrefixCoded((Integer)value,0,br); | |
65 return new Term(name,br); | |
66 } else | 62 } else |
67 throw new RuntimeException("invalid value type "+value.getClass()+"' for term '"+name+"'"); | 63 throw new RuntimeException("invalid value type "+value.getClass()+"' for term '"+name+"'"); |
68 } | 64 } |
69 | 65 |
70 } | 66 } |