0

I'm following along with Pro Drupal 7 Development by Apress (page 321) and using it as a guide to create a module that searches a legacy database of pages I've yet to import into a drupal install. I'm also using the API as a guide as well.

Everything works except for the number of results returned by dynamic query. What happens is, despite having PagerDefault and using a limit of 10, only 1 item shows up on the page. I can switch the number to any number and it's still 1.

I know for a fact there are 240 items that should be returned. And, indeed my pager list 24 pages (24 pages of 10 results). Again, however, there is only 1 result per page for a total of 24 results.

Here is my function:

function searchharvest_search_execute($keys = NULL) {

    // Set up and execute the query
    $query = db_select('search_index', 'i')->extend('SearchQuery')->extend('PagerDefault');


    $query->join('url_data', 'ud', 'ud.id = i.sid');
    $query->searchExpression($keys, 'searchharvest');

    //If there weren't any results return a blank result set
    if(!$query->executeFirstPass()){
        return array();
    }

    //If the first pass returned at least 1 record execute the search
    $found = $query->limit(10)->execute();

    //dsm($query);
    print_r($query->__toString());
    //Create the search results output
    foreach($found as $item){
        //dsm($item);
        //get found items from db
        $note = db_query("SELECT url, stripped_html from url_data where id = :sid", 
                array(':sid' => $item->sid))->fetchObject();




        $results[] = array(
            'link' => $note->url,
            'type' => t('searchharvest'),
            'title' => 'my title ' .$item->calculated_score, 
            'score' => $item->calculated_score,
            'snippet' => search_excerpt($keys, $note->stripped_html),
        );

        return $results;
    }

Thoughts on where the error is? Here is a photo as well with the query 'print_r' 'ed at the top

enter image description here

closed as too localized by mpdonadio Jun 19 '13 at 20:59

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. If this question can be reworded to fit the rules in the help center, please edit the question.

0

The return $results was inside the foreach loop, which stopped the iteration, hence only 1 result.

Not the answer you're looking for? Browse other questions tagged or ask your own question.