Programmatical use of Search API 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.

Information:


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-&gt;keys($term); 
$query-&gt;fields(array('title','body:value')); 
$srv= new SearchApiDbService($server);
$result = $srv-&gt;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.

Results example:

Array
(
[result count] =&gt; 11
[results] =&gt; Array
    (
        [37] =&gt; Array
            (
                [id] =&gt; 37
                [score] =&gt; 15.7503318786621
            )

        [39] =&gt; Array
            (
                [id] =&gt; 39
                [score] =&gt; 7
            )

        [40] =&gt; Array
            (
                [id] =&gt; 40
                [score] =&gt; 5
            )

        [31] =&gt; Array
            (
                [id] =&gt; 31
                [score] =&gt; 4
            )

        [33] =&gt; Array
            (
                [id] =&gt; 33
                [score] =&gt; 1
            )

        [36] =&gt; Array
            (
                [id] =&gt; 36
                [score] =&gt; 1
            )

        [1] =&gt; Array
            (
                [id] =&gt; 1
                [score] =&gt; 1
            )

        [15] =&gt; Array
            (
                [id] =&gt; 15
                [score] =&gt; 1
            )

        [16] =&gt; Array
            (
                [id] =&gt; 16
                [score] =&gt; 1
            )

        [27] =&gt; Array
            (
                [id] =&gt; 27
                [score] =&gt; 1
            )

        [35] =&gt; Array
            (
                [id] =&gt; 35
                [score] =&gt; 0.980873763561249
            )

    )

[warnings] =&gt; Array
    (
    )

[ignored] =&gt; Array
    (
    )

[performance] =&gt; Array
    (
        [complete] =&gt; 0.0033111572265625
        [preprocessing] =&gt; 0.00053095817565918
        [execution] =&gt; 0.0027379989624023
        [postprocessing] =&gt; 4.2200088500977E-5
    )

)
Have you looked at the Search API pages module. It uses the Search API module and creates a custom search page. You could probably look at that module for clues on how to implement what you are trying to do. The module itself might even provide a lot of the functionality that you are looking for.