Full-Text Search
Once you have your SDK for your preferred language installed, you can start performing full-text, vector, and hybrid search queries on Orama Cloud.
The client exposes a simple search
method that can be used to query the index:
Sorting
To perform sorting, Orama Cloud uses the properties defined in the schema
to know on which properties you want to perform sorting.
Considering the following schema:
With Orama Cloud, you can set up to three sorting properties. This means that you can sort by up to three properties at the same time.
So, considering the following schema:
You can sort by year
and meta.rating
at the same time:
In that case, “year” will be the primary sorting property, and “meta.rating” will be the secondary sorting property. In case of a tie, the secondary sorting property will be used to break the tie.
Facets
Facets are a powerful tool for filtering and narrowing down search results on the Orama search engine.
With the Orama Faceted Search API, users can filter their search results by various criteria, such as category, price range, or other attributes, making it easier to find the information they need. Whether you’re building a website, mobile app, or any other application, the Orama Faceted Search API is the perfect solution for adding faceted search functionality to your project.
Given the following Orama schema:
Orama will be able to generate facets at search-time based on the schema. To do so, we need to specify the facets
property in the search
configuration:
This will generate the following result:
As you may have noticed, the facets
property is an object
that contains different configurations depending on the property type specified in the schema.
String facets
If a property is specified as string
in the schema, the facet will accept the following
configuration:
Property | Type | Default | Description |
---|---|---|---|
order | string | DESC | Order of the values. Can be either ASC or DESC . |
limit | number | 10 | Maximum number of values to return. |
offset | number | 0 | Number of values to skip. |
In the search result, string
facets will be returned as an object
with the following properties:
Number facets
If a property is specified as number
in the schema, the facet will accept the following
configuration:
Property | Type | Default | Description |
---|---|---|---|
ranges | array | [] | Array of ranges to consider. |
Each range is an object
with the following properties:
Property | Type | Description |
---|---|---|
from | number | Minimum value of the range. |
to | number | Maximum value of the range. |
In the search result, number
facets will be returned as an object
with the following properties:
Please note that the from
and to
values are inclusive. Note also that the order of the ranges
is guaranteed as specified in the configuration.
Boolean facets
If a property is specified as boolean
in the schema, the facet will accept the following
configuration:
Property | Type | Default | Description |
---|---|---|---|
true | boolean | true | Whether to consider true values. |
false | boolean | true | Whether to consider false values. |
In the search result, boolean
facets will be returned as an object
with the following properties:
Enum facets
If a property is specified as enum
in the schema, no configuration is required.
In the search result, enum
facets will be returned as an object
with the following properties:
Filters
You can use the filters
interface to filter the search results.
Filters are available for numeric, boolean, string, enum, and geopoint properties. Depending on the type of the property, you can use different operators.
Filtering by string properties
On string
properties it performs an exact matching on tokens so it is advised to disable stemming for the properties
you want to use filters on (when using the default tokenizer you can provide the stemmerSkipProperties
configuration property).
If we consider the following schema:
The results
will contain all documents that contain the word prestige
in the title
property and have tags
property equal to new
.
You can also specify a list of string, in this case, it will return all documents that contain at least one of the values provided:
Filtering by number
properties
The number
properties supports the following operators:
Operator | Description | Example |
---|---|---|
gt | Greater than | year: { gt: 2000 } |
gte | Greater than or equal to | year: { gte: 2000 } |
lt | Less than | year: { lt: 2000 } |
lte | Less than or equal to | year: { lte: 2000 } |
eq | Equal to | year: { eq: 2000 } |
between | Between two values (inclusive) | year: { between: [2000, 2008] } |
So, considering the following schema:
You can filter the results by the meta.rating
property as follows:
Filtering by boolean properties
For boolean properties, you can simply set the property to true
or false
:
Filtering by enum properties
The enum properties support the following operators:
Operator | Description | Example |
---|---|---|
eq | Equal to | genre: { eq: 'drama' } |
in | Contained in the given array | genre: { in: ['drama', 'horror'] } |
nin | Not contained in the given array | genre: { nin: ['commedy'] } |
Filtering by Enum[] properties
The enum properties support the following operators:
Operator | Description | Example |
---|---|---|
containsAll | Contains all the given values | genre: { containsAll: ['comedy', 'action'] } |
Geosearch
Geosearch is a feature that allows you to filter your search results by distance from a given location, or by bounding box.
To perform geosearch queries, you first have to define a new geopoint
property inside your schema definition when creating your Orama instance:
What are geopoints
A geopoint is an object with two properties: lat
and lon
, which are both numbers. For reference, the following is a valid geopoint:
As you may guess, lat
stands for latitude, and lon
for longitude. The values are expressed in degrees, and can be positive or negative.
Inserting documents with geopoints
When inserting documents containing geopoints, you’ll have to provide the lat
and lon
properties as floating-point numbers. For example, considering the following schema:
We would have to insert the following docs:
Given the points above, we can picture them on a map as follows:
To avoid confusion, please note that Orama is a full-text and vector search library. We do not provide the tools to draw on maps.
Now that we have some data, let’s see how we can perform geosearch queries.
Performing geosearch queries
When performing geosearch queries, we have to decide whether we want to filter our results by distance from a given location, or by bounding polygon.
When filtering by distance, we select a central coordinate and a radius of a given length, and we return all the documents that are within that radius from the central coordinate.
When filtering by bounding polygon, we select a polygon on the map, and we return all the documents that are within that polygon.
Filtering by distance (radius)
To filter by distance, we use the radius
property. Let’s see how it works:
The geopoint { lat: 45.4648, lon: 9.18998 }
represents the entrance of the Vittorio Emanuele II Gallery in Milan, nearby the Duomo.
If we follow the configuration above, we are asking Orama to return all the documents that are within 100 meters from the Gallery, as shown in the following map:
The query above will return only one result indeed: the Piazza Duomo document.
If we change the inside
property to false
, we will get the opposite result: all the documents that are outside the radius.
Supported units of measurement
Orama currently supports the following units of measurement:
cm
(centimeters)m
(meters)km
(kilometers)ft
(feet)yd
(yards)mi
(miles)
All these units will be converted into meters automatically. If you feel like we should support other units of measurement, please open an issue
Filtering by bounding polygon
To filter by bounding polygon, we use the polygon
property. Let’s see how it works:
If we try to draw the polygon above on our map, we will get the following result:
The query above will return only one result: Piazza Duomo. This is because it will filter all the documents inside the polygon whose name
property contains the term "Duomo"
.
If you want to return all the points outside the polygon, you can set the inside
property to false
.