# Search

### Search Client

Also you can search for records using our search client library which helps to reduce overheads of creating JSON request

Read more [here](https://www.npmjs.com/package/@gaspl/search-client)

#### Attributes

<table><thead><tr><th width="144.59991455078125">Field</th><th width="169.4000244140625">Type</th><th width="336.199951171875">Description</th><th>Default Value</th></tr></thead><tbody><tr><td>searchFields</td><td>[array, optional]</td><td>Search would be applied on the fields defined here. For instance - Name, Price, Category can be made searchable fields</td><td></td></tr><tr><td>textFacets</td><td>[array, optional]</td><td><p>Text facets to be retrieved. For each of the retrieved facets (eg. color; size; brand), the response will contain a list of facet values (red, blue; small, large; zara…) and associated count of records for that facet value. You would be require to configure facets on the SearchTap dashboard for the collection before fetching its data. If not configured, you would receive an error.<br></p><pre class="language-json"><code class="lang-json">"textFacets": ["vendor","category"]
</code></pre></td><td></td></tr><tr><td>textFacetFilters</td><td>[optional]</td><td><p>Further refine your search results by defining specific values of a text facet. For instance, if you wish to show results for specific brands only (zara &#x26; tommy hilfiger) while applying the facet 'Brand' - use following syntax. The default behavior is to apply no filters.<br></p><pre class="language-json"><code class="lang-json">"textFacetFilters": {
  "vendor": ["parle","britania"],
  "category": ["biscuit","snacks"]
 }
</code></pre></td><td></td></tr><tr><td>numericFacets</td><td>[optional]</td><td><p>Numeric facets as the name suggests, are facets with numeric values (eg. price, age). .numericFacets let's you define the ranges you want to show to the end user along with count of records in that range. You can use the same to create a histogram slider for your front-end UI. You would be require to configure facets on the SearchTap dashboard for the collection before fetching its data. If not configured, you would receive an error. The default behavior is to not fetch any numeric facet value.<br></p><pre class="language-json"><code class="lang-json">"numericFacets": {
  "price": ["[0,100)","[200,300)"]
  }
</code></pre></td><td></td></tr><tr><td>numericFacetsFilters</td><td>[optional]</td><td><p>Let's you define a lower and an upper bound value for a numeric facet to fetch results lying within the range. The default behavior is to apply no filter.<br></p><pre class="language-json"><code class="lang-json">"numericFacetFilters": {
  "price": ["[0,100)"],
  "discount": ["[0,10)","[10,60)"]
}         
</code></pre></td><td></td></tr><tr><td>filter</td><td>[String, optional]</td><td>Define criteria to further refine your search results. For instance, you can choose to remove Out of Stock" items from the search result page or show only the discounted products with 10% off or more by using following syntax. You can also combine multiple filter conditions by using keywords such as AND, OR, NOT. Feel free to group conditions using brackets (...)</td><td></td></tr><tr><td>geo</td><td>[optional]</td><td>geo Search is a way to refine search results by distance around a given lat, lng co-ordinates. The function is defined as - searchClient.geo(lat,lng, radius), where lat is latitude, lng is longitude and radius is the maximum radius to search around the position (in meters). When provided .geo(...) filter, results are sorted distance wise from the provided lat,lng, upto the radius provided. All results beyond the provided radius are removed from the results. If no radius is provided, results will not be limited but still be sorted on basis of distance from provided lat,lng. The default behavior is to not apply any geo filter.</td><td></td></tr><tr><td>skip</td><td>[number, optional]</td><td>It is used in pagination to bypass a specified number of search results and then return the remaining results. The default value set for skip is 0.</td><td>0</td></tr><tr><td>count</td><td>[number, optional]</td><td>Defines how many results you want to fetch for the given search query. The default value is 30.</td><td>30</td></tr><tr><td>facetCount</td><td>[number, optional]</td><td>Defines the number of items you want to fetch for a defined facet.</td><td>100</td></tr><tr><td>sort</td><td>[array, optional]</td><td>It can be used to further sort the results. For example - Price low to high would display results starting from low price value to high.</td><td></td></tr><tr><td>typoTolerance</td><td>[number, optional]</td><td>Results with typos can also be shown in search results. By default, search queries with only 1 typo will be fetched.</td><td>queries with only 1 typo will be fetched.</td></tr><tr><td>groupBy</td><td>[string,optional]</td><td><p>Get aggregated search results based on specified field critera<br></p><pre class="language-json"><code class="lang-json">"groupBy": "vendor" 
</code></pre></td><td></td></tr><tr><td>groupCount</td><td>[number,optional]</td><td><p>Max records under single group<br></p><pre class="language-json"><code class="lang-json">"groupCount": 2
</code></pre></td><td></td></tr></tbody></table>

#### Search records

<mark style="color:red;">`POST https://<app-unique-id>.fast.searchtap.net/v2`</mark>

Sample Body

```
{
  "query": "",
  "fields": [
    "f3",
    "f4"
  ],
  "textFacets": [
    "vendor",
    "category"
  ],
  "searchFields": [
    "title",
    "price"
  ],
  "filter": "",
  "sort": [
    "price",
    "discount"
  ],
  "skip": 0,
  "count": 30,
  "collection": "",
  "facetCount": 100,
  "groupCount": 2,
  "typoTolerance": 1,
  "textFacetFilters": {
    "vendor": [
      "parle",
      "britania"
    ],
    "category": [
      "biscuit",
      "snacks"
    ]
  },
  "numericFacets": {
    "price": [
      "[0,100)",
      "[200,300)"
    ],
    "discount": [
      "[0,10)",
      "[10,60)",
      "[60,100)"
    ]
  },
  "numericFacetFilters": {
    "price": [
      "[0,100)"
    ],
    "discount": [
      "[0,10)",
      "[10,60)"
    ]
  },
  "groupBy": "vendor"
}
```

Response JSON

```
{
  "query": {
    "query": "yourQuery",
    "fields": [
      "*"
    ],
    "textFacets": null,
    "highlightFields": null,
    "searchFields": null,
    "filter": null,
    "sort": null,
    "skip": 0,
    "collection": "UNIQUECOLLECTIONID",
    "facetCount": 100,
    "count": 10,
    "groupBy": null,
    "groupCount": -1,
    "typoTolerance": 1,
    "textFacetFilters": {

    },
    "numericFacets": {

    },
    "numericFacetFilters": {

    },
    "filters": [

    ],
    "geo": null
  },
  "results": [

  ],
  "textFacets": {

  },
  "numericFacets": {

  },
  "responseTime": 3,
  "totalHits": 0
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://greenapplesolutions.gitbook.io/greenapplesolutions-docs/search.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
