本文整理汇总了Java中org.apache.lucene.document.IntPoint类的典型用法代码示例。如果您正苦于以下问题:Java IntPoint类的具体用法?Java IntPoint怎么用?Java IntPoint使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IntPoint类属于org.apache.lucene.document包,在下文中一共展示了IntPoint类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testIntRangeQueryWithNoBounds
import org.apache.lucene.document.IntPoint; //导入依赖的package包/类
@Test
public void testIntRangeQueryWithNoBounds() {
JsonObject json = Json.createObjectBuilder()
.add("query", Json.createObjectBuilder()
.add("type", "RangeQuery")
.add("rangeType", "Int")
.add("field", "field")
.add("lowerTerm", JsonValue.NULL)
.add("upperTerm", JsonValue.NULL)
.add("includeLower", JsonValue.FALSE)
.add("includeUpper", JsonValue.TRUE))
.build();
QueryData q = new QueryData(new StringReader(json.toString()), queryConverter);
Query query = IntPoint.newRangeQuery("field", Integer.MIN_VALUE + 1, Integer.MAX_VALUE);
assertEquals(query, q.query);
}
示例2: termsQuery
import org.apache.lucene.document.IntPoint; //导入依赖的package包/类
@Override
Query termsQuery(String field, List<Object> values) {
int[] v = new int[values.size()];
int upTo = 0;
for (int i = 0; i < values.size(); i++) {
Object value = values.get(i);
if (!hasDecimalPart(value)) {
v[upTo++] = parse(value, true);
}
}
if (upTo == 0) {
return Queries.newMatchNoDocsQuery("All values have a decimal part");
}
if (upTo != v.length) {
v = Arrays.copyOf(v, upTo);
}
return IntPoint.newSetQuery(field, v);
}
示例3: stats
import org.apache.lucene.document.IntPoint; //导入依赖的package包/类
@Override
FieldStats.Long stats(IndexReader reader, String fieldName,
boolean isSearchable, boolean isAggregatable) throws IOException {
FieldInfo fi = org.apache.lucene.index.MultiFields.getMergedFieldInfos(reader).fieldInfo(fieldName);
if (fi == null) {
return null;
}
long size = PointValues.size(reader, fieldName);
if (size == 0) {
return new FieldStats.Long(reader.maxDoc(), 0, -1, -1, isSearchable, isAggregatable);
}
int docCount = PointValues.getDocCount(reader, fieldName);
byte[] min = PointValues.getMinPackedValue(reader, fieldName);
byte[] max = PointValues.getMaxPackedValue(reader, fieldName);
return new FieldStats.Long(reader.maxDoc(),docCount, -1L, size,
isSearchable, isAggregatable,
IntPoint.decodeDimension(min, 0), IntPoint.decodeDimension(max, 0));
}
示例4: addDocument
import org.apache.lucene.document.IntPoint; //导入依赖的package包/类
public static void addDocument(Lucene lucene, String identifier, Map<String, Integer> keys, Map<String, String> fields) throws Exception {
Document doc = new Document();
if (keys != null)
for (String keyField : keys.keySet())
doc.add(new NumericDocValuesField(keyField, keys.get(keyField)));
if (fields != null) {
for (String fieldname : fields.keySet())
if (fieldname.equals("intField"))
doc.add(new IntPoint(fieldname, Integer.parseInt(fields.get(fieldname))));
else {
doc.add(new StringField(fieldname, fields.get(fieldname), Store.NO));
doc.add(new SortedDocValuesField(fieldname, new BytesRef(fields.get(fieldname))));
doc.add(new FacetField("cat_" + fieldname, fields.get(fieldname)));
}
}
lucene.addDocument(identifier, doc);
lucene.maybeCommitAfterUpdate();
}
示例5: testIntRangeQuery
import org.apache.lucene.document.IntPoint; //导入依赖的package包/类
@Test
public void testIntRangeQuery() {
JsonObject json = Json.createObjectBuilder()
.add("query", Json.createObjectBuilder()
.add("type", "RangeQuery")
.add("rangeType", "Int")
.add("field", "field")
.add("lowerTerm", 1)
.add("upperTerm", 5)
.add("includeLower", JsonValue.FALSE)
.add("includeUpper", JsonValue.TRUE))
.build();
QueryData q = new QueryData(new StringReader(json.toString()), queryConverter);
Query query = IntPoint.newRangeQuery("field", 2, 5);
assertEquals(query, q.query);
}
示例6: termQuery
import org.apache.lucene.document.IntPoint; //导入依赖的package包/类
@Override
Query termQuery(String field, Object value) {
if (hasDecimalPart(value)) {
return Queries.newMatchNoDocsQuery("Value [" + value + "] has a decimal part");
}
int v = parse(value, true);
return IntPoint.newExactQuery(field, v);
}
示例7: rangeQuery
import org.apache.lucene.document.IntPoint; //导入依赖的package包/类
@Override
Query rangeQuery(String field, Object lowerTerm, Object upperTerm,
boolean includeLower, boolean includeUpper,
boolean hasDocValues) {
int l = Integer.MIN_VALUE;
int u = Integer.MAX_VALUE;
if (lowerTerm != null) {
l = parse(lowerTerm, true);
// if the lower bound is decimal:
// - if the bound is positive then we increment it:
// if lowerTerm=1.5 then the (inclusive) bound becomes 2
// - if the bound is negative then we leave it as is:
// if lowerTerm=-1.5 then the (inclusive) bound becomes -1 due to the call to longValue
boolean lowerTermHasDecimalPart = hasDecimalPart(lowerTerm);
if ((lowerTermHasDecimalPart == false && includeLower == false) ||
(lowerTermHasDecimalPart && signum(lowerTerm) > 0)) {
if (l == Integer.MAX_VALUE) {
return new MatchNoDocsQuery();
}
++l;
}
}
if (upperTerm != null) {
u = parse(upperTerm, true);
boolean upperTermHasDecimalPart = hasDecimalPart(upperTerm);
if ((upperTermHasDecimalPart == false && includeUpper == false) ||
(upperTermHasDecimalPart && signum(upperTerm) < 0)) {
if (u == Integer.MIN_VALUE) {
return new MatchNoDocsQuery();
}
--u;
}
}
Query query = IntPoint.newRangeQuery(field, l, u);
if (hasDocValues) {
Query dvQuery = SortedNumericDocValuesField.newRangeQuery(field, l, u);
query = new IndexOrDocValuesQuery(query, dvQuery);
}
return query;
}
示例8: createFields
import org.apache.lucene.document.IntPoint; //导入依赖的package包/类
@Override
public List<Field> createFields(String name, Number value,
boolean indexed, boolean docValued, boolean stored) {
List<Field> fields = new ArrayList<>();
if (indexed) {
fields.add(new IntPoint(name, value.intValue()));
}
if (docValued) {
fields.add(new SortedNumericDocValuesField(name, value.intValue()));
}
if (stored) {
fields.add(new StoredField(name, value.intValue()));
}
return fields;
}
示例9: testQueryFiltering
import org.apache.lucene.document.IntPoint; //导入依赖的package包/类
public void testQueryFiltering() throws IOException {
testCase(IntPoint.newRangeQuery("number", 0, 5), iw -> {
iw.addDocument(Arrays.asList(new IntPoint("number", 7), new SortedNumericDocValuesField("number", 7)));
iw.addDocument(Arrays.asList(new IntPoint("number", 1), new SortedNumericDocValuesField("number", 1)));
}, max -> {
assertEquals(1, max.getValue(), 0);
});
}
示例10: testQueryFiltersAll
import org.apache.lucene.document.IntPoint; //导入依赖的package包/类
public void testQueryFiltersAll() throws IOException {
testCase(IntPoint.newRangeQuery("number", -1, 0), iw -> {
iw.addDocument(Arrays.asList(new IntPoint("number", 7), new SortedNumericDocValuesField("number", 7)));
iw.addDocument(Arrays.asList(new IntPoint("number", 1), new SortedNumericDocValuesField("number", 1)));
}, max -> {
assertEquals(Double.NEGATIVE_INFINITY, max.getValue(), 0);
});
}
示例11: testQueryFiltering
import org.apache.lucene.document.IntPoint; //导入依赖的package包/类
public void testQueryFiltering() throws IOException {
testCase(IntPoint.newRangeQuery("number", 0, 3), iw -> {
iw.addDocument(Arrays.asList(new IntPoint("number", 7), new SortedNumericDocValuesField("number", 7)));
iw.addDocument(Arrays.asList(new IntPoint("number", 1), new SortedNumericDocValuesField("number", 2)));
iw.addDocument(Arrays.asList(new IntPoint("number", 3), new SortedNumericDocValuesField("number", 3)));
}, avg -> {
assertEquals(2.5, avg.getValue(), 0);
});
}
示例12: testQueryFiltersAll
import org.apache.lucene.document.IntPoint; //导入依赖的package包/类
public void testQueryFiltersAll() throws IOException {
testCase(IntPoint.newRangeQuery("number", -1, 0), iw -> {
iw.addDocument(Arrays.asList(new IntPoint("number", 7), new SortedNumericDocValuesField("number", 7)));
iw.addDocument(Arrays.asList(new IntPoint("number", 1), new SortedNumericDocValuesField("number", 2)));
iw.addDocument(Arrays.asList(new IntPoint("number", 3), new SortedNumericDocValuesField("number", 7)));
}, avg -> {
assertEquals(Double.NaN, avg.getValue(), 0);
});
}
示例13: testQueryFiltering
import org.apache.lucene.document.IntPoint; //导入依赖的package包/类
public void testQueryFiltering() throws IOException {
testCase(IntPoint.newRangeQuery("level", 0, 5), ValueType.STRING, iw -> {
iw.addDocument(Arrays.asList(new IntPoint("level", 0), new SortedDocValuesField(FIELD_NAME, new BytesRef("foo"))));
iw.addDocument(Arrays.asList(new IntPoint("level", 1), new SortedDocValuesField(FIELD_NAME, new BytesRef("bar"))));
iw.addDocument(Arrays.asList(new IntPoint("level", 3), new SortedDocValuesField(FIELD_NAME, new BytesRef("foo"))));
iw.addDocument(Arrays.asList(new IntPoint("level", 5), new SortedDocValuesField(FIELD_NAME, new BytesRef("baz"))));
iw.addDocument(Arrays.asList(new IntPoint("level", 7), new SortedDocValuesField(FIELD_NAME, new BytesRef("baz"))));
}, count -> assertEquals(4L, count.getValue()));
}
示例14: testToQueryNumericField
import org.apache.lucene.document.IntPoint; //导入依赖的package包/类
public void testToQueryNumericField() throws IOException {
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
Query parsedQuery = rangeQuery(INT_FIELD_NAME).from(23).to(54).includeLower(true).includeUpper(false).toQuery(createShardContext());
// since age is automatically registered in data, we encode it as numeric
assertThat(parsedQuery, instanceOf(IndexOrDocValuesQuery.class));
parsedQuery = ((IndexOrDocValuesQuery) parsedQuery).getIndexQuery();
assertThat(parsedQuery, instanceOf(PointRangeQuery.class));
assertEquals(IntPoint.newRangeQuery(INT_FIELD_NAME, 23, 53), parsedQuery);
}
示例15: testIntegerTermsQueryWithDecimalPart
import org.apache.lucene.document.IntPoint; //导入依赖的package包/类
public void testIntegerTermsQueryWithDecimalPart() {
MappedFieldType ft = new NumberFieldMapper.NumberFieldType(NumberType.INTEGER);
ft.setName("field");
ft.setIndexOptions(IndexOptions.DOCS);
assertEquals(IntPoint.newSetQuery("field", 1), ft.termsQuery(Arrays.asList(1, 2.1), null));
assertEquals(IntPoint.newSetQuery("field", 1), ft.termsQuery(Arrays.asList(1.0, 2.1), null));
assertTrue(ft.termsQuery(Arrays.asList(1.1, 2.1), null) instanceof MatchNoDocsQuery);
}