# Intelligent Search - Post

## **Introduction**

The Intelligent Search Post API allows users to search for posts with advanced filtering options. The search includes all targets where the user has permission to view posts. However, you can refine the results using specific filters for target types, target IDs, post types, or parent-child relationships.

### **Target Filtering**

By default, the search will include all targets where the user can view posts. However, you can narrow the search scope to a specific target by specifying both the `targetType` and `targetId` together.

* `targetType`: Defines the type of target where the post was created, either `community` or `user` feed.
* `targetId`: The ID of the designated target, i.e, community id when `targetType` is `community`; user id when `targetType` is `user`.

### **Post Filtering**

You can choose to filter specific post types or based on parent-child relationships.

* `matchingOnlyParentPost`
  * When set to `true`, only parent posts are included, excluding child posts from the search.
  * When set to `false`, both parent and child posts are included in the search.
* `postTypes`: Filters posts by type. Currently supports filtering for `text` and `image` posts.

## **Example Use Cases**

### **Search for Text Posts** <a href="#search-for-text-posts" id="search-for-text-posts"></a>

When the user searches for "ice cream," the output may include posts ranked by their relevance score. For example:

```
Text Post 1st: "I love ice cream."
Text Post 2nd: "Ice cream is my favorite dessert."
Text Post 3rd: "Nothing beats a scoop of ice cream on a hot day!"
Text Post 4th: "I enjoy trying different types of pastries."
Text Post 5th: "Cooking is a great way to relax after a long day."
```

### **Search for Image Posts** <a href="#search-for-image-posts" id="search-for-image-posts"></a>

When the user searches for "ice cream," the output may include posts ranked by their relevance score. For example:

<table data-view="cards"><thead><tr><th></th><th></th><th></th><th data-hidden data-card-cover data-type="files"></th></tr></thead><tbody><tr><td></td><td><p><strong>image post — 1st</strong></p><p><strong>caption:</strong> I love ice cream.</p></td><td></td><td><a href="https://2352509137-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MX0mOAVWkotGme0iRzu%2Fuploads%2FpSIGvpnStKSJv3a927k4%2F1.avif?alt=media&#x26;token=3c0a83a5-6f65-46bd-8eed-da3825fc0a5c">1.avif</a></td></tr><tr><td></td><td><p><strong>image post — 2nd</strong></p><p><strong>caption:</strong> &#x3C;no caption></p></td><td></td><td><a href="https://2352509137-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MX0mOAVWkotGme0iRzu%2Fuploads%2FiUYwh46403TFv1hrEBNd%2F2.avif?alt=media&#x26;token=d576daf2-c417-45f2-836f-8a3ad7f92bb1">2.avif</a></td></tr><tr><td><p></p><p><strong>image post — 3rd</strong></p><p><strong>caption:</strong> food on my table!</p></td><td></td><td></td><td><a href="https://2352509137-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MX0mOAVWkotGme0iRzu%2Fuploads%2FVslFLytCp845q59Fp0LS%2F3.avif?alt=media&#x26;token=4d896cf6-87e0-4fa1-9e46-65af01db5fc7">3.avif</a></td></tr></tbody></table>

The following code snippet demonstrates how to search for text and image posts across the entire network. Users can filter the results to display only text, images, or both, depending on their preference.

{% tabs %}
{% tab title="iOS" %}
{% embed url="<https://gist.github.com/amythee/458cd0240139113df1e1ae4cadb34268#file-semantic_search_posts-swift>" %}
{% endtab %}

{% tab title="Android" %}
{% embed url="<https://gist.github.com/amythee/4fcd7690cee86b4f388074ee497fac7b#file-amitypostsearch-kt>" %}
{% endtab %}

{% tab title="Typescript" %}
{% embed url="<https://gist.github.com/amythee/74eed63fb6535e4385b09d1acaf60209>" %}
{% endtab %}
{% endtabs %}

### Limitations <a href="#limitations" id="limitations"></a>

* Currently, the search only supports text and image posts; other post types are not included.
* The search function only considers the context of individual posts. It does not consider the relationship between parent posts, their replies, or comments.
