Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #24660 correct api search description #262

Merged
merged 5 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions docs/API/search.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ You can use the search engine via the `GET /api/v1/search` endpoint to search th
| aggregate_by[] | array | Fields to aggregate results. The expected format: `aggregate_by[]=name&aggregate_by[]=slug` |
| aggregate_by_numeric[] | array | Fields to aggregate results by numeric values. The expected format: `aggregate_by_numeric[]=price&aggregate_by_numeric[]=count` |
| filters[] | array | Filter by object properties. The expected format: `filters[propertyName]=value1&filters[propertyName2]=value2`. Follows the rules of the [ElasticSearch Query String Query](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html). |
| geo_filters | array | Filter by object geolocation properties. Example value: `geo_distance,1.50km,40.1,-19.2` which means: `filter name`, `distance`, `latitude`, `longitude`. For more information see [ElasticSearch docs](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-distance-query.html). Only `geo_distance` query is supported. |
| geo_filters | array | Filter by object geolocation properties. Example value: `geo_distance,1.50km,40.1,-19.2` which means: `filter name`, `distance`, `latitude` and `longitude`. For more information see [ElasticSearch docs](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-distance-query.html). Only the `geo_distance` query is supported. |
| post_filters | array | Filter by object properties. Use it when you want aggregated counts without filters applied. Expected format: `filters[propertyName]=value1&filters[propertyName2]=value2` |
| fields[] | array | List of content fields to be searched. The expected format: `fields[]=field1&fields[]=field2` |
| order_by | string | Name of the field to sort results by (they are always primarily sorted by `_score`) |
Expand Down Expand Up @@ -74,23 +74,35 @@ Response:

## Limit the search to a specific Content Type

You can easily limit the search to a specific Content Type by providing its name in `content_type[]` argument.
You can easily limit the search to a specific Content Type by providing its name in the `content_type[]` argument.

## Order by content field

You can sort the results from the search endpoint by Content Type's field using an "order_by" parameter:

!!! Example
GET https://api.flotiq.com/api/v1/search?q=Flotiq&content_type[]=post&**order_by=date**

Keep in mind that ordering by a field that is nested in the `object` input type (list) is not possible.

!!! Note
You may also use the `.keyword` suffix for other data than text fields, for example, if you are using an `id` field that uses a `number` type in Flotiq, you may still want to consider using the `.keyword` suffix when ordering by such field. This will result in slightly faster searching and will sort objects by id alphabetically, not from the highest number to the lowest.

## Limit the search to a specific field

You can restrict querying to a specific field by passing the `fields[]` argument, for example `fields[]=name` would only search in the `name` field.
You can restrict queries to a specific field by passing the `fields[]` argument, for example, `fields[]=name` would only search in the `name` field.

## Increase scoring for specific fields

If you'd like to search in several fields but give better score to results that match the query in a specific field - you can use [ElasticSearch's field boosting](https://www.elastic.co/guide/en/elasticsearch/reference/7.6/query-dsl-query-string-query.html#query-string-multi-field) to promote fields. In order to do that - pass the fields and their weights through the `fields[]` argument, for example `fields[]=title^3&fields[]=content^1` would assign a weight of 3 to the `title` field and a weight of 1 to `content` field.
If you'd like to search in several fields but give better score to results that match the query in a specific field - you can use [ElasticSearch's field boosting](https://www.elastic.co/guide/en/elasticsearch/reference/7.6/query-dsl-query-string-query.html#query-string-multi-field) to promote fields. In order to do that - pass the fields and their weights through the `fields[]` argument, for example, `fields[]=title^3&fields[]=content^1` would assign a weight of 3 to the `title` field and a weight of 1 to the `content` field.

## Aggregate results by field

If you'd like to display faceted results of your searches you can use the `aggregate_by[]` param. Add `aggregate_by[]=category` to aggregate by the `category` field. This works best with fields that have discreet values (like status, category, etc), and only works with string fields, if you wish to aggregate with numeric fields, use `aggregate_by_numeric[]` param.

## Get random content objects

You can use the `random_seed` parameter to retrieve random content objects. The `random_seed` parameter accepts a number value for a random number generator. This will sort data in random order, so if you want for example to retrieve two random content objects, you can pass any number to `random_seed` and set `limit` parameter value to 2.
You can use the `random_seed` parameter to retrieve random content objects. The `random_seed` parameter accepts a number value for a random number generator. This will sort data in random order, so if you want for example to retrieve two random content objects, you can pass any number to `random_seed` and set the `limit` parameter value to 2.

!!! Note
Since random_seed is changing the order of retrieved content objects, it will override the value of your `order_by` parameter.
18 changes: 9 additions & 9 deletions docs/Deep-Dives/storing-location-data-headless-cms.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: This tutorial shows how to build a store locator webpage using Flot

# Storing location data

Flotiq plays really well with location data, especially once you get to use our search capabilities. In this quick tutorial we'll build a very simple web page that displays locations on a map and allows to easily search your location database.
Flotiq plays really well with location data, especially once you get to use our search capabilities. In this quick tutorial, we'll build a very simple web page that displays locations on a map and allows you to easily search your location database.

What we'll need:

Expand All @@ -13,14 +13,14 @@ What we'll need:
- A scoped API key
- Some HTML, CSS and plain Javascript (to keep things simple).

And here's a sneak peak at what we'll build.
And here's a sneak peek at what we'll build.

![Flotiq-based store locator](images/store-locator-1.png){: .center .border .width75}


## Setting up Flotiq

Once you [registered a Flotiq account](https://editor.flotiq.com/register.html) and logged in, you'll have to create a new Content Type Definition. This is how you tell Flotiq what kind of data you will be dealing with. Mine looks like this:
Once you [register a Flotiq account](https://editor.flotiq.com/register.html) and log in, you'll have to create a new Content Type Definition. This is how you tell Flotiq what kind of data you will be dealing with. Mine looks like this:

![Store Content Type Definition](images/store-locator-2.png){: .center .border .width75}

Expand All @@ -30,7 +30,7 @@ Next - create several Content Objects under the `Store` type. I added 3 shops in

![Store entries in grid](images/store-locator-3.png){: .center .border .width75}

Finally - setup a scoped API key - you'll need it in a moment.
Finally - set up a scoped API key - you'll need it in a moment.

## Building the page

Expand Down Expand Up @@ -180,7 +180,7 @@ You will need to populate the `TOKEN` constant with your API key, copied from Fl
{ data-search-exclude }

!!! warning
We strongly recommend to create a dedicated key for every application you build and explicitly define the access scope to cover only the least amount of privileges required for a given app. Read more about [Flotiq's scoped API keys](https://flotiq.com/docs/API/#user-defined-api-keys) in our docs.
We strongly recommend creating a dedicated key for every application you build and explicitly defining the access scope to cover only the least amount of privileges required for a given app. Read more about [Flotiq's scoped API keys](https://flotiq.com/docs/API/#user-defined-api-keys) in our docs.

Now, define the `loadMarkers()` function, like this:

Expand Down Expand Up @@ -449,7 +449,7 @@ A neat, yellow box with a positioning icon should appear in your browser:

![Browser location can be used to navigate the map](images/store-locator-6.png){: .center .border .width75}

Let's now add an input field and connect the geocodeing service to translate location names to coordinates.
Let's now add an input field and connect the geocoding service to translate location names to coordinates.

Add a text input to the yellow overlay:
```
Expand Down Expand Up @@ -502,7 +502,7 @@ Now, let's add an event handler on the form's submit event. Once a user submits
```
{ data-search-exclude }

You can now put cities or full addresses in the text input. When you submit the form - your map should automatically move to the address you entered and the nearby stores should load.
You can now put cities or full addresses in the text input. When you submit the form - your map should automatically move to the address you entered and the nearby stores should load.

## Final touches

Expand Down Expand Up @@ -539,7 +539,7 @@ with
```
{ data-search-exclude }

This should provide standard maps popovers, if you'd like to give them some extra style - add this to the CSS file and adjust to your needs:
This should provide standard maps popovers if you'd like to give them some extra style - add this to the CSS file and adjust to your needs:

```
.leaflet-popup-content-wrapper {
Expand Down Expand Up @@ -637,6 +637,6 @@ and finally - drop this at the end of the `onMarkersLoaded()` function:
```
{ data-search-exclude }

That's it! You should now have a fully working webpage, which will display the list of stores you store in Flotiq and will place the store's on a map. Look into our [Git repository](https://github.com/flotiq/flotiq-demo-storing-location-data) for some extra style and let us know in the comments when you build something!
That's it! You should now have a fully working webpage, which will display the list of stores you store in Flotiq and will place the stores on a map. Look into our [Git repository](https://github.com/flotiq/flotiq-demo-storing-location-data) for some extra style and let us know in the comments when you build something!

![The final result - store locator webpage with data dynamically pulled from Flotiq](images/store-locator-7.png){: .center .border .width75}
4 changes: 2 additions & 2 deletions docs/panel/webhooks/hosted-webhook.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Example Use Cases:

## Setting Up Hosted Sync Webhooks

Creating a Hosted Sync Webhook follows a similar process as for sync webhooks. Once you select the type of your webhook to "synchronous", you will be presented with radio option, allowing you to choose between a standard URL webhook or hosted webhook.
Creating a Hosted Sync Webhook follows a similar process as for sync webhooks. Once you select the type of your webhook to "synchronous", you will be presented with a radio option, allowing you to choose between a standard URL webhook or hosted webhook.

Once you choose the "Code" option, an embedded code editor will show up, allowing you to easily write code for your hosted webhook without the need for the use of any IDE. The editor will contain example code snippets; one of which allows you to validate the target content object, and the second example that will mutate the content object, automatically creating a slug from the title property.

Expand Down Expand Up @@ -52,7 +52,7 @@ function _webhook(ctx) {
```
{ data-search-exclude }

This hosted webhok could be used to easily increment the number of the posts, when duplicating existing objects, or counting the number of edits on an event.
This hosted webhook could be used to easily increment the number of posts when duplicating existing objects, or counting the number of edits on an event.

### Generating a Slug

Expand Down
Loading