Problem: Need to run my own searches programmatically with Search API. Every google result I find is geared toward teaching non-developers how to use the module with Views with no results on doing it like I want.
- Using local database service instead of Solr or any other.
- Have data not stored in database that will appear alongside other results.
- Content will be grouped in "type" tabs.
- Not using Views for various reasons.
- Have Facets API enabled but no clue how to use it either.
Why: Because I want to have the search page be at /site-search and without /node/keyword after the page argument. Also will be asked to customize this beyond the scope of other modules that may provide the same type of functionality. And I want to learn how to do this but have not found any tutorials or other insight on how to accomplish it.
The rest: I have created my search page and on it I am executing the search with:
$term = $_SESSION['my-search']['term']; $server = search_api_server_load('database'); $index = search_api_index_load('default_node_index'); $query = new SearchApiQuery($index); $query->keys($term); $query->fields(array('title','body:value')); $srv= new SearchApiDbService($server); $result = $srv->search($query);
The session variable is set when a search form is submitted then redirects the user to /site-search to perform the search and show the results.
If I output $result I see it's an array with different information including a result set that is an array of node ids and their scores.
I could run through those, grabbing the node and displaying the results myself but I figure there's got to be some other method for rendering the results of the search. I haven't found it though and that's the problem.
I've been looking through the different classes in Search API and Facet API and can't find anything in them that seem like they would build result output.
Any help with this will be appreciated.
Array ( [result count] => 11 [results] => Array (  => Array ( [id] => 37 [score] => 15.7503318786621 )  => Array ( [id] => 39 [score] => 7 )  => Array ( [id] => 40 [score] => 5 )  => Array ( [id] => 31 [score] => 4 )  => Array ( [id] => 33 [score] => 1 )  => Array ( [id] => 36 [score] => 1 )  => Array ( [id] => 1 [score] => 1 )  => Array ( [id] => 15 [score] => 1 )  => Array ( [id] => 16 [score] => 1 )  => Array ( [id] => 27 [score] => 1 )  => Array ( [id] => 35 [score] => 0.980873763561249 ) ) [warnings] => Array ( ) [ignored] => Array ( ) [performance] => Array ( [complete] => 0.0033111572265625 [preprocessing] => 0.00053095817565918 [execution] => 0.0027379989624023 [postprocessing] => 4.2200088500977E-5 ) )