你如何使用日光浴在solr中分页?

时间:2013-07-06 09:37:09

标签: php solr lucene solarium

我正在使用solrium,一个PHP Solr cilent用于使用Solr和PHP,我能够使用像select等查询。当我使用select时,我只得到10个在Solr中默认配置中设置为10的结果,如何在结果中获得所有带有分页的结果?

这是代码

<?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();





?>

1 个答案:

答案 0 :(得分:4)

你可以这样做:$query->setStart(2)->setRows(20)看一下这个例子:http://wiki.solarium-project.org/index.php/V3:Usage_modes

以下是您可以提供的选项:http://wiki.solarium-project.org/index.php/V2:Building_a_select_query