本文整理汇总了Java中org.apache.lucene.util.NumericUtils.longToPrefixCodedBytes方法的典型用法代码示例。如果您正苦于以下问题:Java NumericUtils.longToPrefixCodedBytes方法的具体用法?Java NumericUtils.longToPrefixCodedBytes怎么用?Java NumericUtils.longToPrefixCodedBytes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.lucene.util.NumericUtils
的用法示例。
在下文中一共展示了NumericUtils.longToPrefixCodedBytes方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readableToIndexed
import org.apache.lucene.util.NumericUtils; //导入方法依赖的package包/类
@Override
public void readableToIndexed(CharSequence val, BytesRef result) {
String s = val.toString();
switch (type) {
case INTEGER:
NumericUtils.intToPrefixCodedBytes(Integer.parseInt(s), 0, result);
break;
case FLOAT:
NumericUtils.intToPrefixCodedBytes(NumericUtils.floatToSortableInt(Float.parseFloat(s)), 0, result);
break;
case LONG:
NumericUtils.longToPrefixCodedBytes(Long.parseLong(s), 0, result);
break;
case DOUBLE:
NumericUtils.longToPrefixCodedBytes(NumericUtils.doubleToSortableLong(Double.parseDouble(s)), 0, result);
break;
case DATE:
NumericUtils.longToPrefixCodedBytes(dateField.parseMath(null, s).getTime(), 0, result);
break;
default:
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Unknown type for trie field: " + type);
}
}
示例2: readableToIndexed
import org.apache.lucene.util.NumericUtils; //导入方法依赖的package包/类
@Override
public void readableToIndexed(CharSequence val, BytesRef result) {
String s = val.toString();
BytesRefBuilder b = new BytesRefBuilder();
try {
switch (type) {
case INTEGER:
NumericUtils.intToPrefixCodedBytes(Integer.parseInt(s), 0, b);
break;
case FLOAT:
NumericUtils.intToPrefixCodedBytes(NumericUtils.floatToSortableInt(Float.parseFloat(s)), 0, b);
break;
case LONG:
NumericUtils.longToPrefixCodedBytes(Long.parseLong(s), 0, b);
break;
case DOUBLE:
NumericUtils.longToPrefixCodedBytes(NumericUtils.doubleToSortableLong(Double.parseDouble(s)), 0, b);
break;
case DATE:
NumericUtils.longToPrefixCodedBytes(dateField.parseMath(null, s).getTime(), 0, b);
break;
default:
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Unknown type for trie field: " + type);
}
result.copyBytes(b.get());
} catch (NumberFormatException nfe) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
"Invalid Number: " + val);
}
}
示例3: readableToIndexed
import org.apache.lucene.util.NumericUtils; //导入方法依赖的package包/类
@Override
public void readableToIndexed(CharSequence val, BytesRef result) {
String s = val.toString();
try {
switch (type) {
case INTEGER:
NumericUtils.intToPrefixCodedBytes(Integer.parseInt(s), 0, result);
break;
case FLOAT:
NumericUtils.intToPrefixCodedBytes(NumericUtils.floatToSortableInt(Float.parseFloat(s)), 0, result);
break;
case LONG:
NumericUtils.longToPrefixCodedBytes(Long.parseLong(s), 0, result);
break;
case DOUBLE:
NumericUtils.longToPrefixCodedBytes(NumericUtils.doubleToSortableLong(Double.parseDouble(s)), 0, result);
break;
case DATE:
NumericUtils.longToPrefixCodedBytes(dateField.parseMath(null, s).getTime(), 0, result);
break;
default:
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Unknown type for trie field: " + type);
}
} catch (NumberFormatException nfe) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
"Invalid Number: " + val);
}
}
示例4: toIndexForm
import org.apache.lucene.util.NumericUtils; //导入方法依赖的package包/类
@Override
public void toIndexForm(Number number, BytesRefBuilder bytes) {
NumericUtils.longToPrefixCodedBytes(number.longValue(), 0, bytes);
}
示例5: makeNumberTermQuery
import org.apache.lucene.util.NumericUtils; //导入方法依赖的package包/类
private Query makeNumberTermQuery(String field, double number) {
BytesRefBuilder bytes = new BytesRefBuilder();
NumericUtils.longToPrefixCodedBytes(NumericUtils.doubleToSortableLong(number), 0, bytes);
return new TermQuery(new Term(field, bytes.get()));
}
示例6: testRandomTrieAndClassicRangeQuery
import org.apache.lucene.util.NumericUtils; //导入方法依赖的package包/类
private void testRandomTrieAndClassicRangeQuery(int precisionStep) throws Exception {
String field="field"+precisionStep;
int totalTermCountT=0,totalTermCountC=0,termCountT,termCountC;
int num = TestUtil.nextInt(random(), 10, 20);
for (int i = 0; i < num; i++) {
long lower=(long)(random().nextDouble()*noDocs*distance)+startOffset;
long upper=(long)(random().nextDouble()*noDocs*distance)+startOffset;
if (lower>upper) {
long a=lower; lower=upper; upper=a;
}
final BytesRef lowerBytes, upperBytes;
BytesRefBuilder b = new BytesRefBuilder();
NumericUtils.longToPrefixCodedBytes(lower, 0, b);
lowerBytes = b.toBytesRef();
NumericUtils.longToPrefixCodedBytes(upper, 0, b);
upperBytes = b.toBytesRef();
// test inclusive range
NumericRangeQuery<Long> tq=NumericRangeQuery.newLongRange(field, precisionStep, lower, upper, true, true);
TermRangeQuery cq=new TermRangeQuery(field, lowerBytes, upperBytes, true, true);
TopDocs tTopDocs = searcher.search(tq, 1);
TopDocs cTopDocs = searcher.search(cq, 1);
assertEquals("Returned count for NumericRangeQuery and TermRangeQuery must be equal", cTopDocs.totalHits, tTopDocs.totalHits );
totalTermCountT += termCountT = countTerms(tq);
totalTermCountC += termCountC = countTerms(cq);
checkTermCounts(precisionStep, termCountT, termCountC);
// test exclusive range
tq=NumericRangeQuery.newLongRange(field, precisionStep, lower, upper, false, false);
cq=new TermRangeQuery(field, lowerBytes, upperBytes, false, false);
tTopDocs = searcher.search(tq, 1);
cTopDocs = searcher.search(cq, 1);
assertEquals("Returned count for NumericRangeQuery and TermRangeQuery must be equal", cTopDocs.totalHits, tTopDocs.totalHits );
totalTermCountT += termCountT = countTerms(tq);
totalTermCountC += termCountC = countTerms(cq);
checkTermCounts(precisionStep, termCountT, termCountC);
// test left exclusive range
tq=NumericRangeQuery.newLongRange(field, precisionStep, lower, upper, false, true);
cq=new TermRangeQuery(field, lowerBytes, upperBytes, false, true);
tTopDocs = searcher.search(tq, 1);
cTopDocs = searcher.search(cq, 1);
assertEquals("Returned count for NumericRangeQuery and TermRangeQuery must be equal", cTopDocs.totalHits, tTopDocs.totalHits );
totalTermCountT += termCountT = countTerms(tq);
totalTermCountC += termCountC = countTerms(cq);
checkTermCounts(precisionStep, termCountT, termCountC);
// test right exclusive range
tq=NumericRangeQuery.newLongRange(field, precisionStep, lower, upper, true, false);
cq=new TermRangeQuery(field, lowerBytes, upperBytes, true, false);
tTopDocs = searcher.search(tq, 1);
cTopDocs = searcher.search(cq, 1);
assertEquals("Returned count for NumericRangeQuery and TermRangeQuery must be equal", cTopDocs.totalHits, tTopDocs.totalHits );
totalTermCountT += termCountT = countTerms(tq);
totalTermCountC += termCountC = countTerms(cq);
checkTermCounts(precisionStep, termCountT, termCountC);
}
checkTermCounts(precisionStep, totalTermCountT, totalTermCountC);
if (VERBOSE && precisionStep != Integer.MAX_VALUE) {
System.out.println("Average number of terms during random search on '" + field + "':");
System.out.println(" Numeric query: " + (((double)totalTermCountT)/(num * 4)));
System.out.println(" Classical query: " + (((double)totalTermCountC)/(num * 4)));
}
}
示例7: testRandomTrieAndClassicRangeQuery
import org.apache.lucene.util.NumericUtils; //导入方法依赖的package包/类
private void testRandomTrieAndClassicRangeQuery(int precisionStep) throws Exception {
String field="field"+precisionStep;
int totalTermCountT=0,totalTermCountC=0,termCountT,termCountC;
int num = _TestUtil.nextInt(random(), 10, 20);
for (int i = 0; i < num; i++) {
long lower=(long)(random().nextDouble()*noDocs*distance)+startOffset;
long upper=(long)(random().nextDouble()*noDocs*distance)+startOffset;
if (lower>upper) {
long a=lower; lower=upper; upper=a;
}
final BytesRef lowerBytes = new BytesRef(NumericUtils.BUF_SIZE_LONG), upperBytes = new BytesRef(NumericUtils.BUF_SIZE_LONG);
NumericUtils.longToPrefixCodedBytes(lower, 0, lowerBytes);
NumericUtils.longToPrefixCodedBytes(upper, 0, upperBytes);
// test inclusive range
NumericRangeQuery<Long> tq=NumericRangeQuery.newLongRange(field, precisionStep, lower, upper, true, true);
TermRangeQuery cq=new TermRangeQuery(field, lowerBytes, upperBytes, true, true);
TopDocs tTopDocs = searcher.search(tq, 1);
TopDocs cTopDocs = searcher.search(cq, 1);
assertEquals("Returned count for NumericRangeQuery and TermRangeQuery must be equal", cTopDocs.totalHits, tTopDocs.totalHits );
totalTermCountT += termCountT = countTerms(tq);
totalTermCountC += termCountC = countTerms(cq);
checkTermCounts(precisionStep, termCountT, termCountC);
// test exclusive range
tq=NumericRangeQuery.newLongRange(field, precisionStep, lower, upper, false, false);
cq=new TermRangeQuery(field, lowerBytes, upperBytes, false, false);
tTopDocs = searcher.search(tq, 1);
cTopDocs = searcher.search(cq, 1);
assertEquals("Returned count for NumericRangeQuery and TermRangeQuery must be equal", cTopDocs.totalHits, tTopDocs.totalHits );
totalTermCountT += termCountT = countTerms(tq);
totalTermCountC += termCountC = countTerms(cq);
checkTermCounts(precisionStep, termCountT, termCountC);
// test left exclusive range
tq=NumericRangeQuery.newLongRange(field, precisionStep, lower, upper, false, true);
cq=new TermRangeQuery(field, lowerBytes, upperBytes, false, true);
tTopDocs = searcher.search(tq, 1);
cTopDocs = searcher.search(cq, 1);
assertEquals("Returned count for NumericRangeQuery and TermRangeQuery must be equal", cTopDocs.totalHits, tTopDocs.totalHits );
totalTermCountT += termCountT = countTerms(tq);
totalTermCountC += termCountC = countTerms(cq);
checkTermCounts(precisionStep, termCountT, termCountC);
// test right exclusive range
tq=NumericRangeQuery.newLongRange(field, precisionStep, lower, upper, true, false);
cq=new TermRangeQuery(field, lowerBytes, upperBytes, true, false);
tTopDocs = searcher.search(tq, 1);
cTopDocs = searcher.search(cq, 1);
assertEquals("Returned count for NumericRangeQuery and TermRangeQuery must be equal", cTopDocs.totalHits, tTopDocs.totalHits );
totalTermCountT += termCountT = countTerms(tq);
totalTermCountC += termCountC = countTerms(cq);
checkTermCounts(precisionStep, termCountT, termCountC);
}
checkTermCounts(precisionStep, totalTermCountT, totalTermCountC);
if (VERBOSE && precisionStep != Integer.MAX_VALUE) {
System.out.println("Average number of terms during random search on '" + field + "':");
System.out.println(" Numeric query: " + (((double)totalTermCountT)/(num * 4)));
System.out.println(" Classical query: " + (((double)totalTermCountC)/(num * 4)));
}
}