Exemplo n.º 1
0
func (n *NumericField) Number() (float64, error) {
	i64, err := n.value.Int64()
	if err != nil {
		return 0.0, err
	}
	return numeric_util.Int64ToFloat64(i64), nil
}
Exemplo n.º 2
0
func (fb *NumericFacetBuilder) Update(ft index.FieldTerms) {
	terms, ok := ft[fb.field]
	if ok {
		for _, term := range terms {
			// only consider the values which are shifted 0
			prefixCoded := numeric_util.PrefixCoded(term)
			shift, err := prefixCoded.Shift()
			if err == nil && shift == 0 {
				i64, err := prefixCoded.Int64()
				if err == nil {
					f64 := numeric_util.Int64ToFloat64(i64)

					// look at each of the ranges for a match
					for rangeName, r := range fb.ranges {

						if (r.min == nil || f64 >= *r.min) && (r.max == nil || f64 < *r.max) {

							existingCount, existed := fb.termsCount[rangeName]
							if existed {
								fb.termsCount[rangeName] = existingCount + 1
							} else {
								fb.termsCount[rangeName] = 1
							}
							fb.total++
						}
					}
				}
			}
		}
	} else {
		fb.missing++
	}
}
Exemplo n.º 3
0
func (q *dateRangeQuery) Searcher(i index.IndexReader, m *IndexMapping, explain bool) (search.Searcher, error) {

	dateTimeParserName := ""
	if q.DateTimeParser != nil {
		dateTimeParserName = *q.DateTimeParser
	} else {
		dateTimeParserName = m.datetimeParserNameForPath(q.FieldVal)
	}
	dateTimeParser := m.dateTimeParserNamed(dateTimeParserName)
	if dateTimeParser == nil {
		return nil, fmt.Errorf("no datetime parser named '%s' registered", *q.DateTimeParser)
	}

	field := q.FieldVal
	if q.FieldVal == "" {
		field = m.DefaultField
	}

	// now parse the endpoints
	min := math.Inf(-1)
	max := math.Inf(1)
	if q.Start != nil && *q.Start != "" {
		startTime, err := dateTimeParser.ParseDateTime(*q.Start)
		if err != nil {
			return nil, err
		}
		min = numeric_util.Int64ToFloat64(startTime.UnixNano())
	}
	if q.End != nil && *q.End != "" {
		endTime, err := dateTimeParser.ParseDateTime(*q.End)
		if err != nil {
			return nil, err
		}
		max = numeric_util.Int64ToFloat64(endTime.UnixNano())
	}

	return searchers.NewNumericRangeSearcher(i, &min, &max, q.InclusiveStart, q.InclusiveEnd, field, q.BoostVal, explain)
}