Adding indexed field to Search API query in code I want to add an indexed field to a Search API query in code. My query currently looks like this:

$index = search_api_index_load("default_node_index");
$query=new SearchApiQuery($index);
$query-&gt;condition('type', 'answers_question', '=');
$filter = $query-&gt;createFilter('OR');
$filter-&gt;condition('title', $text, '=');
$filter-&gt;condition('body:value', $text, '=');
$query-&gt;sort('search_api_relevance', DESC);
$query-&gt;fields(array('title'));
$query-&gt;filter($filter);
$query-&gt;keys($text);
$data=$query-&gt;execute();


This returns the correct results, however the result set is composed of an array of arrays with an 'id' and a 'score'. I want the indexed node title to be returned as well. I cannot do a join to the node table as ->join is not available on SearchApiQuery.

The statement:

$query-&gt;fields(array('title'));


does not seem to do anything.

I have this same query set up in a view where it is working properly. When I inspect the query at hook_search_api_query_alter I cannot see where or how the title is added.

How do I add the indexed title as a field to be returned in the result set?
$query-&gt;fields(array('title'));


Doesn't do what you think it does/should, this tells Search API that this is one of your fulltext fields that you want querying against the string you passed to keys()

$query-&gt;keys($text);


What backend are you using for Search API, in my experience Solr returns all indexed non empty fields. Make sure the Title is indexed so that it is available to your Search API's backend.