示例#1
0
func (q *numericRangeQuery) Searcher(i index.IndexReader, m *IndexMapping, explain bool) (search.Searcher, error) {
	field := q.FieldVal
	if q.FieldVal == "" {
		field = m.DefaultField
	}
	return searchers.NewNumericRangeSearcher(i, q.Min, q.Max, q.InclusiveMin, q.InclusiveMax, field, q.BoostVal, explain)
}
示例#2
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)
}