Constructor

/*
 Constructors are not exposed in the JS/Node SDK.
 SearchResult objects are returned by search and scroll Collection methods.
 */

kuzzle.collection('collection', 'index').search({}, (error, searchResult) => {
  // searchResult is a SearchResult object
});
JSONObject filter = new JSONObject();

kuzzle
  .collection("collection", "index")
  .search(filter, new ResponseListener<SearchResult>() {
    @Override
    public void onSuccess(SearchResult searchResult) {
      for (Document doc : result.getDocuments()) {
        // fetched documents
      }

      result.getTotal(); // returns the total number of documents returnable

      result.getAggregations(): // returns a JSONObject representing the aggregations response
    }

    @Override
    public void onError(JSONObject error) {
      // Handle error
    }
  });
<?php

use \Kuzzle\Kuzzle;


$filters = (object) [];

$kuzzle = new Kuzzle('localhost');
$dataCollection = $kuzzle->collection('collection', 'index');

try {
  $searchResult = $dataCollection->search($filters);

  // $searchResult instanceof SearchResult
  $searchResult->getTotal();

  foreach($searchResult->getDocuments() as $document) {
    // $document instanceof Document
  }

  // return an array representing the aggregations response
  $searchResult->getAggregations();
}
catch (ErrorException $e) {

}

This object is the result of a search or a scroll request, allowing to manipulate the result and do subsequent requests.


SearchResult(collection, total, documents, aggregations, options, filters, [previous])

ArgumentsTypeDescription
collectionCollectionAn instantiated Collection object
totalintegerThe total number of results of the search/scroll request
documentsDocument[]An array of instantiated Document objects
aggregationsobjectThe result of an aggregation produced by a search request
optionsobjectThe arguments of the search/scroll request
filtersobjectThe filters of the search request
previousSearchRequestThe previous SearchResult produced by a previous search/scroll request (see fetchNext)

Note: this constructor is meant to be called internally when retrieving results from a search or a scroll request.


Properties

Property nameTypeDescriptionget/set
aggregationsobjectThe result of an aggregation produced by a search requestget
collectionCollectionThe data collection associated to this documentget
documentsDocument[]An array of instantiated Document objectsget
fetchedDocumentnumberRepresents the offset of the last document in the current SearchResult setget/set
optionsobjectThe arguments of the search/scroll requestget
filtersobjectThe filters of the search requestget
totalintegerThe total number of results of the search/scroll requestget

Getters

Getter nameTypeDescription
getAggregations()objectReturns the aggregation property value
getCollection()CollectionReturns the collection property value
getDocuments()Document[]Returns the documents property value
getFetchedDocument()numberReturns the fetchedDocument property value
getOptions()objectReturns the options property value
getFilters()objectReturns the filters property value
getTotal()integerReturns the total property value