public function SearchApiQuery::execute in Search API 7
Executes this search query.
Return value
array An associative array containing the search results. The following keys are standardized:
- 'result count': The overall number of results for this query, without range restrictions. Might be approximated, for large numbers, or skipped entirely if the "skip result count" option was set on this query.
- results: An array of results, ordered as specified. The array keys are
the items' IDs, values are arrays containing the following keys:
- id: The item's ID.
- score: A float measuring how well the item fits the search.
- fields: (optional) If set, an array containing some field values
already ready-to-use. This allows search engines (or postprocessors)
to store extracted fields so other modules don't have to extract them
again. This fields should always be checked by modules that want to
use field contents of the result items. The format of the array is
field IDs (as used by the Search API internally) mapped to either the
raw value of the field (scalar or array value), or an associative
array with the following keys:
- #value: The raw field value.
- #sanitize_callback: The callback to use for sanitizing the field value for HTML output, or FALSE to state that the field value is already sanitized.
In the simple form, it's assumed the field value should be sanitized with check_plain().
- entity: (optional) If set, the fully loaded result item. This field should always be used by modules using search results, to avoid duplicate item loads.
- excerpt: (optional) If set, an HTML text containing highlighted portions of the fulltext that match the query.
- warnings: A numeric array of translated warning messages that may be displayed to the user.
- ignored: A numeric array of search keys that were ignored for this search (e.g., because of being too short or stop words).
- performance: An associative array with the time taken (as floats, in
seconds) for specific parts of the search execution:
- complete: The complete runtime of the query.
- hooks: Hook invocations and other client-side preprocessing.
- preprocessing: Preprocessing of the service class.
- execution: The actual query to the search server, in whatever form.
- postprocessing: Preparing the results for returning.
Additional metadata may be returned in other keys. Only 'result count' and 'results' always have to be set, all other entries are optional.
Throws
SearchApiException If an error prevented the search from completing.
Overrides SearchApiQueryInterface::execute
File
- includes/
query.inc, line 632 - Contains SearchApiQueryInterface and SearchApiQuery.
Class
- SearchApiQuery
- Provides a standard implementation of the SearchApiQueryInterface.
Code
public function execute() {
$start = microtime(TRUE);
// Prepare the query for execution by the server.
$this
->preExecute();
$pre_search = microtime(TRUE);
// Execute query.
$response = $this->index
->server()
->search($this);
$post_search = microtime(TRUE);
// Postprocess the search results.
$this
->postExecute($response);
$end = microtime(TRUE);
$response['performance']['complete'] = $end - $start;
$response['performance']['hooks'] = $response['performance']['complete'] - ($post_search - $pre_search);
// Store search for later retrieval for facets, etc.
search_api_current_search(NULL, $this, $response);
return $response;
}