server/search: add content-checksum
This commit is contained in:
parent
ffb87f1650
commit
422b99ac8d
4 changed files with 65 additions and 40 deletions
3
API.md
3
API.md
|
@ -633,7 +633,7 @@ data.
|
|||
**Named tokens**
|
||||
|
||||
| `<key>` | Description |
|
||||
| ---------------- | ---------------------------------------------------------- |
|
||||
| ------------------ | ---------------------------------------------------------- |
|
||||
| `id` | having given post number |
|
||||
| `tag` | having given tag |
|
||||
| `score` | having given score |
|
||||
|
@ -649,6 +649,7 @@ data.
|
|||
| `relation-count` | having given number of relations |
|
||||
| `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`). |
|
||||
| `content-checksum` | having given SHA1 checksum |
|
||||
| `file-size` | having given file size (in bytes) |
|
||||
| `image-width` | having given image width (where applicable) |
|
||||
| `image-height` | having given image height (where applicable) |
|
||||
|
|
|
@ -66,6 +66,10 @@
|
|||
<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>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>content-checksum</code></td>
|
||||
<td>having given SHA1 checksum</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>file-size</code></td>
|
||||
<td>having given file size (in bytes)</td>
|
||||
|
|
|
@ -182,6 +182,8 @@ class PostSearchConfig(BaseSearchConfig):
|
|||
'type':
|
||||
search_util.create_str_filter(
|
||||
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),
|
||||
('image-width', '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)
|
||||
|
||||
|
||||
@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', [
|
||||
('file-size:100', [1]),
|
||||
('file-size:102', [3]),
|
||||
|
|
Loading…
Reference in a new issue