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:
using System.Threading.Tasks;
using Clarifai.API;
using Clarifai.DTOs.Searches;
using Newtonsoft.Json.Linq;
namespace YourNamespace
{
public class YourClassName
{
public static async Task Main()
{
var client = new ClarifaiClient("YOUR_API_KEY");
var metadata = new JObject();
metadata.Add("isPuppy", true);
await client.SearchInputs(
SearchBy.Metadata(metadata))
.Page(1)
.ExecuteAsync();
}
}
}
// Search by metadata only.
[_app searchByMetadata:@{@"my_key": @[@"my", @"values"]} page:@1 perPage:@20 completion:^(NSArray<ClarifaiSearchResult *> *results, NSError *error) {
// Print output of first search result.
NSLog(@"inputID: %@", results[0].inputID);
NSLog(@"URL: %@", results[0].mediaURL);
NSLog(@"probability of input matching search query: %@", results[0].score);
}];
// Search metadata in conjunction with other ClarifaiSearchTerms. For example, the
// following will search for inputs with predicted tag "fast" and matching metadata.
ClarifaiConcept *conceptFromGeneralModel = [[ClarifaiConcept alloc] initWithConceptName:@"fast"];
ClarifaiSearchTerm *searchTerm1 = [ClarifaiSearchTerm searchByPredictedConcept:conceptFromGeneralModel];
ClarifaiSearchTerm *searchTerm2 = [ClarifaiSearchTerm searchInputsWithMetadata:@{@"my_key": @[@"my", @"values"]}];
[app search:@[searchTerm1, searchTerm2] page:@1 perPage:@20 completion:^(NSArray<ClarifaiSearchResult *> *results, NSError *error) {
// Print output of first search result.
NSLog(@"inputID: %@", results[0].inputID);
NSLog(@"URL: %@", results[0].mediaURL);
NSLog(@"probability of input matching search query: %@", results[0].score);
}];
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 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, withinRadians.
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.
import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.*;
// Insert here the initialization code as outlined on this page:
// https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
MultiInputResponse postInputsResponse = stub.postInputs(
PostInputsRequest.newBuilder().addInputs(
Input.newBuilder().setData(
Data.newBuilder()
.setImage(
Image.newBuilder()
.setUrl("https://samples.clarifai.com/dog.tiff")
.setAllowDuplicateUrl(true)
)
.setGeo(
Geo.newBuilder().setGeoPoint(
GeoPoint.newBuilder()
.setLongitude(-30)
.setLatitude(40)
)
)
)
).build()
);
if (postInputsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Post inputs failed, status: " + postInputsResponse.getStatus());
}
// Insert here the initialization code as outlined on this page:
// https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
stub.PostInputs(
{
inputs: [
{
data: {
image: {url: "https://samples.clarifai.com/dog.tiff", allow_duplicate_url: true},
geo: {
geo_point: {
longitude: -30,
latitude: 40
}
}
}
}
]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("Post inputs failed, status: " + response.status.description);
}
}
);
# Insert here the initialization code as outlined on this page:
# https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions
post_inputs_response = stub.PostInputs(
service_pb2.PostInputsRequest(
inputs=[
resources_pb2.Input(
data=resources_pb2.Data(
image=resources_pb2.Image(
url="https://samples.clarifai.com/dog.tiff",
allow_duplicate_url=True
),
geo=resources_pb2.Geo(
geo_point=resources_pb2.GeoPoint(
longitude=-30.0,
latitude=40.0,
)
)
)
)
]
),
metadata=metadata
)
if post_inputs_response.status.code != status_code_pb2.SUCCESS:
raise Exception("Post inputs failed, status: " + post_inputs_response.status.description)
app.inputs.create({
url: "https://samples.clarifai.com/puppy.jpeg",
geo: { longitude: 116.2317, latitude: 39.5427},
}).then(
function(response) {
// do something with response
},
function(err) {
// there was an error
}
);
using System.Threading.Tasks;
using Clarifai.API;
using Clarifai.DTOs;
using Clarifai.DTOs.Inputs;
namespace YourNamespace
{
public class YourClassName
{
public static async Task Main()
{
var client = new ClarifaiClient("YOUR_API_KEY");
await client.AddInputs(
new ClarifaiURLImage(
"https://samples.clarifai.com/puppy.jpeg",
geo: new GeoPoint(116.2317M, 39.5427M)))
.ExecuteAsync();
}
}
}
using System.Threading.Tasks;
using Clarifai.API;
using Clarifai.DTOs;
using Clarifai.DTOs.Searches;
namespace YourNamespace
{
public class YourClassName
{
public static async Task Main()
{
var client = new ClarifaiClient("YOUR_API_KEY");
await client.SearchInputs(
SearchBy.Geo(
new GeoPoint(59M, 29.75M),
new GeoRadius(500, GeoRadius.RadiusUnit.WithinKilometers)))
.Page(1)
.ExecuteAsync();
}
}
}
using System.Threading.Tasks;
using Clarifai.API;
using Clarifai.DTOs;
using Clarifai.DTOs.Searches;
namespace YourNamespace
{
public class YourClassName
{
public static async Task Main()
{
var client = new ClarifaiClient("YOUR_API_KEY");
await client.SearchInputs(
SearchBy.Geo(
new GeoPoint(3M, 0M),
new GeoPoint(70M, 30M)))
.Page(1)
.ExecuteAsync();
}
}
}