Content Search V2 (Deprecated)

Content Search allows you to perform more complex content searching and sorting. The feature can be used for the following use cases:

  • Search post by text content

  • Find posts that contain a specific hashtag

  • Sort post by last activity or reaction count

Search Posts

Search Posts API can be used to search and sort relevant posts created into Social Plus. All APIs will return sorted list of post IDs that contains relevant contents.

API Reference

(V2) Search posts by query as indicated in request JSON body

POST https://beta.amity.services/search/v2/posts

Headers

Name
Type
Description

Authorization*

String

Bearer {accessToken}

(accessToken is retrieved from Amity SDK)

Request Body

Name
Type
Description

query*

JSON

Query JSON (see below)

sort

JSON

Sort JSON (see below)

from

Number

Offset from the first result to be fetched

size

Number

Maximum amount of IDs to be returned

populatePostObject

Bool

Include post object in response or not?

{
    "success": true,
    "postIds": [
    "id",
    "id"
    ],
    "objects": {<postObject>}
    //To view the complete <postObject> format, please refer to the response section in the api documentation for the get list of posts, which can be found at https://api-docs.amity.co/#/Post/get_api_v3_posts_list.
}

(V2) Search posts by query as indicated in request JSON body

POST https://beta.amity.services/search/v2/posts

Headers

Name
Type
Description

Authorization*

String

4GhW4Zkn5wyA

Request Body

Name
Type
Description

query*

JSON

ksvJag3FnmK7

sort

JSON

DPUspUSAMciZ

from

Number

PQwGuNG9QW0L

size

Number

HPqjW34NqGXA

populatePostObject

Bool

2qk6tMD7d9su

When populatePostObject is set to true, the posts object will be retrieved from the API separately and will not be cached within the SDK. If the user wants to subscribe to the post object and use LiveObject/LiveCollection, they should use getList from the SDK.

Query JSON

query is a JSON object that indicates the posts to be searched for. The following is the full JSON structure with all the fields:

All fields are optional. If targetId is present the system will search for posts on those communities. If targetId is not specified the system will search for all posts created by userId calling the API.

For Search V2:

"query" : {
   "targetId" : ["communityId_1", "communityId_2"], // ID of community to search the posts from
   "targetType" : "community", // Mandatory if targetIds exist
   "publicSearch" : false // Boolean indicating whether the post originated from a public source or not, targetType must be public when this field is true.
   "text" : "christmas", // Text content to search for
   "sharedCount" : { "gt":10, "lt":20 }, // Number of share of the post in NumberQuery format - Please see NumberQuery section for more detail
   "createdAt" : { "gt":"2021-05-20T04:44:42.334Z" }, // Created time of the post in TimeQuery format - Please see NumberQuery section for more detail
   "updatedAt" : { "gt":"2021-05-20T04:44:42.334Z" }, // last updated time of the post in TimeQuery format - Please see NumberQuery section for more detail
   "hasFlaggedComment" : false, // Boolean whether the posts contain any comments that has been flagged
   "hasFlaggedChildren" : false, // Boolean whether the posts contain any children post that has been flagged
   "postedUserId" : "user_101", //User ID who created the post
   "flagCount" : { "gt":0 }, // Number of flags oon the post in NumberQuery format - Please see NumberQuery section for more detail
   "reactionsCount" : { "gt":10, "lt":20 }, // Number of reactions on the post in NumberQuery format - Please see NumberQuery section for more detail
   "categoryId" : "categoryId_1",// Category of community the post is on
   "lastActivity" : "2021-12-08T15:17:07.965Z", // Last timestamp the post is liked or commented on
   "mentionees": [
     "userIdA",
     "userIdB"
   ], // Use 'mentionees' to search for posts where these userIDs have been mentioned."
   "hashtagList":[
     "#tags1",
     "#tags2",
     "#tags3"
   ], // If your post contained #ABC on your text post you can use 'haghtagList' to search for your #.
   "tags":[
      "tags1",
      "tags2",
      "tags3"
   ] // If your post added any tag on tags field you can use 'haghtagList' to search for your #.
}

targetType can be the following values:

  • community - search posts in all communities ID as defined in targetId

  • self - search all posts that belongs to the user passed in userId within request body

  • public - search all posts that is in all public communities

Limitations

Current limitations on Search Posts API are

  • Posts created on user feed is not yet searchable.

Query & Sort Format

NumberQuery

NumberQuery JSON structure defines range of numerical value to look for in a property. Available fields within the JSON structure are:

{
   "gt" : 0, // value of the field must be greater than specific value
   "lt" : 10, // value of the field must be less than specific value
   "gte" : 0, // value of the field must be greater than or equals to specific value
   "lte" : 10 // value of the field must be less than or equals to specific value
}

TimeQuery

TimeQuery JSON structure defines range of date time value to look for in a property. Available fields within the JSON structure are:

{
   "gt" : "2021-08-20T06:26:57.205Z", // value of the field must be after specific date time
   "lt" : "2021-08-31T06:26:57.205Z", // value of the field must be before specific date time
   "gte" : "2021-08-20T06:26:57.205Z", // value of the field must be after than or equals to specific date time
   "lte" : "2021-08-31T06:26:57.205Z" // value of the field must be before than or equals to specific date time
}

Time string in TimeQuery must be in ISO Date Format: YYYY-MM-DDThh:mm:ss.sZ

Sort JSON

sort is a JSON array that indicates how should the returning contents be sorted. The following is the full JSON structure:

[
   "<sort_field>" : { 
      "order" : "asc" // can be 'asc' for ascending order or 'desc' for descending order
   },
   "<sort_field>" : { 
      "order" : "desc" // can be 'asc' for ascending order or 'desc' for descending order
   }
]

The returning content IDs will be sorted by the sort priority defined in Sort JSON. sort_field is the field the post should be sorted by - this can be any of the field Query JSON that is in NumberQuery or TimeQuery format.

Limitations

  • We currently do not support searching within a post’s metadata.

Last updated