Example #1
0
    public function action_test($page = 1)
    {
        $page = $page <= 0 ? 1 : $page;
        $search = Sphinx::factory(Sprig::factory('actor'));
        $search->limit = 10;
        $search->offset = $search->limit * ($page - 1);
        $search->order_by('sort_fname');
        $result = $search->results;
        ?>
        <h2>Sorted by first name</h2>
        <h3><?php 
        echo $search->offset + 1, ' - ', $search->offset + 10;
        ?>
 results. Of <?php 
        echo $search->total;
        ?>
</h3>
        <a href="<?php 
        echo URL::site('sphinxexample/test/' . ($page - 1));
        ?>
">Prev</a> | <a href="<?php 
        echo URL::site('sphinxexample/test/' . ($page + 1));
        ?>
">Next</a>
        <br/>
        <table width="500"> 
        <tr>
            <th>docid</th>
            <th>Films</th>
            <th>First Name</th>
            <th>Last Name</th>
        </tr>
        <?php 
        foreach ($search as $i => $actor) {
            ?>
        <tr>
            <td><?php 
            echo $actor->actor_id;
            ?>
</td>
            <td>
            <?php 
            echo $search->attr($actor->actor_id, 'films');
            ?>
            </td>
            <td>
            <?php 
            echo $actor->first_name;
            ?>
            </td>
            <td>
            <?php 
            echo $actor->last_name;
            ?>
            </td>
        </tr>
        <?php 
        }
        ?>
        </table>
        <?php 
        if (!$result) {
            echo Kohana::debug($search->last_error);
        } else {
            echo Kohana::debug($result);
        }
    }