server/search: support -min and -max suffixes
This commit is contained in:
parent
71e8e32faf
commit
0bc45e9c45
5 changed files with 26 additions and 5 deletions
3
API.md
3
API.md
|
@ -622,6 +622,9 @@ take following form:
|
|||
| `..4` | will show things that are equal to at most 4. |
|
||||
| `1..4` | will show things that are equal to 1, 2, 3 or 4. |
|
||||
|
||||
Ranged values can be also supplied by appending `-min` or `-max` to the key,
|
||||
for example like this: `score-min:1`.
|
||||
|
||||
Date/time values can be of following form:
|
||||
|
||||
- `today`
|
||||
|
|
|
@ -58,6 +58,10 @@ take following form:</p>
|
|||
</tbody>
|
||||
</table>
|
||||
|
||||
<p>Ranged values can be also supplied by appending <code>-min</code> or
|
||||
<code>-max</code> to the key, for example like this:
|
||||
<code>score-min:1</code>.</p>
|
||||
|
||||
<p>Date/time values can be of following form:</p>
|
||||
|
||||
<ul>
|
||||
|
|
|
@ -25,7 +25,6 @@ class EndlessPageView {
|
|||
const threshold = window.innerHeight / 3;
|
||||
|
||||
if (ctx.state && ctx.state.html) {
|
||||
console.log('Loading from state');
|
||||
this.minPageShown = ctx.state.minPageShown;
|
||||
this.maxPageShown = ctx.state.maxPageShown;
|
||||
this.totalPages = ctx.state.totalPages;
|
||||
|
@ -83,6 +82,7 @@ class EndlessPageView {
|
|||
if (ctx.state && ctx.state.html) {
|
||||
pagesHolder.innerHTML = ctx.state.html;
|
||||
window.scroll(ctx.state.scrollX, ctx.state.scrollY);
|
||||
this.updater();
|
||||
} else {
|
||||
this.loadPage(pagesHolder, ctx, ctx.searchQuery.page, true);
|
||||
}
|
||||
|
|
|
@ -52,8 +52,7 @@ class SearchExecutor(object):
|
|||
elif key == 'special':
|
||||
return self._handle_special(query, value, negated)
|
||||
else:
|
||||
return self._handle_named(
|
||||
query, key, self._create_criterion(value, negated))
|
||||
return self._handle_named(query, key, value, negated)
|
||||
|
||||
def _handle_anonymous(self, query, criterion):
|
||||
if not self._search_config.anonymous_filter:
|
||||
|
@ -61,7 +60,14 @@ class SearchExecutor(object):
|
|||
'Anonymous tokens are not valid in this context.')
|
||||
return self._search_config.anonymous_filter(query, criterion)
|
||||
|
||||
def _handle_named(self, query, key, criterion):
|
||||
def _handle_named(self, query, key, value, negated):
|
||||
if key.endswith('-min'):
|
||||
key = key[:-4]
|
||||
value += '..'
|
||||
elif key.endswith('-max'):
|
||||
key = key[:-4]
|
||||
value = '..' + value
|
||||
criterion = self._create_criterion(value, negated)
|
||||
if key in self._search_config.named_filters:
|
||||
return self._search_config.named_filters[key](query, criterion)
|
||||
raise errors.SearchError(
|
||||
|
@ -113,7 +119,7 @@ class SearchExecutor(object):
|
|||
|
||||
def _create_criterion(self, value, negated):
|
||||
if '..' in value:
|
||||
low, high = value.split('..')
|
||||
low, high = value.split('..', 1)
|
||||
if not low and not high:
|
||||
raise errors.SearchError('Empty ranged value')
|
||||
return criteria.RangedSearchCriterion(value, negated, low, high)
|
||||
|
|
|
@ -26,6 +26,8 @@ def verify_unpaged(session, executor):
|
|||
('creation-time:2014-06..2015-01-01', ['u2', 'u3']),
|
||||
('creation-time:2014-06..', ['u2', 'u3']),
|
||||
('creation-time:..2014-06', ['u1', 'u2']),
|
||||
('creation-time-min:2014-06', ['u2', 'u3']),
|
||||
('creation-time-max:2014-06', ['u1', 'u2']),
|
||||
('-creation-time:2014..2014-06', ['u3']),
|
||||
('-creation-time:2014-06..2015-01-01', ['u1']),
|
||||
('creation-date:2014..2014-06', ['u1', 'u2']),
|
||||
|
@ -192,6 +194,12 @@ def test_random_order(session, executor, user_factory):
|
|||
|
||||
@pytest.mark.parametrize('input,expected_error', [
|
||||
('creation-date:..', errors.SearchError),
|
||||
('creation-date-min:..', errors.ValidationError),
|
||||
('creation-date-min:..2014-01-01', errors.ValidationError),
|
||||
('creation-date-min:2014-01-01..', errors.ValidationError),
|
||||
('creation-date-max:..2014-01-01', errors.ValidationError),
|
||||
('creation-date-max:2014-01-01..', errors.ValidationError),
|
||||
('creation-date-max:yesterday,today', errors.ValidationError),
|
||||
('creation-date:bad..', errors.ValidationError),
|
||||
('creation-date:..bad', errors.ValidationError),
|
||||
('creation-date:bad..bad', errors.ValidationError),
|
||||
|
|
Loading…
Reference in a new issue