Java 类org.apache.lucene.document.DoublePoint 实例源码

项目:elasticsearch_my    文件:NumberFieldMapper.java   
@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 DoublePoint(name, value.doubleValue()));
    }
    if (docValued) {
        fields.add(new SortedNumericDocValuesField(name,
            NumericUtils.doubleToSortableLong(value.doubleValue())));
    }
    if (stored) {
        fields.add(new StoredField(name, value.doubleValue()));
    }
    return fields;
}
项目:elasticsearch_my    文件:NumberFieldMapper.java   
@Override
FieldStats.Double 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.Double(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.Double(reader.maxDoc(),docCount, -1L, size,
        isSearchable, isAggregatable,
        DoublePoint.decodeDimension(min, 0), DoublePoint.decodeDimension(max, 0));
}
项目:meresco-lucene    文件:JsonQueryConverterTest.java   
@Test
public void testDoubleRangeQuery() {
    JsonObject json = Json.createObjectBuilder()
            .add("query", Json.createObjectBuilder()
                .add("type", "RangeQuery")
                .add("rangeType", "Double")
                .add("field", "field")
                .add("lowerTerm", 1.0)
                .add("upperTerm", 5.0)
                .add("includeLower", JsonValue.FALSE)
                .add("includeUpper", JsonValue.TRUE))
            .build();
    QueryData q = new QueryData(new StringReader(json.toString()), queryConverter);
    Query query = DoublePoint.newRangeQuery("field", Math.nextUp(1.0), 5.0);
    assertEquals(query, q.query);
}
项目:meresco-lucene    文件:JsonQueryConverterTest.java   
@Test
public void testDoubleRangeQueryWithNoBounds() {
    JsonObject json = Json.createObjectBuilder()
            .add("query", Json.createObjectBuilder()
                .add("type", "RangeQuery")
                .add("rangeType", "Double")
                .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 = DoublePoint.newRangeQuery("field", Math.nextUp(Double.NEGATIVE_INFINITY), Double.POSITIVE_INFINITY);
    assertEquals(query, q.query);
}
项目:elasticsearch_my    文件:NumberFieldMapper.java   
@Override
Query termsQuery(String field, List<Object> values) {
    double[] v = new double[values.size()];
    for (int i = 0; i < values.size(); ++i) {
        v[i] = parse(values.get(i), false);
    }
    return DoublePoint.newSetQuery(field, v);
}
项目:elasticsearch_my    文件:NumberFieldMapper.java   
@Override
Query rangeQuery(String field, Object lowerTerm, Object upperTerm,
                 boolean includeLower, boolean includeUpper,
                 boolean hasDocValues) {
    double l = Double.NEGATIVE_INFINITY;
    double u = Double.POSITIVE_INFINITY;
    if (lowerTerm != null) {
        l = parse(lowerTerm, false);
        if (includeLower == false) {
            l = DoublePoint.nextUp(l);
        }
    }
    if (upperTerm != null) {
        u = parse(upperTerm, false);
        if (includeUpper == false) {
            u = DoublePoint.nextDown(u);
        }
    }
    Query query = DoublePoint.newRangeQuery(field, l, u);
    if (hasDocValues) {
        Query dvQuery = SortedNumericDocValuesField.newRangeQuery(field,
                NumericUtils.doubleToSortableLong(l),
                NumericUtils.doubleToSortableLong(u));
        query = new IndexOrDocValuesQuery(query, dvQuery);
    }
    return query;
}
项目:elasticsearch_my    文件:ScaledFloatFieldTypeTests.java   
public void testRangeQuery() throws IOException {
    // make sure the accuracy loss of scaled floats only occurs at index time
    // this test checks that searching scaled floats yields the same results as
    // searching doubles that are rounded to the closest half float
    ScaledFloatFieldMapper.ScaledFloatFieldType ft = new ScaledFloatFieldMapper.ScaledFloatFieldType();
    ft.setName("scaled_float");
    ft.setScalingFactor(0.1 + randomDouble() * 100);
    Directory dir = newDirectory();
    IndexWriter w = new IndexWriter(dir, new IndexWriterConfig(null));
    final int numDocs = 1000;
    for (int i = 0; i < numDocs; ++i) {
        Document doc = new Document();
        double value = (randomDouble() * 2 - 1) * 10000;
        long scaledValue = Math.round(value * ft.getScalingFactor());
        double rounded = scaledValue / ft.getScalingFactor();
        doc.add(new LongPoint("scaled_float", scaledValue));
        doc.add(new DoublePoint("double", rounded));
        w.addDocument(doc);
    }
    final DirectoryReader reader = DirectoryReader.open(w);
    w.close();
    IndexSearcher searcher = newSearcher(reader);
    final int numQueries = 1000;
    for (int i = 0; i < numQueries; ++i) {
        Double l = randomBoolean() ? null : (randomDouble() * 2 - 1) * 10000;
        Double u = randomBoolean() ? null : (randomDouble() * 2 - 1) * 10000;
        boolean includeLower = randomBoolean();
        boolean includeUpper = randomBoolean();
        Query doubleQ = NumberFieldMapper.NumberType.DOUBLE.rangeQuery("double", l, u, includeLower, includeUpper, false);
        Query scaledFloatQ = ft.rangeQuery(l, u, includeLower, includeUpper, null);
        assertEquals(searcher.count(doubleQ), searcher.count(scaledFloatQ));
    }
    IOUtils.close(reader, dir);
}
项目:meresco-lucene    文件:JsonQueryConverter.java   
private Query createRangeQuery(JsonObject query) {
    String field = query.getString("field");
    boolean includeLower = query.getBoolean("includeLower");
    boolean includeUpper = query.getBoolean("includeUpper");
    boolean lower = query.get("lowerTerm") != JsonValue.NULL;
    boolean upper = query.get("upperTerm") != JsonValue.NULL;
    switch (query.getString("rangeType")) {
        case "String":
            return TermRangeQuery.newStringRange(field, lower ? query.getString("lowerTerm") : null, upper ? query.getString("upperTerm") : null, includeLower, includeUpper);
        case "Int":
            Integer iLowerValue = lower ? query.getInt("lowerTerm") : Integer.MIN_VALUE;
            Integer iUpperValue = upper ? query.getInt("upperTerm") : Integer.MAX_VALUE;
            if (!includeLower && iLowerValue != null)
                iLowerValue += 1;
            if (!includeUpper && iUpperValue != null)
                iUpperValue -= 1;
            return IntPoint.newRangeQuery(field, iLowerValue, iUpperValue);
        case "Long":
            Long lLowerValue = lower ? query.getJsonNumber("lowerTerm").longValue() : Long.MIN_VALUE;
            Long lUpperValue = upper ? query.getJsonNumber("upperTerm").longValue() : Long.MAX_VALUE;
            if (!includeLower && lLowerValue != null)
                lLowerValue += 1;
            if (!includeUpper && lUpperValue != null)
                lUpperValue -= 1;
            return LongPoint.newRangeQuery(field, lLowerValue, lUpperValue);
        case "Double":
            Double dLowerValue = lower ? query.getJsonNumber("lowerTerm").doubleValue() : Double.NEGATIVE_INFINITY;
            Double dUpperValue = upper ? query.getJsonNumber("upperTerm").doubleValue() : Double.POSITIVE_INFINITY;
            if (!includeLower && dLowerValue != null)
                dLowerValue = Math.nextUp(dLowerValue);
            if (!includeUpper && dUpperValue != null)
                dUpperValue = Math.nextDown(dUpperValue);
            return DoublePoint.newRangeQuery(field, dLowerValue, dUpperValue);
    }
    return null;
}
项目:meresco-lucene    文件:DocumentStringToDocumentTest.java   
@Test
public void testDoubleField() {
    JsonArray json = Json.createArrayBuilder()
            .add(Json.createObjectBuilder()
                .add("type", "DoubleField")
                .add("name", "name")
                .add("value", 1.5))
            .build();
    Document result = convert(json.toString());
    assertEquals(new DoublePoint("name", 1).fieldType(), result.getField("name").fieldType());
    assertEquals(1.5D, result.getField("name").numericValue().doubleValue(), 0);
}
项目:elasticsearch_my    文件:NumberFieldMapper.java   
@Override
Query termQuery(String field, Object value) {
    double v = parse(value, false);
    return DoublePoint.newExactQuery(field, v);
}
项目:fiery    文件:APIStatisticDetailPage.java   
@RequestMapping(value = "/apistatisticdetail", method = RequestMethod.GET)
    public String currentlog(Model model, @RequestParam(value = "url", required = false, defaultValue = "") String keyword,
                             @RequestParam(value = "topdatarange", required = false, defaultValue = "") String dataRange) {

        //date list
        List<String> timelist = DateTimeHelper.getDateTimeListForPage(fieryConfig.getKeepdataday());
        model.addAttribute("datelist", timelist);
        model.addAttribute("datelist_selected", dataRange);

        //now the date render
        long shardtime = DateTimeHelper.getTimesMorning(DateTimeHelper.getBeforeDay(Integer.parseInt(dataRange)));
        ConcurrentHashMap<String, APIStatisticStruct> urllist = apiStatisticTimeSet.getDaySharder(shardtime, false);

        //data range
        Integer dataRangeInt = 0;

        if (dataRange.trim().length() == 0) {
            dataRange = "0";
        }

        model.addAttribute("topdatarange", dataRange);

        try {
            dataRangeInt = Integer.parseInt(dataRange);
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());
            return "apistatisticdetail";
        }

        Long startRange = DateTimeHelper.getTimesMorning(DateTimeHelper.getCurrentTime()) - (dataRangeInt * 86400);

        TermQuery termQuery = new TermQuery(new Term("url", keyword.trim()));
        Query rangeQuery = DoublePoint.newRangeQuery("time", startRange, startRange + 86400);
        //rangeStart
        BooleanQuery query = new BooleanQuery.Builder()
                .add(termQuery, BooleanClause.Occur.MUST)
                .add(rangeQuery, BooleanClause.Occur.MUST)
                .build();
/*
        //term query
        String queryString = "url:\"" + keyword.trim() + "\" AND time_raw:[" + startRange + " TO " + (startRange + 86400) + "]";
        log.info("queryString:" + queryString);

        Query query;
        QueryParser parser = new QueryParser("url,time_raw", new StandardAnalyzer());
        try {
            query = parser.parse(queryString);
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());
            return "apistatisticdetail";
        }
*/
/*
        Query query;
        Term term = new Term("url", keyword.trim());
        query = new TermQuery(term);

*/

        Sort sort = new Sort(new SortField("elapsed_ms", SortField.Type.DOUBLE, true));
        ResponseJson result = indexHelper.searchByQuery(startRange, query, 0, 1000, sort);
        model.addAttribute("resultlist", result.getResult());
        model.addAttribute("url", keyword);

        return "apistatisticdetail";
    }
项目:lumongo    文件:DoubleFieldIndexer.java   
@Override
protected Field createField(Number o, String indexedFieldName) {
    return new DoublePoint(indexedFieldName, o.doubleValue());
}
项目:meresco-lucene    文件:DocumentStringToDocument.java   
private List<IndexableField> createFields(JsonObject jsonField) throws IOException {
    String name = jsonField.getString("name");
    List<IndexableField> fields = new ArrayList<>();
    switch (jsonField.getString("type")) {
        case "StringField":
            String stringValue = jsonField.getString("value");
            if (jsonField.getBoolean("sort", false)) {
                fields.add(new SortedDocValuesField(name, new BytesRef(stringValue)));
            } else {
                boolean stored = jsonField.getBoolean("stored", false);
                fields.add(new Field(name, stringValue, maybeAddTermVectors(jsonField, stored ? StringField.TYPE_STORED : StringField.TYPE_NOT_STORED)));
            }
            break;
        case "TextField":
            fields.add(new Field(name, jsonField.getString("value"), maybeAddTermVectors(jsonField, TextField.TYPE_NOT_STORED)));
            break;
        case "NoTermsFrequencyField":
            fields.add(new Field(name, jsonField.getString("value"), NO_TERMS_FREQUENCY_FIELD));
            break;
        case "IntPoint":
        case "IntField":  // for backwards compatibility
            int intValue = jsonField.getInt("value");
            if (jsonField.getBoolean("sort", false)) {
                fields.add(new NumericDocValuesField(name, intValue));
            } else {
                if (jsonField.getBoolean("stored", false))
                    fields.add(new StoredField(name, intValue));
                fields.add(new IntPoint(name, intValue));
            }
            break;
        case "DoublePoint":
        case "DoubleField":  // for backwards compatibility
            double doubleValue = jsonField.getJsonNumber("value").doubleValue();
            if (jsonField.getBoolean("sort", false)) {
                fields.add(new NumericDocValuesField(name, NumericUtils.doubleToSortableLong(doubleValue)));
            } else {
                if (jsonField.getBoolean("stored", false))
                    fields.add(new StoredField(name, doubleValue));
                fields.add(new DoublePoint(name, doubleValue));
            }
            break;
        case "LongPoint":
        case "LongField":  // for backwards compatibility
            long longValue = jsonField.getJsonNumber("value").longValue();
            if (jsonField.getBoolean("sort", false)) {
                fields.add(new NumericDocValuesField(name, longValue));
            } else {
                if (jsonField.getBoolean("stored", false))
                    fields.add(new StoredField(name, longValue));
                fields.add(new LongPoint(name, longValue));
            }
            break;
        case "NumericField":
            fields.add(new NumericDocValuesField(name, jsonField.getJsonNumber("value").longValue()));
            break;
        case "KeyField":
            int value;
            if (jsonField.get("value").getValueType().equals(ValueType.STRING)) {
                value = termNumerator.numerateTerm(jsonField.getString("value"));
            } else {
                value = jsonField.getInt("value");
            }
            fields.add(new NumericDocValuesField(name, value));
            break;
        case "FacetField":
            JsonArray jsonArray = jsonField.getJsonArray("path");
            String[] path = new String[jsonArray.size()];
            for (int i = 0; i < jsonArray.size(); i++) {
                path[i] = jsonArray.getString(i);
            }
            fields.add(new FacetField(name, path));
    }
    return fields;
}