Api clients / JavaScript / V3 / Methods

Find Object | JavaScript API Client V3 (Deprecated)

This version of the JavaScript API client has been deprecated in favor of the latest version of the JavaScript API client.

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

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.

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 request options sent along with the request.

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?