API Reference / API Methods / Search / Find Object
Required API Key: any key with the search ACL
Method signature
$index->findObject(function callback)

$index->findObject(function callback, {
    // All the following parameters are optional
    'query' => string,
    'paginate' => bool
})

About this method

You are currently reading the JavaScript API client v4 documentation. Check our migration guide to learn how to upgrade from v3 to v4. You can still access the v3 documentation.

You are currently reading the Ruby API client v2 documentation. Check our migration guide to learn how to upgrade from v1 to v2. You can still access the v1 documentation.

Find an object by the given condition. Can be used to debug relevance.

findObject may be used to debug the relevance of a specific object. This method accepts a condition and returns the first matching object along with its position information in the result set.

The findObject method uses search internally so it can also retrieve the position for a given query. For simply retrieving an object, you can use the more efficient getObjects method instead.

Examples

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$index->findObject(function($obj) {
  return array_key_exists('firstname', $obj) && 'Jimmie' === $obj['firstname'];
});

// With a query
$options1 = [ 'query' => 'query string' ];
$index->findObject(function($obj) {
  return array_key_exists('firstname', $obj) && 'Jimmie' === $obj['firstname'];
}, $options1);

// With a query and only the first page
$options2 = [ 'query' => 'query string', 'paginate' => false ];
$index->findObject(function($obj) {
  return array_key_exists('firstname', $obj) && 'Jimmie' === $obj['firstname'];
}, $options2);

Parameters

callback
type: function
Required

The callback used to find the object.

query
type: string
default: empty string
Optional

The query used to search.

paginate
type: boolean
default: true
Optional

Whether to paginate the search results.

requestOptions
type: key/value mapping
default: No request options
Optional

A mapping of requestOptions to send along with the request. In addition to sending extra HTTP headers or setting timeouts, you can use requestOptions to specify search parameters, when using this method.

index
type: string
Required

Only for Scala - The name of the index to query.

Response

In this section we document the JSON response returned by the API. Each language will encapsulate this response inside objects specific to the language and/or the implementation. So the actual type in your language might differ from what is documented.

JSON format

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
{
  "object": {
    "firstname": "Jimmie",
    "lastname": "Barninger",
    "_highlightResult": {
      "firstname": {
        "value": "<em>Jimmie</em>",
        "matchLevel": "partial"
      },
      "lastname": {
        "value": "Barninger",
        "matchLevel": "none"
      },
      "company": {
        "value": "California <em>Paint</em> & Wlpaper Str",
        "matchLevel": "partial"
      }
    }
  },
  "position": 0,
  "page": 0
}
object
key/value mapping

The hit matching your callback.

A hit is made of the schemaless JSON object that you stored in the index.

However, Algolia enriches them with additional fields like _highlightResult.

object: {
    field1 : "",
    field2 : "",
    [...],

    _highlightResult: {
      [...]
    }
}
position
integer

Number of the matching object’s position in the result set (zero-based).

page
integer

Number of the current page (zero-based). See the page search parameter.

Did you find this page helpful?