Filter
Select a subset of your data based on useful filters
The initialization code used in the following example is outlined in detail on the client installation page.
By Custom Metadata
After you have added inputs with custom metadata, you can search by that metadata.
Below is an example of searching over custom metadata. You can exact match any key
: value
pair no matter how nested it is.
For example, if the metadata on an input is:
{
"keyname": "value1",
"somelist": [1,2,3],
"somenesting": {
"keyname2":"value2",
"list2":[4,5]
}
}
Then the following searches will find this:
{
"keyname": "value1"
}
{
"somelist": [1,2,3]
}
{
"somelist": [1,2]
}
{
"somenesting": {"keyname2":"value2"}
}
{
"somenesting": {"list2":[5]}
}
How to perform searches:
- gRPC Python
- gRPC NodeJS
- gRPC Java
- cURL
################################################################
# In this section, we set the user authentication and app ID.
# Change these strings to run your own example.
################################################################
USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the portal under Authentification
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2
from google.protobuf.struct_pb2 import Struct
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
metadata = (('authorization', 'Key ' + PAT),)
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID) # The userDataObject is required when using a PAT
search_metadata = Struct()
search_metadata.update({"type": "animal"})
post_searches_response = stub.PostSearches(
service_pb2.PostSearchesRequest(
user_app_id=userDataObject,
query=resources_pb2.Query(
ands=[
resources_pb2.And(
input=resources_pb2.Input(
data=resources_pb2.Data(
metadata=search_metadata
)
)
)
]
)
),
metadata=metadata
)
if post_searches_response.status.code != status_code_pb2.SUCCESS:
print(post_searches_response.status)
raise Exception("Post searches failed, status: " + post_searches_response.status.description)
print("Found inputs:")
for hit in post_searches_response.hits:
print("\tScore %.2f for %s" % (hit.score, hit.input.id))
//index.js file
///////////////////////////////////////////////////////////////////
// In this section, we set the user authentication and app ID.
// Change these strings to run your own example.
////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the portal under Authentification
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const { ClarifaiStub, grpc } = require("clarifai-nodejs-grpc");
const stub = ClarifaiStub.grpc();
// This will be used by every Clarifai endpoint call
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key " + PAT);
stub.PostSearches(
{
user_app_id: {
user_id: USER_ID,
app_id: APP_ID
},
query: {
ands: [
{
input: {
data: {
metadata: {
"type": "animal"
}
}
}
}
]
}
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("Post searches failed, status: " + response.status.description);
}
console.log("Found inputs:");
for (const hit of response.hits) {
console.log("\tScore " + hit.score + " for " + hit.input.id);
}
}
);
package com.clarifai.example;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.StatusCode;
import com.google.protobuf.Struct;
import com.google.protobuf.Value;
public class ClarifaiExample {
///////////////////////////////////////////////////////////////////
// In this section, we set the user authentication and app ID.
// Change these strings to run your own example.
////////////////////////////////////////////////////////////////////
static final String USER_ID = "YOUR_USER_ID_HERE";
//Your PAT (Personal Access Token) can be found in the portal under Authentication
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
public static void main(String[] args) {
V2Grpc.V2BlockingStub stub = V2Grpc.newBlockingStub(ClarifaiChannel.INSTANCE.getGrpcChannel())
.withCallCredentials(new ClarifaiCallCredentials(PAT));
MultiSearchResponse postSearchesResponse = stub.postSearches(
PostSearchesRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.setQuery(
Query.newBuilder().addAnds(
And.newBuilder().setInput(
Input.newBuilder().setData(
Data.newBuilder().setMetadata(
Struct.newBuilder()
.putFields("type", Value.newBuilder().setStringValue("animal").build())
)
)
)
)
)
.build()
);
if (postSearchesResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Post searches failed, status: " + postSearchesResponse.getStatus());
}
System.out.println("Found inputs " + postSearchesResponse.getHitsCount() + ":");
for (Hit hit: postSearchesResponse.getHitsList()) {
System.out.printf("\tScore %.2f for %s\n", hit.getScore(), hit.getInput().getId());
}
}
}
curl -X POST "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/searches" \
-H "Authorization: Key YOUR_PAT_HERE" \
-H "Content-Type: application/json" \
-d '{
"query": {
"ands": [
{
"input":{
"data": {
"metadata": {
"type": "animal"
}
}
}
}
]
}
}'
By Geo Location
Search by geo location allows you to restrict your search results to a bounding box based on longitude and latitude points. There are two ways you can provide longitude/latitude points. You can provide one point and a radius or you can provide two points.
It is important to note that a search by geo location acts as a filter and returns results ranked by any other provided search criteria, whether that is a visual search, concept search, or something else. If no other criteria is provided, results will return in the order the inputs were created, NOT by their distance to the center of the search area.
If you are providing one point and a radius, the radius can be in "mile", "kilometer", "degree", or "radian", marked by keywords withinMiles
, withinKilometers
, withinDegrees
, or withinRadians
respectively.
If you are providing two points, a box will be drawn from the uppermost point to the lowermost point, and the leftmost point to the rightmost point.
Before you perform a search by geo location, make sure you have added inputs with longitude and latitude points.
Add Inputs With Longitude and Latitude Points
Provide a geo point to an input. The geo point is a JSON object consisting of a longitude and a latitude in GPS coordinate system (SRID 4326). There can be at most one single geo point associated with each input.
- gRPC Python
- gRPC NodeJS
- gRPC Java
- cURL
##################################################################################
# In this section, we set the user authentication, app ID, and the input details
# we want to add. Change these strings to run your own example.
##################################################################################
USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the portal under Authentification
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change these to add your own input with longitude and latitude points
IMAGE_URL = 'https://samples.clarifai.com/dog.tiff'
LONGITUDE = -30.0
LATITUDE = 40.0
##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
metadata = (('authorization', 'Key ' + PAT),)
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID) # The userDataObject is required when using a PAT
post_inputs_response = stub.PostInputs(
service_pb2.PostInputsRequest(
user_app_id=userDataObject,
inputs=[
resources_pb2.Input(
data=resources_pb2.Data(
image=resources_pb2.Image(
url=IMAGE_URL,
allow_duplicate_url=True
),
geo=resources_pb2.Geo(
geo_point=resources_pb2.GeoPoint(
longitude=LONGITUDE,
latitude=LATITUDE,
)
)
)
)
]
),
metadata=metadata
)
if post_inputs_response.status.code != status_code_pb2.SUCCESS:
print(post_inputs_response.status)
raise Exception("Post inputs failed, status: " + post_inputs_response.status.description)
//index.js file
////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the input details
// we want to add. Change these strings to run your own example.
////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the portal under Authentification
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these to add your own input with longitude and latitude points
const IMAGE_URL = 'https://samples.clarifai.com/dog.tiff';
const LONGITUDE = -30.0;
const LATITUDE = 40.0;
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const { ClarifaiStub, grpc } = require("clarifai-nodejs-grpc");
const stub = ClarifaiStub.grpc();
// This will be used by every Clarifai endpoint call
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key " + PAT);
stub.PostInputs(
{
user_app_id: {
user_id: USER_ID,
app_id: APP_ID
},
inputs: [
{
data: {
image: { url: IMAGE_URL, allow_duplicate_url: true },
geo: {
geo_point: {
longitude: LONGITUDE,
latitude: LATITUDE
}
}
}
}
]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("Post inputs failed, status: " + response.status.description);
}
}
);
package com.clarifai.example;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.StatusCode;
public class ClarifaiExample {
////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and the input details
// we want to add. Change these strings to run your own example.
////////////////////////////////////////////////////////////////////////////////////
static final String USER_ID = "YOUR_USER_ID_HERE";
//Your PAT (Personal Access Token) can be found in the portal under Authentication
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
// Change these to add your own input with longitude and latitude points
static final String IMAGE_URL = "https://samples.clarifai.com/dog.tiff";
static final float LONGITUDE = -30.0f;
static final float LATITUDE = 40.0f;
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
public static void main(String[] args) {
V2Grpc.V2BlockingStub stub = V2Grpc.newBlockingStub(ClarifaiChannel.INSTANCE.getGrpcChannel())
.withCallCredentials(new ClarifaiCallCredentials(PAT));
MultiInputResponse postInputsResponse = stub.postInputs(
PostInputsRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.addInputs(
Input.newBuilder().setData(
Data.newBuilder()
.setImage(
Image.newBuilder()
.setUrl(IMAGE_URL)
.setAllowDuplicateUrl(true)
)
.setGeo(
Geo.newBuilder().setGeoPoint(
GeoPoint.newBuilder()
.setLongitude(LONGITUDE)
.setLatitude(LATITUDE)
)
)
)
).build()
);
if (postInputsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Post inputs failed, status: " + postInputsResponse.getStatus());
}
}
}
curl -X POST "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/inputs" \
-H "Authorization: Key YOUR_PAT_HERE" \
-H "Content-Type: application/json" \
-d '
{
"inputs": [
{
"data": {
"image": {
"url": "https://samples.clarifai.com/dog.tiff",
"allow_duplicate_url": true
},
"geo": {
"geo_point": {
"longitude": -30,
"latitude": 40
}
}
}
}
]
}'
Perform a Search With One Geo Point and Radius in Kilometers
- gRPC Python
- gRPC NodeJS
- gRPC Java
- cURL
#####################################################################################
# In this section, we set the user authentication, app ID, and details of the point
# we want to perform a search with. Change these strings to run your own example.
#####################################################################################
USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the portal under Authentification
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change these to perform your own search
LONGITUDE = -29.0
LATITUDE = 40.0
##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
metadata = (('authorization', 'Key ' + PAT),)
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID) # The userDataObject is required when using a PAT
post_searches_response = stub.PostSearches(
service_pb2.PostSearchesRequest(
user_app_id=userDataObject,
query=resources_pb2.Query(
ands=[
resources_pb2.And(
input=resources_pb2.Input(
data=resources_pb2.Data(
geo=resources_pb2.Geo(
geo_point=resources_pb2.GeoPoint(
longitude=LONGITUDE,
latitude=LATITUDE,
),
geo_limit=resources_pb2.GeoLimit(
type="withinKilometers",
value=150.0
)
)
)
)
)
]
)
),
metadata=metadata
)
if post_searches_response.status.code != status_code_pb2.SUCCESS:
print(post_searches_response)
raise Exception("Post searches failed, status: " + post_searches_response.status.description)
print("Found inputs:")
for hit in post_searches_response.hits:
print("\tScore %.2f for %s" % (hit.score, hit.input.id))
//index.js file
///////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and details of the point
// we want to perform a search with. Change these strings to run your own example.
///////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the portal under Authentification
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these to perform your own search
const LONGITUDE = -29.0;
const LATITUDE = 40.0;
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const { ClarifaiStub, grpc } = require("clarifai-nodejs-grpc");
const stub = ClarifaiStub.grpc();
// This will be used by every Clarifai endpoint call
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key " + PAT);
stub.PostSearches(
{
user_app_id: {
user_id: USER_ID,
app_id: APP_ID
},
query: {
ands: [
{
input: {
data: {
geo: {
geo_point: {
longitude: LONGITUDE,
latitude: LATITUDE
},
geo_limit: {
type: "withinKilometers",
value: 150.0
}
}
}
}
}
]
}
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("Post searches failed, status: " + response.status.description);
}
console.log("Found inputs:");
for (const hit of response.hits) {
console.log("\tScore " + hit.score + " for " + hit.input.id);
}
}
);
package com.clarifai.example;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.StatusCode;
public class ClarifaiExample {
///////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and details of the point
// we want to perform a search with. Change these strings to run your own example.
///////////////////////////////////////////////////////////////////////////////////////
static final String USER_ID = "YOUR_USER_ID_HERE";
//Your PAT (Personal Access Token) can be found in the portal under Authentication
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
// Change these to perform your own search
static final float LONGITUDE = -29.0f;
static final float LATITUDE = 40.0f;
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
public static void main(String[] args) {
V2Grpc.V2BlockingStub stub = V2Grpc.newBlockingStub(ClarifaiChannel.INSTANCE.getGrpcChannel())
.withCallCredentials(new ClarifaiCallCredentials(PAT));
MultiSearchResponse postSearchesResponse = stub.postSearches(
PostSearchesRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.setQuery(
Query.newBuilder().addAnds(
And.newBuilder().setInput(
Input.newBuilder().setData(
Data.newBuilder().setGeo(
Geo.newBuilder()
.setGeoPoint(
GeoPoint.newBuilder()
.setLongitude(LONGITUDE)
.setLatitude(LATITUDE)
)
.setGeoLimit(
GeoLimit.newBuilder()
.setType("withinKilometers")
.setValue(150.0f)
)
)
)
)
)
)
.build()
);
if (postSearchesResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Post searches failed, status: " + postSearchesResponse.getStatus());
}
System.out.println("Found inputs " + postSearchesResponse.getHitsCount() + ":");
for (Hit hit : postSearchesResponse.getHitsList()) {
System.out.printf("\tScore %.2f for %s\n", hit.getScore(), hit.getInput().getId());
}
}
}
curl -X POST "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/searches" \
-H "Authorization: Key YOUR_PAT_HERE" \
-H "Content-Type: application/json" \
-d '{
"query": {
"ands": [
{
"input": {
"data": {
"geo": {
"geo_point": {
"longitude": -29.0,
"latitude": 40.0
},
"geo_limit": {
"type": "withinKilometers",
"value": 150
}
}
}
}
}
]
}
}'
Perform a Search With Two Geo Points
- gRPC Python
- gRPC NodeJS
- gRPC Java
- cURL
#####################################################################################
# In this section, we set the user authentication, app ID, and details of the points
# we want to perform a search with. Change these strings to run your own example.
#####################################################################################
USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the portal under Authentification
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change these to perform your own search
LONGITUDE_1 = -31.0
LATITUDE_1 = 42.0
LONGITUDE_2 = -29.0
LATITUDE_2 = 39.0
##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
metadata = (('authorization', 'Key ' + PAT),)
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID) # The userDataObject is required when using a PAT
post_searches_response = stub.PostSearches(
service_pb2.PostSearchesRequest(
user_app_id=userDataObject,
query=resources_pb2.Query(
ands=[
resources_pb2.And(
input=resources_pb2.Input(
data=resources_pb2.Data(
geo=resources_pb2.Geo(
geo_box=[
resources_pb2.GeoBoxedPoint(
geo_point=resources_pb2.GeoPoint(
longitude=LONGITUDE_1,
latitude=LATITUDE_1,
),
),
resources_pb2.GeoBoxedPoint(
geo_point=resources_pb2.GeoPoint(
longitude=LONGITUDE_2,
latitude=LATITUDE_2,
),
),
]
)
)
)
)
]
)
),
metadata=metadata
)
if post_searches_response.status.code != status_code_pb2.SUCCESS:
print(post_searches_response.status)
raise Exception("Post searches failed, status: " + post_searches_response.status.description)
print("Found inputs:")
for hit in post_searches_response.hits:
print("\tScore %.2f for %s" % (hit.score, hit.input.id))
//index.js file
///////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and details of the points
// we want to perform a search with. Change these strings to run your own example.
///////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the portal under Authentification
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these to perform your own search
const LONGITUDE_1 = -31.0;
const LATITUDE_1 = 42.0;
const LONGITUDE_2 = -29.0;
const LATITUDE_2 = 39.0;
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const { ClarifaiStub, grpc } = require("clarifai-nodejs-grpc");
const stub = ClarifaiStub.grpc();
// This will be used by every Clarifai endpoint call
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key " + PAT);
stub.PostSearches(
{
user_app_id: {
user_id: USER_ID,
app_id: APP_ID
},
query: {
ands: [
{
input: {
data: {
geo: {
geo_box: [
{
geo_point: {
longitude: LONGITUDE_1,
latitude: LATITUDE_1
}
},
{
geo_point: {
longitude: LONGITUDE_2,
latitude: LATITUDE_2
}
}
]
}
}
}
}
]
}
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("Post searches failed, status: " + response.status.description);
}
console.log("Found inputs:");
for (const hit of response.hits) {
console.log("\tScore " + hit.score + " for " + hit.input.id);
}
}
);
package com.clarifai.example;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.StatusCode;
public class ClarifaiExample {
///////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and details of the points
// we want to perform a search with. Change these strings to run your own example.
///////////////////////////////////////////////////////////////////////////////////////
static final String USER_ID = "YOUR_USER_ID_HERE";
//Your PAT (Personal Access Token) can be found in the portal under Authentication
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
// Change these to perform your own search
static final float LONGITUDE_1 = -31.0f;
static final float LATITUDE_1 = 42.0f;
static final float LONGITUDE_2 = -29.0f;
static final float LATITUDE_2 = 39.0f;
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
public static void main(String[] args) {
V2Grpc.V2BlockingStub stub = V2Grpc.newBlockingStub(ClarifaiChannel.INSTANCE.getGrpcChannel())
.withCallCredentials(new ClarifaiCallCredentials(PAT));
MultiSearchResponse postSearchesResponse = stub.postSearches(
PostSearchesRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.setQuery(
Query.newBuilder().addAnds(
And.newBuilder().setInput(
Input.newBuilder().setData(
Data.newBuilder().setGeo(
Geo.newBuilder()
.addGeoBox(
GeoBoxedPoint.newBuilder().setGeoPoint(
GeoPoint.newBuilder()
.setLongitude(LONGITUDE_1)
.setLatitude(LATITUDE_1)
)
)
.addGeoBox(
GeoBoxedPoint.newBuilder().setGeoPoint(
GeoPoint.newBuilder()
.setLongitude(LONGITUDE_2)
.setLatitude(LATITUDE_2)
).build()
)
)
)
)
)
)
.build()
);
if (postSearchesResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Post searches failed, status: " + postSearchesResponse.getStatus());
}
System.out.println("Found inputs " + postSearchesResponse.getHitsCount() + ":");
for (Hit hit : postSearchesResponse.getHitsList()) {
System.out.printf("\tScore %.2f for %s\n", hit.getScore(), hit.getInput().getId());
}
}
}
curl -X POST "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/searches" \
-H "Authorization: Key YOUR_PAT_HERE" \
-H "Content-Type: application/json" \
-d '{
"query": {
"ands": [
{
"input": {
"data": {
"geo": {
"geo_box": [
{
"geo_point": {
"latitude": 42,
"longitude": -31
}
},
{
"geo_point": {
"latitude": 39,
"longitude": -29
}
}
]
}
}
}
}
]
}
}'