server/search: add content-checksum
This commit is contained in:
parent
ffb87f1650
commit
422b99ac8d
4 changed files with 65 additions and 40 deletions
81
API.md
81
API.md
|
@ -632,46 +632,47 @@ data.
|
||||||
|
|
||||||
**Named tokens**
|
**Named tokens**
|
||||||
|
|
||||||
| `<key>` | Description |
|
| `<key>` | Description |
|
||||||
| ---------------- | ---------------------------------------------------------- |
|
| ------------------ | ---------------------------------------------------------- |
|
||||||
| `id` | having given post number |
|
| `id` | having given post number |
|
||||||
| `tag` | having given tag |
|
| `tag` | having given tag |
|
||||||
| `score` | having given score |
|
| `score` | having given score |
|
||||||
| `uploader` | uploaded by given user |
|
| `uploader` | uploaded by given user |
|
||||||
| `upload` | alias of upload |
|
| `upload` | alias of upload |
|
||||||
| `submit` | alias of upload |
|
| `submit` | alias of upload |
|
||||||
| `comment` | commented by given user |
|
| `comment` | commented by given user |
|
||||||
| `fav` | favorited by given user |
|
| `fav` | favorited by given user |
|
||||||
| `tag-count` | having given number of tags |
|
| `tag-count` | having given number of tags |
|
||||||
| `comment-count` | having given number of comments |
|
| `comment-count` | having given number of comments |
|
||||||
| `fav-count` | favorited by given number of users |
|
| `fav-count` | favorited by given number of users |
|
||||||
| `note-count` | having given number of annotations |
|
| `note-count` | having given number of annotations |
|
||||||
| `relation-count` | having given number of relations |
|
| `relation-count` | having given number of relations |
|
||||||
| `feature-count` | having been featured given number of times |
|
| `feature-count` | having been featured given number of times |
|
||||||
| `type` | given type of posts. `<value>` can be either `image`, `animation` (or `animated` or `anim`), `flash` (or `swf`) or `video` (or `webm`). |
|
| `type` | given type of posts. `<value>` can be either `image`, `animation` (or `animated` or `anim`), `flash` (or `swf`) or `video` (or `webm`). |
|
||||||
| `file-size` | having given file size (in bytes) |
|
| `content-checksum` | having given SHA1 checksum |
|
||||||
| `image-width` | having given image width (where applicable) |
|
| `file-size` | having given file size (in bytes) |
|
||||||
| `image-height` | having given image height (where applicable) |
|
| `image-width` | having given image width (where applicable) |
|
||||||
| `image-area` | having given number of pixels (image width * image height) |
|
| `image-height` | having given image height (where applicable) |
|
||||||
| `width` | alias of `image-width` |
|
| `image-area` | having given number of pixels (image width * image height) |
|
||||||
| `height` | alias of `image-height` |
|
| `width` | alias of `image-width` |
|
||||||
| `area` | alias of `image-area` |
|
| `height` | alias of `image-height` |
|
||||||
| `creation-date` | posted at given date |
|
| `area` | alias of `image-area` |
|
||||||
| `creation-time` | alias of `creation-date` |
|
| `creation-date` | posted at given date |
|
||||||
| `date` | alias of `creation-date` |
|
| `creation-time` | alias of `creation-date` |
|
||||||
| `time` | alias of `creation-date` |
|
| `date` | alias of `creation-date` |
|
||||||
| `last-edit-date` | edited at given date |
|
| `time` | alias of `creation-date` |
|
||||||
| `last-edit-time` | alias of `last-edit-date` |
|
| `last-edit-date` | edited at given date |
|
||||||
| `edit-date` | alias of `last-edit-date` |
|
| `last-edit-time` | alias of `last-edit-date` |
|
||||||
| `edit-time` | alias of `last-edit-date` |
|
| `edit-date` | alias of `last-edit-date` |
|
||||||
| `comment-date` | commented at given date |
|
| `edit-time` | alias of `last-edit-date` |
|
||||||
| `comment-time` | alias of `comment-date` |
|
| `comment-date` | commented at given date |
|
||||||
| `fav-date` | last favorited at given date |
|
| `comment-time` | alias of `comment-date` |
|
||||||
| `fav-time` | alias of `fav-date` |
|
| `fav-date` | last favorited at given date |
|
||||||
| `feature-date` | featured at given date |
|
| `fav-time` | alias of `fav-date` |
|
||||||
| `feature-time` | alias of `feature-time` |
|
| `feature-date` | featured at given date |
|
||||||
| `safety` | having given safety. `<value>` can be either `safe`, `sketchy` (or `questionable`) or `unsafe`. |
|
| `feature-time` | alias of `feature-time` |
|
||||||
| `rating` | alias of `safety` |
|
| `safety` | having given safety. `<value>` can be either `safe`, `sketchy` (or `questionable`) or `unsafe`. |
|
||||||
|
| `rating` | alias of `safety` |
|
||||||
|
|
||||||
**Sort style tokens**
|
**Sort style tokens**
|
||||||
|
|
||||||
|
|
|
@ -66,6 +66,10 @@
|
||||||
<td><code>type</code></td>
|
<td><code>type</code></td>
|
||||||
<td>given type of posts. <code><value></code> can be either <code>image</code>, <code>animation</code> (or <code>animated</code> or <code>anim</code>), <code>flash</code> (or <code>swf</code>) or <code>video</code> (or <code>webm</code>).</td>
|
<td>given type of posts. <code><value></code> can be either <code>image</code>, <code>animation</code> (or <code>animated</code> or <code>anim</code>), <code>flash</code> (or <code>swf</code>) or <code>video</code> (or <code>webm</code>).</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><code>content-checksum</code></td>
|
||||||
|
<td>having given SHA1 checksum</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td><code>file-size</code></td>
|
<td><code>file-size</code></td>
|
||||||
<td>having given file size (in bytes)</td>
|
<td>having given file size (in bytes)</td>
|
||||||
|
|
|
@ -182,6 +182,8 @@ class PostSearchConfig(BaseSearchConfig):
|
||||||
'type':
|
'type':
|
||||||
search_util.create_str_filter(
|
search_util.create_str_filter(
|
||||||
db.Post.type, _type_transformer),
|
db.Post.type, _type_transformer),
|
||||||
|
'content-checksum': search_util.create_str_filter(
|
||||||
|
db.Post.checksum),
|
||||||
'file-size': search_util.create_num_filter(db.Post.file_size),
|
'file-size': search_util.create_num_filter(db.Post.file_size),
|
||||||
('image-width', 'width'):
|
('image-width', 'width'):
|
||||||
search_util.create_num_filter(db.Post.canvas_width),
|
search_util.create_num_filter(db.Post.canvas_width),
|
||||||
|
|
|
@ -365,6 +365,24 @@ def test_filter_by_invalid_type(executor):
|
||||||
executor.execute('type:invalid', page=1, page_size=100)
|
executor.execute('type:invalid', page=1, page_size=100)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('input,expected_post_ids', [
|
||||||
|
('content-checksum:checksum1', [1]),
|
||||||
|
('content-checksum:checksum3', [3]),
|
||||||
|
('content-checksum:checksum1,checksum3', [1, 3]),
|
||||||
|
])
|
||||||
|
def test_filter_by_content_checksum(
|
||||||
|
verify_unpaged, post_factory, input, expected_post_ids):
|
||||||
|
post1 = post_factory(id=1)
|
||||||
|
post2 = post_factory(id=2)
|
||||||
|
post3 = post_factory(id=3)
|
||||||
|
post1.checksum = 'checksum1'
|
||||||
|
post2.checksum = 'checksum2'
|
||||||
|
post3.checksum = 'checksum3'
|
||||||
|
db.session.add_all([post1, post2, post3])
|
||||||
|
db.session.flush()
|
||||||
|
verify_unpaged(input, expected_post_ids)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('input,expected_post_ids', [
|
@pytest.mark.parametrize('input,expected_post_ids', [
|
||||||
('file-size:100', [1]),
|
('file-size:100', [1]),
|
||||||
('file-size:102', [3]),
|
('file-size:102', [3]),
|
||||||
|
|
Loading…
Reference in a new issue