diff options
author | Jon Bratseth <bratseth@yahoo-inc.com> | 2016-06-15 23:09:44 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@yahoo-inc.com> | 2016-06-15 23:09:44 +0200 |
commit | 72231250ed81e10d66bfe70701e64fa5fe50f712 (patch) | |
tree | 2728bba1131a6f6e5bdf95afec7d7ff9358dac50 /container-search/src/main/java/com/yahoo/prelude/query/RangeItem.java |
Publish
Diffstat (limited to 'container-search/src/main/java/com/yahoo/prelude/query/RangeItem.java')
-rw-r--r-- | container-search/src/main/java/com/yahoo/prelude/query/RangeItem.java | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/container-search/src/main/java/com/yahoo/prelude/query/RangeItem.java b/container-search/src/main/java/com/yahoo/prelude/query/RangeItem.java new file mode 100644 index 00000000000..4db8ff0b47a --- /dev/null +++ b/container-search/src/main/java/com/yahoo/prelude/query/RangeItem.java @@ -0,0 +1,114 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.prelude.query; + +/** + * This class represents a numeric range. You can also specify the number of hits you want this range to produce, + * which can be used to create more efficient searches. + * Note that '0' as hit limit means all hits matching the range criterion will be a match, + * while positive numbers start from 'from' working + * its way towards 'to' until it has reached its limit or range is exhausted. Negative number means that it will start + * from 'to' and work its way towards 'from'. + * + * @author balder + * @author bratseth + * @since 5.1.23 + */ +// Note that this is just a convenience subclass of IntItem - it does not add any functionality not available in it. +public class RangeItem extends IntItem { + + /** + * Creates a new range operator + * + * @param from inclusive start point for range + * @param to inclusive end point for range + * @param indexName the index to search for this range + */ + public RangeItem(Number from, Number to, String indexName) { + this(from, to, indexName, false); + } + + /** + * Creates a new range operator + * + * @param from start point for range + * @param to end point for range + * @param indexName the index to search for this range + */ + public RangeItem(Limit from, Limit to, String indexName) { + this(from, to, indexName, false); + } + + /** + * Creates a new range operator + * + * @param from inclusive start point for range + * @param to inclusive end point for range + * @param indexName the index to search for this range + * @param isFromQuery Indicate if this stems directly from the user given query, + * or if you have constructed it at will. + */ + public RangeItem(Number from, Number to, String indexName, boolean isFromQuery) { + this(from, to, 0, indexName, isFromQuery); + } + + /** + * Creates a new range operator + * + * @param from start point for range + * @param to end point for range + * @param indexName the index to search for this range + * @param isFromQuery Indicate if this stems directly from the user given query, + * or if you have constructed it at will. + */ + public RangeItem(Limit from, Limit to, String indexName, boolean isFromQuery) { + this(from, to, 0, indexName, isFromQuery); + } + + /** + * + * @param from inclusive start point for range + * @param to inclusive end point for range + * @param hitLimit This tells how many results you want included from this range as a minimum. + * You might get less if there are not enough, or you might get more. It will use the dictionary and + * include enough entries to satisfy your request. + * Positive number will start from left (@from) and work right. + * Negative number will start from right and work its way left. + * 0 means no limit. + * @param indexName the index to search for this range + * @param isFromQuery Indicate if this stems directly from the user given query, + * or if you have constructed it at will. + */ + public RangeItem(Number from, Number to, int hitLimit, String indexName, boolean isFromQuery) { + this(new Limit(from, true), new Limit(to, true), hitLimit, indexName, isFromQuery); + } + + /** + * + * @param from start point for range + * @param to end point for range + * @param hitLimit This tells how many results you want included from this range as a minimum. + * You might get less if there are not enough, or you might get more. It will use the dictionary and + * include enough entries to satisfy your request. + * Positive number will start from left (@from) and work right. + * Negative number will start from right and work its way left. + * 0 means no limit. + * @param indexName the index to search for this range + * @param isFromQuery Indicate if this stems directly from the user given query, + * or if you have constructed it at will. + */ + public RangeItem(Limit from, Limit to, int hitLimit, String indexName, boolean isFromQuery) { + super(from, to, hitLimit, indexName, isFromQuery); + } + + /** Returns the lower limit of this range, which may be negative infinity */ + public final Number getFrom() { + return getFromLimit().number(); + } + + /** Returns the upper limit of this range, which may be positive infinity */ + public final Number getTo() { + return getToLimit().number(); + } + + +} |