server/posts: expose reverse image search
This commit is contained in:
parent
1a59a74d63
commit
a7a5cc8180
3 changed files with 68 additions and 0 deletions
52
API.md
52
API.md
|
@ -42,6 +42,7 @@
|
||||||
- [Removing post from favorites](#removing-post-from-favorites)
|
- [Removing post from favorites](#removing-post-from-favorites)
|
||||||
- [Getting featured post](#getting-featured-post)
|
- [Getting featured post](#getting-featured-post)
|
||||||
- [Featuring post](#featuring-post)
|
- [Featuring post](#featuring-post)
|
||||||
|
- [Reverse image search](#reverse-image-search)
|
||||||
- Comments
|
- Comments
|
||||||
- [Listing comments](#listing-comments)
|
- [Listing comments](#listing-comments)
|
||||||
- [Creating comment](#creating-comment)
|
- [Creating comment](#creating-comment)
|
||||||
|
@ -76,6 +77,7 @@
|
||||||
- [Snapshot](#snapshot)
|
- [Snapshot](#snapshot)
|
||||||
- [Unpaged search result](#unpaged-search-result)
|
- [Unpaged search result](#unpaged-search-result)
|
||||||
- [Paged search result](#paged-search-result)
|
- [Paged search result](#paged-search-result)
|
||||||
|
- [Image search result](#image-search-result)
|
||||||
|
|
||||||
4. [Search](#search)
|
4. [Search](#search)
|
||||||
|
|
||||||
|
@ -1057,6 +1059,28 @@ data.
|
||||||
|
|
||||||
Features a post on the main page in web client.
|
Features a post on the main page in web client.
|
||||||
|
|
||||||
|
## Reverse image search
|
||||||
|
- **Request**
|
||||||
|
|
||||||
|
`POST /posts/reverse-search`
|
||||||
|
|
||||||
|
- **Files**
|
||||||
|
|
||||||
|
- `content` - the image to search for.
|
||||||
|
|
||||||
|
- **Output**
|
||||||
|
|
||||||
|
A list of [image search results](#image-search-result).
|
||||||
|
|
||||||
|
- **Errors**
|
||||||
|
|
||||||
|
- privileges are too low
|
||||||
|
|
||||||
|
- **Description**
|
||||||
|
|
||||||
|
Retrieves posts that look like the input image. Works only on images and
|
||||||
|
animations, i.e. does not work for videos and Flash movies.
|
||||||
|
|
||||||
## Listing comments
|
## Listing comments
|
||||||
- **Request**
|
- **Request**
|
||||||
|
|
||||||
|
@ -2118,6 +2142,34 @@ A result of search operation that involves paging.
|
||||||
details on this field, check the documentation for given API call.
|
details on this field, check the documentation for given API call.
|
||||||
|
|
||||||
|
|
||||||
|
## Image search result
|
||||||
|
**Description**
|
||||||
|
|
||||||
|
A result of reverse image search operation.
|
||||||
|
|
||||||
|
**Structure**
|
||||||
|
|
||||||
|
```json5
|
||||||
|
{
|
||||||
|
"results": [
|
||||||
|
{
|
||||||
|
"dist": <distance>,
|
||||||
|
"post": <post>
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"dist": <distance>,
|
||||||
|
"post": <post>
|
||||||
|
},
|
||||||
|
...
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Field meaning**
|
||||||
|
- `<dist>`: distance from the original image (0..1). The lower this value is, the more similar the
|
||||||
|
post is.
|
||||||
|
- `<post>`: a [post resource](#post).
|
||||||
|
|
||||||
# Search
|
# Search
|
||||||
|
|
||||||
Search queries are built of tokens that are separated by spaces. Each token can
|
Search queries are built of tokens that are separated by spaces. Each token can
|
||||||
|
|
|
@ -73,6 +73,7 @@ privileges:
|
||||||
'posts:create:anonymous': regular
|
'posts:create:anonymous': regular
|
||||||
'posts:create:identified': regular
|
'posts:create:identified': regular
|
||||||
'posts:list': anonymous
|
'posts:list': anonymous
|
||||||
|
'posts:reverse_search': regular
|
||||||
'posts:view': anonymous
|
'posts:view': anonymous
|
||||||
'posts:edit:content': power
|
'posts:edit:content': power
|
||||||
'posts:edit:flags': regular
|
'posts:edit:flags': regular
|
||||||
|
|
|
@ -205,3 +205,18 @@ def get_posts_around(ctx, params):
|
||||||
_search_executor.config.user = ctx.user
|
_search_executor.config.user = ctx.user
|
||||||
return _search_executor.get_around_and_serialize(
|
return _search_executor.get_around_and_serialize(
|
||||||
ctx, params['post_id'], lambda post: _serialize_post(ctx, post))
|
ctx, params['post_id'], lambda post: _serialize_post(ctx, post))
|
||||||
|
|
||||||
|
|
||||||
|
@routes.post('/posts/reverse-search/?')
|
||||||
|
def get_posts_by_image(ctx, _params=None):
|
||||||
|
auth.verify_privilege(ctx.user, 'posts:reverse_search')
|
||||||
|
content = ctx.get_file('content', required=True)
|
||||||
|
return {
|
||||||
|
'results': [
|
||||||
|
{
|
||||||
|
'dist': item['dist'],
|
||||||
|
'post': _serialize_post(ctx, item['post']),
|
||||||
|
}
|
||||||
|
for item in posts.search_by_image(content)
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue