3

I am using solrium , a PHP Solr cilent for using Solr with PHP , I am able to use queries like select etc . When I use select i get all only 10 results which is being set to 10 in default configuration in Solr , how do I get all results with Pagination at the result?

here's the code

<?php



require('/var/www/lg/vendor/solarium/solarium/examples/init.php');

htmlHeader();

// create a client instance
$client = new Solarium\Client($config);


// get a select query instance
$query = $client->createQuery($client::QUERY_SELECT);




// this executes the query and returns the result
$resultset = $client->execute($query);


// display the total number of documents found by solr
echo 'NumFound: '.$resultset->getNumFound();

// show documents using the resultset iterator
foreach ($resultset as $document) {


$query->setStart(2)->setRows(10);

//$query->setStart(21)->setRows(30);
    echo '<hr/><table>';

    // the documents are also iterable, to get all fields
    foreach($document AS $field => $value)
    {
        // this converts multivalue fields to a comma-separated string
        if(is_array($value)) $value = implode(', ', $value);

        echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>';
    }

    echo '</table>';
}

//new PageRequest(0, 10)

htmlFooter();





?>
Neetz
  • 364
  • 5
  • 18

1 Answers1

5

You can do it like: $query->setStart(2)->setRows(20) take a look at this example:http://wiki.solarium-project.org/index.php/V3:Usage_modes

And here is a little bit more about options you can give: http://wiki.solarium-project.org/index.php/V2:Building_a_select_query

Aurimas Ličkus
  • 9,886
  • 4
  • 24
  • 26
  • Hey , thanks but I want only 10 results to be printed per page , and rest of the results should be paginated by 10 records . Just like google gives you page 1 , 2 , 3 .. results – Neetz Jul 06 '13 at 18:17
  • Well you can change parameters, or i am missing something? – Aurimas Ličkus Jul 06 '13 at 18:31
  • Changing Parameters will give me all the results in the single page on the browser , But I want only 10 results per page , and the next 10 results on the another page , and so on .. did you get it ? – Neetz Jul 06 '13 at 18:35
  • ok then change setStart accordingly, for example 1 page setStart(1), second 2,3,4... and just leave setRows(10) and you have pagination. setStart is offset in you resultset. – Aurimas Ličkus Jul 06 '13 at 18:38
  • No , that dint work .. It will show the result of the last solr execution , i mean the last specified setStart(n) , not before that and no pagination – Neetz Jul 06 '13 at 18:44
  • 1
    Wel it should work. even in manual it's described. start = 'Start position (offset) in the complete Solr query resultset, to paginate big resultsets.' http://wiki.solarium-project.org/index.php/V2:Building_a_select_query – Aurimas Ličkus Jul 06 '13 at 18:46
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/33005/discussion-between-aurimas-lickus-and-neetz) – Aurimas Ličkus Jul 06 '13 at 18:58